From 5a042b6f80be92564624504084385e67fe3e490a Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Wed, 25 Mar 2020 21:53:40 +0530 Subject: [PATCH 001/309] Java Example of Hexagonal Architecture --- hexagonaljava/.gitignore | 31 ++ .../.mvn/wrapper/MavenWrapperDownloader.java | 117 +++++++ hexagonaljava/.mvn/wrapper/maven-wrapper.jar | Bin 0 -> 50710 bytes .../.mvn/wrapper/maven-wrapper.properties | 2 + hexagonaljava/mvnw | 310 ++++++++++++++++++ hexagonaljava/mvnw.cmd | 182 ++++++++++ hexagonaljava/pom.xml | 60 ++++ .../HexagonaljavaApplication.java | 13 + .../controller/StudentResultController.java | 29 ++ .../hexagonaljava/entity/Student.java | 37 +++ .../repository/StudentResultJdbcRepoImpl.java | 84 +++++ .../repository/StudentResultRepo.java | 11 + .../repository/StudentResultRepoImpl.java | 26 ++ .../service/StudentResultService.java | 11 + .../service/StudentResultServiceImpl.java | 32 ++ .../src/main/resources/application.properties | 5 + hexagonaljava/src/main/resources/schema.sql | 11 + .../HexagonaljavaApplicationTests.java | 13 + 18 files changed, 974 insertions(+) create mode 100644 hexagonaljava/.gitignore create mode 100644 hexagonaljava/.mvn/wrapper/MavenWrapperDownloader.java create mode 100644 hexagonaljava/.mvn/wrapper/maven-wrapper.jar create mode 100644 hexagonaljava/.mvn/wrapper/maven-wrapper.properties create mode 100755 hexagonaljava/mvnw create mode 100644 hexagonaljava/mvnw.cmd create mode 100644 hexagonaljava/pom.xml create mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java create mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java create mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java create mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java create mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java create mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java create mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java create mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java create mode 100644 hexagonaljava/src/main/resources/application.properties create mode 100644 hexagonaljava/src/main/resources/schema.sql create mode 100644 hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java diff --git a/hexagonaljava/.gitignore b/hexagonaljava/.gitignore new file mode 100644 index 0000000000..a2a3040aa8 --- /dev/null +++ b/hexagonaljava/.gitignore @@ -0,0 +1,31 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ diff --git a/hexagonaljava/.mvn/wrapper/MavenWrapperDownloader.java b/hexagonaljava/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000..e76d1f3241 --- /dev/null +++ b/hexagonaljava/.mvn/wrapper/MavenWrapperDownloader.java @@ -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(); + } + +} diff --git a/hexagonaljava/.mvn/wrapper/maven-wrapper.jar b/hexagonaljava/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..2cc7d4a55c0cd0092912bf49ae38b3a9e3fd0054 GIT binary patch literal 50710 zcmbTd1CVCTmM+|7+wQV$+qP}n>auOywyU~q+qUhh+uxis_~*a##hm*_WW?9E7Pb7N%LRFiwbEGCJ0XP=%-6oeT$XZcYgtzC2~q zk(K08IQL8oTl}>>+hE5YRgXTB@fZ4TH9>7=79e`%%tw*SQUa9~$xKD5rS!;ZG@ocK zQdcH}JX?W|0_Afv?y`-NgLum62B&WSD$-w;O6G0Sm;SMX65z)l%m1e-g8Q$QTI;(Q z+x$xth4KFvH@Bs6(zn!iF#nenk^Y^ce;XIItAoCsow38eq?Y-Auh!1in#Rt-_D>H^ z=EjbclGGGa6VnaMGmMLj`x3NcwA43Jb(0gzl;RUIRAUDcR1~99l2SAPkVhoRMMtN} zXvC<tOmX83grD8GSo_Lo?%lNfhD#EBgPo z*nf@ppMC#B!T)Ae0RG$mlJWmGl7CkuU~B8-==5i;rS;8i6rJ=PoQxf446XDX9g|c> zU64ePyMlsI^V5Jq5A+BPe#e73+kpc_r1tv#B)~EZ;7^67F0*QiYfrk0uVW;Qb=NsG zN>gsuCwvb?s-KQIppEaeXtEMdc9dy6Dfduz-tMTms+i01{eD9JE&h?Kht*$eOl#&L zJdM_-vXs(V#$Ed;5wyNWJdPNh+Z$+;$|%qR(t`4W@kDhd*{(7-33BOS6L$UPDeE_53j${QfKN-0v-HG z(QfyvFNbwPK%^!eIo4ac1;b>c0vyf9}Xby@YY!lkz-UvNp zwj#Gg|4B~?n?G^{;(W;|{SNoJbHTMpQJ*Wq5b{l9c8(%?Kd^1?H1om1de0Da9M;Q=n zUfn{f87iVb^>Exl*nZ0hs(Yt>&V9$Pg`zX`AI%`+0SWQ4Zc(8lUDcTluS z5a_KerZWe}a-MF9#Cd^fi!y3%@RFmg&~YnYZ6<=L`UJ0v={zr)>$A;x#MCHZy1st7 ztT+N07NR+vOwSV2pvWuN1%lO!K#Pj0Fr>Q~R40{bwdL%u9i`DSM4RdtEH#cW)6}+I-eE< z&tZs+(Ogu(H_;$a$!7w`MH0r%h&@KM+<>gJL@O~2K2?VrSYUBbhCn#yy?P)uF3qWU z0o09mIik+kvzV6w>vEZy@&Mr)SgxPzUiDA&%07m17udz9usD82afQEps3$pe!7fUf z0eiidkJ)m3qhOjVHC_M(RYCBO%CZKZXFb8}s0-+}@CIn&EF(rRWUX2g^yZCvl0bI} zbP;1S)iXnRC&}5-Tl(hASKqdSnO?ASGJ*MIhOXIblmEudj(M|W!+I3eDc}7t`^mtg z)PKlaXe(OH+q-)qcQ8a@!llRrpGI8DsjhoKvw9T;TEH&?s=LH0w$EzI>%u;oD@x83 zJL7+ncjI9nn!TlS_KYu5vn%f*@qa5F;| zEFxY&B?g=IVlaF3XNm_03PA)=3|{n-UCgJoTr;|;1AU9|kPE_if8!Zvb}0q$5okF$ zHaJdmO&gg!9oN|M{!qGE=tb|3pVQ8PbL$}e;NgXz<6ZEggI}wO@aBP**2Wo=yN#ZC z4G$m^yaM9g=|&!^ft8jOLuzc3Psca*;7`;gnHm}tS0%f4{|VGEwu45KptfNmwxlE~ z^=r30gi@?cOm8kAz!EylA4G~7kbEiRlRIzwrb~{_2(x^$-?|#e6Bi_**(vyr_~9Of z!n>Gqf+Qwiu!xhi9f53=PM3`3tNF}pCOiPU|H4;pzjcsqbwg*{{kyrTxk<;mx~(;; z1NMrpaQ`57yn34>Jo3b|HROE(UNcQash!0p2-!Cz;{IRv#Vp5!3o$P8!%SgV~k&Hnqhp`5eLjTcy93cK!3Hm-$`@yGnaE=?;*2uSpiZTs_dDd51U%i z{|Zd9ou-;laGS_x=O}a+ zB||za<795A?_~Q=r=coQ+ZK@@ zId~hWQL<%)fI_WDIX#=(WNl!Dm$a&ROfLTd&B$vatq!M-2Jcs;N2vps$b6P1(N}=oI3<3luMTmC|0*{ zm1w8bt7vgX($!0@V0A}XIK)w!AzUn7vH=pZEp0RU0p?}ch2XC-7r#LK&vyc2=-#Q2 z^L%8)JbbcZ%g0Du;|8=q8B>X=mIQirpE=&Ox{TiuNDnOPd-FLI^KfEF729!!0x#Es z@>3ursjFSpu%C-8WL^Zw!7a0O-#cnf`HjI+AjVCFitK}GXO`ME&on|^=~Zc}^LBp9 zj=-vlN;Uc;IDjtK38l7}5xxQF&sRtfn4^TNtnzXv4M{r&ek*(eNbIu!u$>Ed%` z5x7+&)2P&4>0J`N&ZP8$vcR+@FS0126s6+Jx_{{`3ZrIMwaJo6jdrRwE$>IU_JTZ} z(||hyyQ)4Z1@wSlT94(-QKqkAatMmkT7pCycEB1U8KQbFX&?%|4$yyxCtm3=W`$4fiG0WU3yI@c zx{wfmkZAYE_5M%4{J-ygbpH|(|GD$2f$3o_Vti#&zfSGZMQ5_f3xt6~+{RX=$H8at z?GFG1Tmp}}lmm-R->ve*Iv+XJ@58p|1_jRvfEgz$XozU8#iJS})UM6VNI!3RUU!{5 zXB(+Eqd-E;cHQ>)`h0(HO_zLmzR3Tu-UGp;08YntWwMY-9i^w_u#wR?JxR2bky5j9 z3Sl-dQQU$xrO0xa&>vsiK`QN<$Yd%YXXM7*WOhnRdSFt5$aJux8QceC?lA0_if|s> ze{ad*opH_kb%M&~(~&UcX0nFGq^MqjxW?HJIP462v9XG>j(5Gat_)#SiNfahq2Mz2 zU`4uV8m$S~o9(W>mu*=h%Gs(Wz+%>h;R9Sg)jZ$q8vT1HxX3iQnh6&2rJ1u|j>^Qf`A76K%_ubL`Zu?h4`b=IyL>1!=*%!_K)=XC z6d}4R5L+sI50Q4P3upXQ3Z!~1ZXLlh!^UNcK6#QpYt-YC=^H=EPg3)z*wXo*024Q4b2sBCG4I# zlTFFY=kQ>xvR+LsuDUAk)q%5pEcqr(O_|^spjhtpb1#aC& zghXzGkGDC_XDa%t(X`E+kvKQ4zrQ*uuQoj>7@@ykWvF332)RO?%AA&Fsn&MNzmFa$ zWk&&^=NNjxLjrli_8ESU)}U|N{%j&TQmvY~lk!~Jh}*=^INA~&QB9em!in_X%Rl1&Kd~Z(u z9mra#<@vZQlOY+JYUwCrgoea4C8^(xv4ceCXcejq84TQ#sF~IU2V}LKc~Xlr_P=ry zl&Hh0exdCbVd^NPCqNNlxM3vA13EI8XvZ1H9#bT7y*U8Y{H8nwGpOR!e!!}*g;mJ#}T{ekSb}5zIPmye*If(}}_=PcuAW#yidAa^9-`<8Gr0 z)Fz=NiZ{)HAvw{Pl5uu)?)&i&Us$Cx4gE}cIJ}B4Xz~-q7)R_%owbP!z_V2=Aq%Rj z{V;7#kV1dNT9-6R+H}}(ED*_!F=~uz>&nR3gb^Ce%+0s#u|vWl<~JD3MvS0T9thdF zioIG3c#Sdsv;LdtRv3ml7%o$6LTVL>(H`^@TNg`2KPIk*8-IB}X!MT0`hN9Ddf7yN z?J=GxPL!uJ7lqwowsl?iRrh@#5C$%E&h~Z>XQcvFC*5%0RN-Opq|=IwX(dq(*sjs+ zqy99+v~m|6T#zR*e1AVxZ8djd5>eIeCi(b8sUk)OGjAsKSOg^-ugwl2WSL@d#?mdl zib0v*{u-?cq}dDGyZ%$XRY=UkQwt2oGu`zQneZh$=^! zj;!pCBWQNtvAcwcWIBM2y9!*W|8LmQy$H~5BEx)78J`4Z0(FJO2P^!YyQU{*Al+fs z){!4JvT1iLrJ8aU3k0t|P}{RN)_^v%$$r;+p0DY7N8CXzmS*HB*=?qaaF9D@#_$SN zSz{moAK<*RH->%r7xX~9gVW$l7?b|_SYI)gcjf0VAUJ%FcQP(TpBs; zg$25D!Ry_`8xpS_OJdeo$qh#7U+cepZ??TII7_%AXsT$B z=e)Bx#v%J0j``00Zk5hsvv6%T^*xGNx%KN-=pocSoqE5_R)OK%-Pbu^1MNzfds)mL zxz^F4lDKV9D&lEY;I+A)ui{TznB*CE$=9(wgE{m}`^<--OzV-5V4X2w9j(_!+jpTr zJvD*y6;39&T+==$F&tsRKM_lqa1HC}aGL0o`%c9mO=fts?36@8MGm7Vi{Y z^<7m$(EtdSr#22<(rm_(l_(`j!*Pu~Y>>xc>I9M#DJYDJNHO&4=HM%YLIp?;iR&$m z#_$ZWYLfGLt5FJZhr3jpYb`*%9S!zCG6ivNHYzNHcI%khtgHBliM^Ou}ZVD7ehU9 zS+W@AV=?Ro!=%AJ>Kcy9aU3%VX3|XM_K0A+ZaknKDyIS3S-Hw1C7&BSW5)sqj5Ye_ z4OSW7Yu-;bCyYKHFUk}<*<(@TH?YZPHr~~Iy%9@GR2Yd}J2!N9K&CN7Eq{Ka!jdu; zQNB*Y;i(7)OxZK%IHGt#Rt?z`I|A{q_BmoF!f^G}XVeTbe1Wnzh%1g>j}>DqFf;Rp zz7>xIs12@Ke0gr+4-!pmFP84vCIaTjqFNg{V`5}Rdt~xE^I;Bxp4)|cs8=f)1YwHz zqI`G~s2~qqDV+h02b`PQpUE#^^Aq8l%y2|ByQeXSADg5*qMprEAE3WFg0Q39`O+i1 z!J@iV!`Y~C$wJ!5Z+j5$i<1`+@)tBG$JL=!*uk=2k;T<@{|s1$YL079FvK%mPhyHV zP8^KGZnp`(hVMZ;s=n~3r2y;LTwcJwoBW-(ndU-$03{RD zh+Qn$ja_Z^OuMf3Ub|JTY74s&Am*(n{J3~@#OJNYuEVVJd9*H%)oFoRBkySGm`hx! zT3tG|+aAkXcx-2Apy)h^BkOyFTWQVeZ%e2@;*0DtlG9I3Et=PKaPt&K zw?WI7S;P)TWED7aSH$3hL@Qde?H#tzo^<(o_sv_2ci<7M?F$|oCFWc?7@KBj-;N$P zB;q!8@bW-WJY9do&y|6~mEruZAVe$!?{)N9rZZxD-|oltkhW9~nR8bLBGXw<632!l z*TYQn^NnUy%Ds}$f^=yQ+BM-a5X4^GHF=%PDrRfm_uqC zh{sKwIu|O0&jWb27;wzg4w5uA@TO_j(1X?8E>5Zfma|Ly7Bklq|s z9)H`zoAGY3n-+&JPrT!>u^qg9Evx4y@GI4$n-Uk_5wttU1_t?6><>}cZ-U+&+~JE) zPlDbO_j;MoxdLzMd~Ew|1o^a5q_1R*JZ=#XXMzg?6Zy!^hop}qoLQlJ{(%!KYt`MK z8umEN@Z4w!2=q_oe=;QttPCQy3Nm4F@x>@v4sz_jo{4m*0r%J(w1cSo;D_hQtJs7W z><$QrmG^+<$4{d2bgGo&3-FV}avg9zI|Rr(k{wTyl3!M1q+a zD9W{pCd%il*j&Ft z5H$nENf>>k$;SONGW`qo6`&qKs*T z2^RS)pXk9b@(_Fw1bkb)-oqK|v}r$L!W&aXA>IpcdNZ_vWE#XO8X`#Yp1+?RshVcd zknG%rPd*4ECEI0wD#@d+3NbHKxl}n^Sgkx==Iu%}HvNliOqVBqG?P2va zQ;kRJ$J6j;+wP9cS za#m;#GUT!qAV%+rdWolk+)6kkz4@Yh5LXP+LSvo9_T+MmiaP-eq6_k;)i6_@WSJ zlT@wK$zqHu<83U2V*yJ|XJU4farT#pAA&@qu)(PO^8PxEmPD4;Txpio+2)#!9 z>&=i7*#tc0`?!==vk>s7V+PL#S1;PwSY?NIXN2=Gu89x(cToFm))7L;< z+bhAbVD*bD=}iU`+PU+SBobTQ%S!=VL!>q$rfWsaaV}Smz>lO9JXT#`CcH_mRCSf4%YQAw`$^yY z3Y*^Nzk_g$xn7a_NO(2Eb*I=^;4f!Ra#Oo~LLjlcjke*k*o$~U#0ZXOQ5@HQ&T46l z7504MUgZkz2gNP1QFN8Y?nSEnEai^Rgyvl}xZfMUV6QrJcXp;jKGqB=D*tj{8(_pV zqyB*DK$2lgYGejmJUW)*s_Cv65sFf&pb(Yz8oWgDtQ0~k^0-wdF|tj}MOXaN@ydF8 zNr={U?=;&Z?wr^VC+`)S2xl}QFagy;$mG=TUs7Vi2wws5zEke4hTa2)>O0U?$WYsZ z<8bN2bB_N4AWd%+kncgknZ&}bM~eDtj#C5uRkp21hWW5gxWvc6b*4+dn<{c?w9Rmf zIVZKsPl{W2vQAlYO3yh}-{Os=YBnL8?uN5(RqfQ=-1cOiUnJu>KcLA*tQK3FU`_bM zM^T28w;nAj5EdAXFi&Kk1Nnl2)D!M{@+D-}bIEe+Lc4{s;YJc-{F#``iS2uk;2!Zp zF9#myUmO!wCeJIoi^A+T^e~20c+c2C}XltaR!|U-HfDA=^xF97ev}$l6#oY z&-&T{egB)&aV$3_aVA51XGiU07$s9vubh_kQG?F$FycvS6|IO!6q zq^>9|3U^*!X_C~SxX&pqUkUjz%!j=VlXDo$!2VLH!rKj@61mDpSr~7B2yy{>X~_nc zRI+7g2V&k zd**H++P9dg!-AOs3;GM`(g<+GRV$+&DdMVpUxY9I1@uK28$az=6oaa+PutlO9?6#? zf-OsgT>^@8KK>ggkUQRPPgC7zjKFR5spqQb3ojCHzj^(UH~v+!y*`Smv)VpVoPwa6 zWG18WJaPKMi*F6Zdk*kU^`i~NNTfn3BkJniC`yN98L-Awd)Z&mY? zprBW$!qL-OL7h@O#kvYnLsfff@kDIegt~?{-*5A7JrA;#TmTe?jICJqhub-G@e??D zqiV#g{)M!kW1-4SDel7TO{;@*h2=_76g3NUD@|c*WO#>MfYq6_YVUP+&8e4|%4T`w zXzhmVNziAHazWO2qXcaOu@R1MrPP{t)`N)}-1&~mq=ZH=w=;-E$IOk=y$dOls{6sRR`I5>|X zpq~XYW4sd;J^6OwOf**J>a7u$S>WTFPRkjY;BfVgQst)u4aMLR1|6%)CB^18XCz+r ztkYQ}G43j~Q&1em(_EkMv0|WEiKu;z2zhb(L%$F&xWwzOmk;VLBYAZ8lOCziNoPw1 zv2BOyXA`A8z^WH!nXhKXM`t0;6D*-uGds3TYGrm8SPnJJOQ^fJU#}@aIy@MYWz**H zvkp?7I5PE{$$|~{-ZaFxr6ZolP^nL##mHOErB^AqJqn^hFA=)HWj!m3WDaHW$C)i^ z9@6G$SzB=>jbe>4kqr#sF7#K}W*Cg-5y6kun3u&0L7BpXF9=#7IN8FOjWrWwUBZiU zT_se3ih-GBKx+Uw0N|CwP3D@-C=5(9T#BH@M`F2!Goiqx+Js5xC92|Sy0%WWWp={$(am!#l~f^W_oz78HX<0X#7 zp)p1u~M*o9W@O8P{0Qkg@Wa# z2{Heb&oX^CQSZWSFBXKOfE|tsAm#^U-WkDnU;IowZ`Ok4!mwHwH=s|AqZ^YD4!5!@ zPxJj+Bd-q6w_YG`z_+r;S86zwXb+EO&qogOq8h-Ect5(M2+>(O7n7)^dP*ws_3U6v zVsh)sk^@*c>)3EML|0<-YROho{lz@Nd4;R9gL{9|64xVL`n!m$-Jjrx?-Bacp!=^5 z1^T^eB{_)Y<9)y{-4Rz@9_>;_7h;5D+@QcbF4Wv7hu)s0&==&6u)33 zHRj+&Woq-vDvjwJCYES@$C4{$?f$Ibi4G()UeN11rgjF+^;YE^5nYprYoJNoudNj= zm1pXSeG64dcWHObUetodRn1Fw|1nI$D9z}dVEYT0lQnsf_E1x2vBLql7NrHH!n&Sq z6lc*mvU=WS6=v9Lrl}&zRiu_6u;6g%_DU{9b+R z#YHqX7`m9eydf?KlKu6Sb%j$%_jmydig`B*TN`cZL-g!R)iE?+Q5oOqBFKhx z%MW>BC^(F_JuG(ayE(MT{S3eI{cKiwOtPwLc0XO*{*|(JOx;uQOfq@lp_^cZo=FZj z4#}@e@dJ>Bn%2`2_WPeSN7si^{U#H=7N4o%Dq3NdGybrZgEU$oSm$hC)uNDC_M9xc zGzwh5Sg?mpBIE8lT2XsqTt3j3?We8}3bzLBTQd639vyg^$0#1epq8snlDJP2(BF)K zSx30RM+{f+b$g{9usIL8H!hCO117Xgv}ttPJm9wVRjPk;ePH@zxv%j9k5`TzdXLeT zFgFX`V7cYIcBls5WN0Pf6SMBN+;CrQ(|EsFd*xtwr#$R{Z9FP`OWtyNsq#mCgZ7+P z^Yn$haBJ)r96{ZJd8vlMl?IBxrgh=fdq_NF!1{jARCVz>jNdC)H^wfy?R94#MPdUjcYX>#wEx+LB#P-#4S-%YH>t-j+w zOFTI8gX$ard6fAh&g=u&56%3^-6E2tpk*wx3HSCQ+t7+*iOs zPk5ysqE}i*cQocFvA68xHfL|iX(C4h*67@3|5Qwle(8wT&!&{8*{f%0(5gH+m>$tq zp;AqrP7?XTEooYG1Dzfxc>W%*CyL16q|fQ0_jp%%Bk^k!i#Nbi(N9&T>#M{gez_Ws zYK=l}adalV(nH}I_!hNeb;tQFk3BHX7N}}R8%pek^E`X}%ou=cx8InPU1EE0|Hen- zyw8MoJqB5=)Z%JXlrdTXAE)eqLAdVE-=>wGHrkRet}>3Yu^lt$Kzu%$3#(ioY}@Gu zjk3BZuQH&~7H+C*uX^4}F*|P89JX;Hg2U!pt>rDi(n(Qe-c}tzb0#6_ItoR0->LSt zR~UT<-|@TO%O`M+_e_J4wx7^)5_%%u+J=yF_S#2Xd?C;Ss3N7KY^#-vx+|;bJX&8r zD?|MetfhdC;^2WG`7MCgs>TKKN=^=!x&Q~BzmQio_^l~LboTNT=I zC5pme^P@ER``p$2md9>4!K#vV-Fc1an7pl>_|&>aqP}+zqR?+~Z;f2^`a+-!Te%V? z;H2SbF>jP^GE(R1@%C==XQ@J=G9lKX+Z<@5}PO(EYkJh=GCv#)Nj{DkWJM2}F&oAZ6xu8&g7pn1ps2U5srwQ7CAK zN&*~@t{`31lUf`O;2w^)M3B@o)_mbRu{-`PrfNpF!R^q>yTR&ETS7^-b2*{-tZAZz zw@q5x9B5V8Qd7dZ!Ai$9hk%Q!wqbE1F1c96&zwBBaRW}(^axoPpN^4Aw}&a5dMe+*Gomky_l^54*rzXro$ z>LL)U5Ry>~FJi=*{JDc)_**c)-&faPz`6v`YU3HQa}pLtb5K)u%K+BOqXP0)rj5Au$zB zW1?vr?mDv7Fsxtsr+S6ucp2l#(4dnr9sD*v+@*>g#M4b|U?~s93>Pg{{a5|rm2xfI z`>E}?9S@|IoUX{Q1zjm5YJT|3S>&09D}|2~BiMo=z4YEjXlWh)V&qs;*C{`UMxp$9 zX)QB?G$fPD6z5_pNs>Jeh{^&U^)Wbr?2D6-q?)`*1k@!UvwQgl8eG$r+)NnFoT)L6 zg7lEh+E6J17krfYJCSjWzm67hEth24pomhz71|Qodn#oAILN)*Vwu2qpJirG)4Wnv}9GWOFrQg%Je+gNrPl8mw7ykE8{ z=|B4+uwC&bpp%eFcRU6{mxRV32VeH8XxX>v$du<$(DfinaaWxP<+Y97Z#n#U~V zVEu-GoPD=9$}P;xv+S~Ob#mmi$JQmE;Iz4(){y*9pFyW-jjgdk#oG$fl4o9E8bo|L zWjo4l%n51@Kz-n%zeSCD`uB?T%FVk+KBI}=ve zvlcS#wt`U6wrJo}6I6Rwb=1GzZfwE=I&Ne@p7*pH84XShXYJRgvK)UjQL%R9Zbm(m zxzTQsLTON$WO7vM)*vl%Pc0JH7WhP;$z@j=y#avW4X8iqy6mEYr@-}PW?H)xfP6fQ z&tI$F{NNct4rRMSHhaelo<5kTYq+(?pY)Ieh8*sa83EQfMrFupMM@nfEV@EmdHUv9 z35uzIrIuo4#WnF^_jcpC@uNNaYTQ~uZWOE6P@LFT^1@$o&q+9Qr8YR+ObBkpP9=F+$s5+B!mX2~T zAuQ6RenX?O{IlLMl1%)OK{S7oL}X%;!XUxU~xJN8xk z`xywS*naF(J#?vOpB(K=o~lE;m$zhgPWDB@=p#dQIW>xe_p1OLoWInJRKbEuoncf; zmS1!u-ycc1qWnDg5Nk2D)BY%jmOwCLC+Ny>`f&UxFowIsHnOXfR^S;&F(KXd{ODlm z$6#1ccqt-HIH9)|@fHnrKudu!6B$_R{fbCIkSIb#aUN|3RM>zuO>dpMbROZ`^hvS@ z$FU-;e4W}!ubzKrU@R*dW*($tFZ>}dd*4_mv)#O>X{U@zSzQt*83l9mI zI$8O<5AIDx`wo0}f2fsPC_l>ONx_`E7kdXu{YIZbp1$(^oBAH({T~&oQ&1{X951QW zmhHUxd)t%GQ9#ak5fTjk-cahWC;>^Rg7(`TVlvy0W@Y!Jc%QL3Ozu# zDPIqBCy&T2PWBj+d-JA-pxZlM=9ja2ce|3B(^VCF+a*MMp`(rH>Rt6W1$;r{n1(VK zLs>UtkT43LR2G$AOYHVailiqk7naz2yZGLo*xQs!T9VN5Q>eE(w zw$4&)&6xIV$IO^>1N-jrEUg>O8G4^@y+-hQv6@OmF@gy^nL_n1P1-Rtyy$Bl;|VcV zF=p*&41-qI5gG9UhKmmnjs932!6hceXa#-qfK;3d*a{)BrwNFeKU|ge?N!;zk+kB! zMD_uHJR#%b54c2tr~uGPLTRLg$`fupo}cRJeTwK;~}A>(Acy4k-Xk&Aa1&eWYS1ULWUj@fhBiWY$pdfy+F z@G{OG{*v*mYtH3OdUjwEr6%_ZPZ3P{@rfbNPQG!BZ7lRyC^xlMpWH`@YRar`tr}d> z#wz87t?#2FsH-jM6m{U=gp6WPrZ%*w0bFm(T#7m#v^;f%Z!kCeB5oiF`W33W5Srdt zdU?YeOdPG@98H7NpI{(uN{FJdu14r(URPH^F6tOpXuhU7T9a{3G3_#Ldfx_nT(Hec zo<1dyhsVsTw;ZkVcJ_0-h-T3G1W@q)_Q30LNv)W?FbMH+XJ* zy=$@39Op|kZv`Rt>X`zg&at(?PO^I=X8d9&myFEx#S`dYTg1W+iE?vt#b47QwoHI9 zNP+|3WjtXo{u}VG(lLUaW0&@yD|O?4TS4dfJI`HC-^q;M(b3r2;7|FONXphw-%7~* z&;2!X17|05+kZOpQ3~3!Nb>O94b&ZSs%p)TK)n3m=4eiblVtSx@KNFgBY_xV6ts;NF;GcGxMP8OKV^h6LmSb2E#Qnw ze!6Mnz7>lE9u{AgQ~8u2zM8CYD5US8dMDX-5iMlgpE9m*s+Lh~A#P1er*rF}GHV3h z=`STo?kIXw8I<`W0^*@mB1$}pj60R{aJ7>C2m=oghKyxMbFNq#EVLgP0cH3q7H z%0?L93-z6|+jiN|@v>ix?tRBU(v-4RV`}cQH*fp|)vd3)8i9hJ3hkuh^8dz{F5-~_ zUUr1T3cP%cCaTooM8dj|4*M=e6flH0&8ve32Q)0dyisl))XkZ7Wg~N}6y`+Qi2l+e zUd#F!nJp{#KIjbQdI`%oZ`?h=5G^kZ_uN`<(`3;a!~EMsWV|j-o>c?x#;zR2ktiB! z);5rrHl?GPtr6-o!tYd|uK;Vbsp4P{v_4??=^a>>U4_aUXPWQ$FPLE4PK$T^3Gkf$ zHo&9$U&G`d(Os6xt1r?sg14n)G8HNyWa^q8#nf0lbr4A-Fi;q6t-`pAx1T*$eKM*$ z|CX|gDrk#&1}>5H+`EjV$9Bm)Njw&7-ZR{1!CJTaXuP!$Pcg69`{w5BRHysB$(tWUes@@6aM69kb|Lx$%BRY^-o6bjH#0!7b;5~{6J+jKxU!Kmi# zndh@+?}WKSRY2gZ?Q`{(Uj|kb1%VWmRryOH0T)f3cKtG4oIF=F7RaRnH0Rc_&372={_3lRNsr95%ZO{IX{p@YJ^EI%+gvvKes5cY+PE@unghjdY5#9A!G z70u6}?zmd?v+{`vCu-53_v5@z)X{oPC@P)iA3jK$`r zSA2a7&!^zmUiZ82R2=1cumBQwOJUPz5Ay`RLfY(EiwKkrx%@YN^^XuET;tE zmr-6~I7j!R!KrHu5CWGSChO6deaLWa*9LLJbcAJsFd%Dy>a!>J`N)Z&oiU4OEP-!Ti^_!p}O?7`}i7Lsf$-gBkuY*`Zb z7=!nTT;5z$_5$=J=Ko+Cp|Q0J=%oFr>hBgnL3!tvFoLNhf#D0O=X^h+x08iB;@8pXdRHxX}6R4k@i6%vmsQwu^5z zk1ip`#^N)^#Lg#HOW3sPI33xqFB4#bOPVnY%d6prwxf;Y-w9{ky4{O6&94Ra8VN@K zb-lY;&`HtxW@sF!doT5T$2&lIvJpbKGMuDAFM#!QPXW87>}=Q4J3JeXlwHys?!1^#37q_k?N@+u&Ns20pEoBeZC*np;i;M{2C0Z4_br2gsh6eL z#8`#sn41+$iD?^GL%5?cbRcaa-Nx0vE(D=*WY%rXy3B%gNz0l?#noGJGP728RMY#q z=2&aJf@DcR?QbMmN)ItUe+VM_U!ryqA@1VVt$^*xYt~-qvW!J4Tp<-3>jT=7Zow5M z8mSKp0v4b%a8bxFr>3MwZHSWD73D@+$5?nZAqGM#>H@`)mIeC#->B)P8T$zh-Pxnc z8)~Zx?TWF4(YfKuF3WN_ckpCe5;x4V4AA3(i$pm|78{%!q?|~*eH0f=?j6i)n~Hso zmTo>vqEtB)`%hP55INf7HM@taH)v`Fw40Ayc*R!T?O{ziUpYmP)AH`euTK!zg9*6Z z!>M=$3pd0!&TzU=hc_@@^Yd3eUQpX4-33}b{?~5t5lgW=ldJ@dUAH%`l5US1y_`40 zs(X`Qk}vvMDYYq+@Rm+~IyCX;iD~pMgq^KY)T*aBz@DYEB={PxA>)mI6tM*sx-DmGQHEaHwRrAmNjO!ZLHO4b;;5mf@zzlPhkP($JeZGE7 z?^XN}Gf_feGoG~BjUgVa*)O`>lX=$BSR2)uD<9 z>o^|nb1^oVDhQbfW>>!;8-7<}nL6L^V*4pB=>wwW+RXAeRvKED(n1;R`A6v$6gy0I(;Vf?!4;&sgn7F%LpM}6PQ?0%2Z@b{It<(G1CZ|>913E0nR2r^Pa*Bp z@tFGi*CQ~@Yc-?{cwu1 zsilf=k^+Qs>&WZG(3WDixisHpR>`+ihiRwkL(3T|=xsoNP*@XX3BU8hr57l3k;pni zI``=3Nl4xh4oDj<%>Q1zYXHr%Xg_xrK3Nq?vKX3|^Hb(Bj+lONTz>4yhU-UdXt2>j z<>S4NB&!iE+ao{0Tx^N*^|EZU;0kJkx@zh}S^P{ieQjGl468CbC`SWnwLRYYiStXm zOxt~Rb3D{dz=nHMcY)#r^kF8|q8KZHVb9FCX2m^X*(|L9FZg!5a7((!J8%MjT$#Fs)M1Pb zq6hBGp%O1A+&%2>l0mpaIzbo&jc^!oN^3zxap3V2dNj3x<=TwZ&0eKX5PIso9j1;e zwUg+C&}FJ`k(M|%%}p=6RPUq4sT3-Y;k-<68ciZ~_j|bt>&9ZLHNVrp#+pk}XvM{8 z`?k}o-!if>hVlCP9j%&WI2V`5SW)BCeR5>MQhF)po=p~AYN%cNa_BbV6EEh_kk^@a zD>4&>uCGCUmyA-c)%DIcF4R6!>?6T~Mj_m{Hpq`*(wj>foHL;;%;?(((YOxGt)Bhx zuS+K{{CUsaC++%}S6~CJ=|vr(iIs-je)e9uJEU8ZJAz)w166q)R^2XI?@E2vUQ!R% zn@dxS!JcOimXkWJBz8Y?2JKQr>`~SmE2F2SL38$SyR1^yqj8_mkBp)o$@+3BQ~Mid z9U$XVqxX3P=XCKj0*W>}L0~Em`(vG<>srF8+*kPrw z20{z(=^w+ybdGe~Oo_i|hYJ@kZl*(9sHw#Chi&OIc?w`nBODp?ia$uF%Hs(X>xm?j zqZQ`Ybf@g#wli`!-al~3GWiE$K+LCe=Ndi!#CVjzUZ z!sD2O*;d28zkl))m)YN7HDi^z5IuNo3^w(zy8 zszJG#mp#Cj)Q@E@r-=NP2FVxxEAeOI2e=|KshybNB6HgE^(r>HD{*}S}mO>LuRGJT{*tfTzw_#+er-0${}%YPe@CMJ1Ng#j#)i)SnY@ss3gL;g zg2D~#Kpdfu#G;q1qz_TwSz1VJT(b3zby$Vk&;Y#1(A)|xj`_?i5YQ;TR%jice5E;0 zYHg;`zS5{S*9xI6o^j>rE8Ua*XhIw{_-*&@(R|C(am8__>+Ws&Q^ymy*X4~hR2b5r zm^p3sw}yv=tdyncy_Ui7{BQS732et~Z_@{-IhHDXAV`(Wlay<#hb>%H%WDi+K$862nA@BDtM#UCKMu+kM`!JHyWSi?&)A7_ z3{cyNG%a~nnH_!+;g&JxEMAmh-Z}rC!o7>OVzW&PoMyTA_g{hqXG)SLraA^OP**<7 zjWbr7z!o2n3hnx7A=2O=WL;`@9N{vQIM@&|G-ljrPvIuJHYtss0Er0fT5cMXNUf1B z7FAwBDixt0X7C3S)mPe5g`YtME23wAnbU)+AtV}z+e8G;0BP=bI;?(#|Ep!vVfDbK zvx+|CKF>yt0hWQ3drchU#XBU+HiuG*V^snFAPUp-5<#R&BUAzoB!aZ+e*KIxa26V}s6?nBK(U-7REa573wg-jqCg>H8~>O{ z*C0JL-?X-k_y%hpUFL?I>0WV{oV`Nb)nZbJG01R~AG>flIJf)3O*oB2i8~;!P?Wo_ z0|QEB*fifiL6E6%>tlAYHm2cjTFE@*<);#>689Z6S#BySQ@VTMhf9vYQyLeDg1*F} zjq>i1*x>5|CGKN{l9br3kB0EHY|k4{%^t7-uhjd#NVipUZa=EUuE5kS1_~qYX?>hJ z$}!jc9$O$>J&wnu0SgfYods^z?J4X;X7c77Me0kS-dO_VUQ39T(Kv(Y#s}Qqz-0AH z^?WRL(4RzpkD+T5FG_0NyPq-a-B7A5LHOCqwObRJi&oRi(<;OuIN7SV5PeHU$<@Zh zPozEV`dYmu0Z&Tqd>t>8JVde9#Pt+l95iHe$4Xwfy1AhI zDM4XJ;bBTTvRFtW>E+GzkN)9k!hA5z;xUOL2 zq4}zn-DP{qc^i|Y%rvi|^5k-*8;JZ~9a;>-+q_EOX+p1Wz;>i7c}M6Nv`^NY&{J-> z`(mzDJDM}QPu5i44**2Qbo(XzZ-ZDu%6vm8w@DUarqXj41VqP~ zs&4Y8F^Waik3y1fQo`bVUH;b=!^QrWb)3Gl=QVKr+6sxc=ygauUG|cm?|X=;Q)kQ8 zM(xrICifa2p``I7>g2R~?a{hmw@{!NS5`VhH8+;cV(F>B94M*S;5#O`YzZH1Z%yD? zZ61w(M`#aS-*~Fj;x|J!KM|^o;MI#Xkh0ULJcA?o4u~f%Z^16ViA27FxU5GM*rKq( z7cS~MrZ=f>_OWx8j#-Q3%!aEU2hVuTu(7`TQk-Bi6*!<}0WQi;_FpO;fhpL4`DcWp zGOw9vx0N~6#}lz(r+dxIGZM3ah-8qrqMmeRh%{z@dbUD2w15*_4P?I~UZr^anP}DB zU9CCrNiy9I3~d#&!$DX9e?A});BjBtQ7oGAyoI$8YQrkLBIH@2;lt4E^)|d6Jwj}z z&2_E}Y;H#6I4<10d_&P0{4|EUacwFHauvrjAnAm6yeR#}f}Rk27CN)vhgRqEyPMMS7zvunj2?`f;%?alsJ+-K+IzjJx>h8 zu~m_y$!J5RWAh|C<6+uiCNsOKu)E72M3xKK(a9Okw3e_*O&}7llNV!=P87VM2DkAk zci!YXS2&=P0}Hx|wwSc9JP%m8dMJA*q&VFB0yMI@5vWoAGraygwn){R+Cj6B1a2Px z5)u(K5{+;z2n*_XD!+Auv#LJEM)(~Hx{$Yb^ldQmcYF2zNH1V30*)CN_|1$v2|`LnFUT$%-tO0Eg|c5$BB~yDfzS zcOXJ$wpzVK0MfTjBJ0b$r#_OvAJ3WRt+YOLlJPYMx~qp>^$$$h#bc|`g0pF-Ao43? z>*A+8lx>}L{p(Tni2Vvk)dtzg$hUKjSjXRagj)$h#8=KV>5s)J4vGtRn5kP|AXIz! zPgbbVxW{2o4s-UM;c#We8P&mPN|DW7_uLF!a|^0S=wr6Esx9Z$2|c1?GaupU6$tb| zY_KU`(_29O_%k(;>^|6*pZURH3`@%EuKS;Ns z1lujmf;r{qAN&Q0&m{wJSZ8MeE7RM5+Sq;ul_ z`+ADrd_Um+G37js6tKsArNB}n{p*zTUxQr>3@wA;{EUbjNjlNd6$Mx zg0|MyU)v`sa~tEY5$en7^PkC=S<2@!nEdG6L=h(vT__0F=S8Y&eM=hal#7eM(o^Lu z2?^;05&|CNliYrq6gUv;|i!(W{0N)LWd*@{2q*u)}u*> z7MQgk6t9OqqXMln?zoMAJcc zMKaof_Up})q#DzdF?w^%tTI7STI^@8=Wk#enR*)&%8yje>+tKvUYbW8UAPg55xb70 zEn5&Ba~NmOJlgI#iS8W3-@N%>V!#z-ZRwfPO1)dQdQkaHsiqG|~we2ALqG7Ruup(DqSOft2RFg_X%3w?6VqvV1uzX_@F(diNVp z4{I|}35=11u$;?|JFBEE*gb;T`dy+8gWJ9~pNsecrO`t#V9jW-6mnfO@ff9od}b(3s4>p0i30gbGIv~1@a^F2kl7YO;DxmF3? zWi-RoXhzRJV0&XE@ACc?+@6?)LQ2XNm4KfalMtsc%4!Fn0rl zpHTrHwR>t>7W?t!Yc{*-^xN%9P0cs0kr=`?bQ5T*oOo&VRRu+1chM!qj%2I!@+1XF z4GWJ=7ix9;Wa@xoZ0RP`NCWw0*8247Y4jIZ>GEW7zuoCFXl6xIvz$ezsWgKdVMBH> z{o!A7f;R-@eK9Vj7R40xx)T<2$?F2E<>Jy3F;;=Yt}WE59J!1WN367 zA^6pu_zLoZIf*x031CcwotS{L8bJE(<_F%j_KJ2P_IusaZXwN$&^t716W{M6X2r_~ zaiMwdISX7Y&Qi&Uh0upS3TyEIXNDICQlT5fHXC`aji-c{U(J@qh-mWl-uMN|T&435 z5)a1dvB|oe%b2mefc=Vpm0C%IUYYh7HI*;3UdgNIz}R##(#{(_>82|zB0L*1i4B5j-xi9O4x10rs_J6*gdRBX=@VJ+==sWb&_Qc6tSOowM{BX@(zawtjl zdU!F4OYw2@Tk1L^%~JCwb|e#3CC>srRHQ*(N%!7$Mu_sKh@|*XtR>)BmWw!;8-mq7 zBBnbjwx8Kyv|hd*`5}84flTHR1Y@@uqjG`UG+jN_YK&RYTt7DVwfEDXDW4U+iO{>K zw1hr{_XE*S*K9TzzUlJH2rh^hUm2v7_XjwTuYap|>zeEDY$HOq3X4Tz^X}E9z)x4F zs+T?Ed+Hj<#jY-`Va~fT2C$=qFT-5q$@p9~0{G&eeL~tiIAHXA!f6C(rAlS^)&k<- zXU|ZVs}XQ>s5iONo~t!XXZgtaP$Iau;JT%h)>}v54yut~pykaNye4axEK#5@?TSsQ zE;Jvf9I$GVb|S`7$pG)4vgo9NXsKr?u=F!GnA%VS2z$@Z(!MR9?EPcAqi5ft)Iz6sNl`%kj+_H-X`R<>BFrBW=fSlD|{`D%@Rcbu2?%>t7i34k?Ujb)2@J-`j#4 zLK<69qcUuniIan-$A1+fR=?@+thwDIXtF1Tks@Br-xY zfB+zblrR(ke`U;6U~-;p1Kg8Lh6v~LjW@9l2P6s+?$2!ZRPX`(ZkRGe7~q(4&gEi<$ch`5kQ?*1=GSqkeV z{SA1EaW_A!t{@^UY2D^YO0(H@+kFVzZaAh0_`A`f(}G~EP~?B|%gtxu&g%^x{EYSz zk+T;_c@d;+n@$<>V%P=nk36?L!}?*=vK4>nJSm+1%a}9UlmTJTrfX4{Lb7smNQn@T zw9p2%(Zjl^bWGo1;DuMHN(djsEm)P8mEC2sL@KyPjwD@d%QnZ$ zMJ3cnn!_!iP{MzWk%PI&D?m?C(y2d|2VChluN^yHya(b`h>~GkI1y;}O_E57zOs!{ zt2C@M$^PR2U#(dZmA-sNreB@z-yb0Bf7j*yONhZG=onhx>t4)RB`r6&TP$n zgmN*)eCqvgriBO-abHQ8ECN0bw?z5Bxpx z=jF@?zFdVn?@gD5egM4o$m`}lV(CWrOKKq(sv*`mNcHcvw&Xryfw<{ch{O&qc#WCTXX6=#{MV@q#iHYba!OUY+MGeNTjP%Fj!WgM&`&RlI^=AWTOqy-o zHo9YFt!gQ*p7{Fl86>#-JLZo(b^O`LdFK~OsZBRR@6P?ad^Ujbqm_j^XycM4ZHFyg ziUbIFW#2tj`65~#2V!4z7DM8Z;fG0|APaQ{a2VNYpNotB7eZ5kp+tPDz&Lqs0j%Y4tA*URpcfi z_M(FD=fRGdqf430j}1z`O0I=;tLu81bwJXdYiN7_&a-?ly|-j*+=--XGvCq#32Gh(=|qj5F?kmihk{%M&$}udW5)DHK zF_>}5R8&&API}o0osZJRL3n~>76nUZ&L&iy^s>PMnNcYZ|9*1$v-bzbT3rpWsJ+y{ zPrg>5Zlery96Um?lc6L|)}&{992{_$J&=4%nRp9BAC6!IB=A&=tF>r8S*O-=!G(_( zwXbX_rGZgeiK*&n5E;f=k{ktyA1(;x_kiMEt0*gpp_4&(twlS2e5C?NoD{n>X2AT# zY@Zp?#!b1zNq96MQqeO*M1MMBin5v#RH52&Xd~DO6-BZLnA6xO1$sou(YJ1Dlc{WF zVa%2DyYm`V#81jP@70IJ;DX@y*iUt$MLm)ByAD$eUuji|5{ptFYq(q)mE(5bOpxjM z^Q`AHWq44SG3`_LxC9fwR)XRVIp=B%<(-lOC3jI#bb@dK(*vjom!=t|#<@dZql%>O z15y^{4tQoeW9Lu%G&V$90x6F)xN6y_oIn;!Q zs)8jT$;&;u%Y>=T3hg34A-+Y*na=|glcStr5D;&5*t5*DmD~x;zQAV5{}Ya`?RRGa zT*t9@$a~!co;pD^!J5bo?lDOWFx%)Y=-fJ+PDGc0>;=q=s?P4aHForSB+)v0WY2JH z?*`O;RHum6j%#LG)Vu#ciO#+jRC3!>T(9fr+XE7T2B7Z|0nR5jw@WG)kDDzTJ=o4~ zUpeyt7}_nd`t}j9BKqryOha{34erm)RmST)_9Aw)@ zHbiyg5n&E{_CQR@h<}34d7WM{s{%5wdty1l+KX8*?+-YkNK2Be*6&jc>@{Fd;Ps|| z26LqdI3#9le?;}risDq$K5G3yoqK}C^@-8z^wj%tdgw-6@F#Ju{Sg7+y)L?)U$ez> zoOaP$UFZ?y5BiFycir*pnaAaY+|%1%8&|(@VB)zweR%?IidwJyK5J!STzw&2RFx zZV@qeaCB01Hu#U9|1#=Msc8Pgz5P*4Lrp!Q+~(G!OiNR{qa7|r^H?FC6gVhkk3y7=uW#Sh;&>78bZ}aK*C#NH$9rX@M3f{nckYI+5QG?Aj1DM)@~z_ zw!UAD@gedTlePB*%4+55naJ8ak_;))#S;4ji!LOqY5VRI){GMwHR~}6t4g>5C_#U# ztYC!tjKjrKvRy=GAsJVK++~$|+s!w9z3H4G^mACv=EErXNSmH7qN}%PKcN|8%9=i)qS5+$L zu&ya~HW%RMVJi4T^pv?>mw*Gf<)-7gf#Qj|e#w2|v4#t!%Jk{&xlf;$_?jW*n!Pyx zkG$<18kiLOAUPuFfyu-EfWX%4jYnjBYc~~*9JEz6oa)_R|8wjZA|RNrAp%}14L7fW zi7A5Wym*K+V8pkqqO-X#3ft{0qs?KVt^)?kS>AicmeO&q+~J~ zp0YJ_P~_a8j= zsAs~G=8F=M{4GZL{|B__UorX@MRNQLn?*_gym4aW(~+i13knnk1P=khoC-ViMZk+x zLW(l}oAg1H`dU+Fv**;qw|ANDSRs>cGqL!Yw^`; zv;{E&8CNJcc)GHzTYM}f&NPw<6j{C3gaeelU#y!M)w-utYEHOCCJo|Vgp7K6C_$14 zqIrLUB0bsgz^D%V%fbo2f9#yb#CntTX?55Xy|Kps&Xek*4_r=KDZ z+`TQuv|$l}MWLzA5Ay6Cvsa^7xvwXpy?`w(6vx4XJ zWuf1bVSb#U8{xlY4+wlZ$9jjPk)X_;NFMqdgq>m&W=!KtP+6NL57`AMljW+es zzqjUjgz;V*kktJI?!NOg^s_)ph45>4UDA!Vo0hn>KZ+h-3=?Y3*R=#!fOX zP$Y~+14$f66ix?UWB_6r#fMcC^~X4R-<&OD1CSDNuX~y^YwJ>sW0j`T<2+3F9>cLo z#!j57$ll2K9(%$4>eA7(>FJX5e)pR5&EZK!IMQzOfik#FU*o*LGz~7u(8}XzIQRy- z!U7AlMTIe|DgQFmc%cHy_9^{o`eD%ja_L>ckU6$O4*U**o5uR7`FzqkU8k4gxtI=o z^P^oGFPm5jwZMI{;nH}$?p@uV8FT4r=|#GziKXK07bHJLtK}X%I0TON$uj(iJ`SY^ zc$b2CoxCQ>7LH@nxcdW&_C#fMYBtTxcg46dL{vf%EFCZ~eErMvZq&Z%Lhumnkn^4A zsx$ay(FnN7kYah}tZ@0?-0Niroa~13`?hVi6`ndno`G+E8;$<6^gsE-K3)TxyoJ4M zb6pj5=I8^FD5H@`^V#Qb2^0cx7wUz&cruA5g>6>qR5)O^t1(-qqP&1g=qvY#s&{bx zq8Hc%LsbK1*%n|Y=FfojpE;w~)G0-X4i*K3{o|J7`krhIOd*c*$y{WIKz2n2*EXEH zT{oml3Th5k*vkswuFXdGDlcLj15Nec5pFfZ*0?XHaF_lVuiB%Pv&p7z)%38}%$Gup zVTa~C8=cw%6BKn_|4E?bPNW4PT7}jZQLhDJhvf4z;~L)506IE0 zX!tWXX(QOQPRj-p80QG79t8T2^az4Zp2hOHziQlvT!|H)jv{Ixodabzv6lBj)6WRB z{)Kg@$~~(7$-az?lw$4@L%I&DI0Lo)PEJJziWP33a3azb?jyXt1v0N>2kxwA6b%l> zZqRpAo)Npi&loWbjFWtEV)783BbeIAhqyuc+~>i7aQ8shIXt)bjCWT6$~ro^>99G} z2XfmT0(|l!)XJb^E!#3z4oEGIsL(xd; zYX1`1I(cG|u#4R4T&C|m*9KB1`UzKvho5R@1eYtUL9B72{i(ir&ls8g!pD ztR|25xGaF!4z5M+U@@lQf(12?xGy`!|3E}7pI$k`jOIFjiDr{tqf0va&3pOn6Pu)% z@xtG2zjYuJXrV)DUrIF*y<1O1<$#54kZ#2;=X51J^F#0nZ0(;S$OZDt_U2bx{RZ=Q zMMdd$fH|!s{ zXq#l;{`xfV`gp&C>A`WrQU?d{!Ey5(1u*VLJt>i27aZ-^&2IIk=zP5p+{$q(K?2(b z8?9h)kvj9SF!Dr zoyF}?V|9;6abHxWk2cEvGs$-}Pg}D+ZzgkaN&$Snp%;5m%zh1E#?Wac-}x?BYlGN#U#Mek*}kek#I9XaHt?mz3*fDrRTQ#&#~xyeqJk1QJ~E$7qsw6 z?sV;|?*=-{M<1+hXoj?@-$y+(^BJ1H~wQ9G8C0#^aEAyhDduNX@haoa=PuPp zYsGv8UBfQaRHgBgLjmP^eh>fLMeh{8ic)?xz?#3kX-D#Z{;W#cd_`9OMFIaJg-=t`_3*!YDgtNQ2+QUEAJB9M{~AvT$H`E)IKmCR21H532+ata8_i_MR@ z2Xj<3w<`isF~Ah$W{|9;51ub*f4#9ziKrOR&jM{x7I_7()O@`F*5o$KtZ?fxU~g`t zUovNEVKYn$U~VX8eR)qb`7;D8pn*Pp$(otYTqL)5KH$lUS-jf}PGBjy$weoceAcPp z&5ZYB$r&P$MN{0H0AxCe4Qmd3T%M*5d4i%#!nmBCN-WU-4m4Tjxn-%j3HagwTxCZ9 z)j5vO-C7%s%D!&UfO>bi2oXiCw<-w{vVTK^rVbv#W=WjdADJy8$khnU!`ZWCIU`># zyjc^1W~pcu>@lDZ{zr6gv%)2X4n27~Ve+cQqcND%0?IFSP4sH#yIaXXYAq^z3|cg` z`I3$m%jra>e2W-=DiD@84T!cb%||k)nPmEE09NC%@PS_OLhkrX*U!cgD*;;&gIaA(DyVT4QD+q_xu z>r`tg{hiGY&DvD-)B*h+YEd+Zn)WylQl}<4>(_NlsKXCRV;a)Rcw!wtelM2_rWX`j zTh5A|i6=2BA(iMCnj_fob@*eA;V?oa4Z1kRBGaU07O70fb6-qmA$Hg$ps@^ka1=RO zTbE_2#)1bndC3VuK@e!Sftxq4=Uux}fDxXE#Q5_x=E1h>T5`DPHz zbH<_OjWx$wy7=%0!mo*qH*7N4tySm+R0~(rbus`7;+wGh;C0O%x~fEMkt!eV>U$`i z5>Q(o z=t$gPjgGh0&I7KY#k50V7DJRX<%^X z>6+ebc9efB3@eE2Tr){;?_w`vhgF>`-GDY(YkR{9RH(MiCnyRtd!LxXJ75z+?2 zGi@m^+2hKJ5sB1@Xi@s_@p_Kwbc<*LQ_`mr^Y%j}(sV_$`J(?_FWP)4NW*BIL~sR>t6 zM;qTJZ~GoY36&{h-Pf}L#y2UtR}>ZaI%A6VkU>vG4~}9^i$5WP2Tj?Cc}5oQxe2=q z8BeLa$hwCg_psjZyC2+?yX4*hJ58Wu^w9}}7X*+i5Rjqu5^@GzXiw#SUir1G1`jY% zOL=GE_ENYxhcyUrEt9XlMNP6kx6h&%6^u3@zB8KUCAa18T(R2J`%JjWZ z!{7cXaEW+Qu*iJPu+m>QqW}Lo$4Z+!I)0JNzZ&_M%=|B1yejFRM04bGAvu{=lNPd+ zJRI^DRQ(?FcVUD+bgEcAi@o(msqys9RTCG#)TjI!9~3-dc`>gW;HSJuQvH~d`MQs86R$|SKXHh zqS9Qy)u;T`>>a!$LuaE2keJV%;8g)tr&Nnc;EkvA-RanHXsy)D@XN0a>h}z2j81R; zsUNJf&g&rKpuD0WD@=dDrPHdBoK42WoBU|nMo17o(5^;M|dB4?|FsAGVrSyWcI`+FVw^vTVC`y}f(BwJl zrw3Sp151^9=}B})6@H*i4-dIN_o^br+BkcLa^H56|^2XsT0dESw2 zMX>(KqNl=x2K5=zIKg}2JpGAZu{I_IO}0$EQ5P{4zol**PCt3F4`GX}2@vr8#Y)~J zKb)gJeHcFnR@4SSh%b;c%J`l=W*40UPjF#q{<}ywv-=vHRFmDjv)NtmC zQx9qm)d%0zH&qG7AFa3VAU1S^(n8VFTC~Hb+HjYMjX8r#&_0MzlNR*mnLH5hi}`@{ zK$8qiDDvS_(L9_2vHgzEQ${DYSE;DqB!g*jhJghE&=LTnbgl&Xepo<*uRtV{2wDHN z)l;Kg$TA>Y|K8Lc&LjWGj<+bp4Hiye_@BfU(y#nF{fpR&|Ltbye?e^j0}8JC4#xi% zv29ZR%8%hk=3ZDvO-@1u8KmQ@6p%E|dlHuy#H1&MiC<*$YdLkHmR#F3ae;bKd;@*i z2_VfELG=B}JMLCO-6UQy^>RDE%K4b>c%9ki`f~Z2Qu8hO7C#t%Aeg8E%+}6P7Twtg z-)dj(w}_zFK&86KR@q9MHicUAucLVshUdmz_2@32(V`y3`&Kf8Q2I)+!n0mR=rrDU zXvv^$ho;yh*kNqJ#r1}b0|i|xRUF6;lhx$M*uG3SNLUTC@|htC z-=fsw^F%$qqz4%QdjBrS+ov}Qv!z00E+JWas>p?z@=t!WWU3K*?Z(0meTuTOC7OTx zU|kFLE0bLZ+WGcL$u4E}5dB0g`h|uwv3=H6f+{5z9oLv-=Q45+n~V4WwgO=CabjM% zBAN+RjM65(-}>Q2V#i1Na@a0`08g&y;W#@sBiX6Tpy8r}*+{RnyGUT`?XeHSqo#|J z^ww~c;ou|iyzpErDtlVU=`8N7JSu>4M z_pr9=tX0edVn9B}YFO2y(88j#S{w%E8vVOpAboK*27a7e4Ekjt0)hIX99*1oE;vex z7#%jhY=bPijA=Ce@9rRO(Vl_vnd00!^TAc<+wVvRM9{;hP*rqEL_(RzfK$er_^SN; z)1a8vo8~Dr5?;0X0J62Cusw$A*c^Sx1)dom`-)Pl7hsW4i(r*^Mw`z5K>!2ixB_mu z*Ddqjh}zceRFdmuX1akM1$3>G=#~|y?eYv(e-`Qy?bRHIq=fMaN~fB zUa6I8Rt=)jnplP>yuS+P&PxeWpJ#1$F`iqRl|jF$WL_aZFZl@kLo&d$VJtu&w?Q0O zzuXK>6gmygq(yXJy0C1SL}T8AplK|AGNUOhzlGeK_oo|haD@)5PxF}rV+5`-w{Aag zus45t=FU*{LguJ11Sr-28EZkq;!mJO7AQGih1L4rEyUmp>B!%X0YemsrV3QFvlgt* z5kwlPzaiJ+kZ^PMd-RRbl(Y?F*m`4*UIhIuf#8q>H_M=fM*L_Op-<_r zBZagV=4B|EW+KTja?srADTZXCd3Yv%^Chfpi)cg{ED${SI>InNpRj5!euKv?=Xn92 zsS&FH(*w`qLIy$doc>RE&A5R?u zzkl1sxX|{*fLpXvIW>9d<$ePROttn3oc6R!sN{&Y+>Jr@yeQN$sFR z;w6A<2-0%UA?c8Qf;sX7>>uKRBv3Ni)E9pI{uVzX|6Bb0U)`lhLE3hK58ivfRs1}d zNjlGK0hdq0qjV@q1qI%ZFMLgcpWSY~mB^LK)4GZ^h_@H+3?dAe_a~k*;9P_d7%NEFP6+ zgV(oGr*?W(ql?6SQ~`lUsjLb%MbfC4V$)1E0Y_b|OIYxz4?O|!kRb?BGrgiH5+(>s zoqM}v*;OBfg-D1l`M6T6{K`LG+0dJ1)!??G5g(2*vlNkm%Q(MPABT$r13q?|+kL4- zf)Mi5r$sn;u41aK(K#!m+goyd$c!KPl~-&-({j#D4^7hQkV3W|&>l_b!}!z?4($OA z5IrkfuT#F&S1(`?modY&I40%gtroig{YMvF{K{>5u^I51k8RriGd${z)=5k2tG zM|&Bp5kDTfb#vfuTTd?)a=>bX=lokw^y9+2LS?kwHQIWI~pYgy7 zb?A-RKVm_vM5!9?C%qYdfRAw& zAU7`up~%g=p@}pg#b7E)BFYx3g%(J36Nw(Dij!b>cMl@CSNbrW!DBDbTD4OXk!G4x zi}JBKc8HBYx$J~31PXH+4^x|UxK~(<@I;^3pWN$E=sYma@JP|8YL`L(zI6Y#c%Q{6 z*APf`DU$S4pr#_!60BH$FGViP14iJmbrzSrOkR;f3YZa{#E7Wpd@^4E-zH8EgPc-# zKWFPvh%WbqU_%ZEt`=Q?odKHc7@SUmY{GK`?40VuL~o)bS|is$Hn=<=KGHOsEC5tB zFb|q}gGlL97NUf$G$>^1b^3E18PZ~Pm9kX%*ftnolljiEt@2#F2R5ah$zbXd%V_Ev zyDd{1o_uuoBga$fB@Fw!V5F3jIr=a-ykqrK?WWZ#a(bglI_-8pq74RK*KfQ z0~Dzus7_l;pMJYf>Bk`)`S8gF!To-BdMnVw5M-pyu+aCiC5dwNH|6fgRsIKZcF&)g zr}1|?VOp}I3)IR@m1&HX1~#wsS!4iYqES zK}4J{Ei>;e3>LB#Oly>EZkW14^@YmpbgxCDi#0RgdM${&wxR+LiX}B+iRioOB0(pDKpVEI;ND?wNx>%e|m{RsqR_{(nmQ z3ZS}@t!p4a(BKx_-CYwrcyJ5u1TO9bcXti$8sy>xcLKqKCc#~UOZYD{llKTSFEjJ~ zyNWt>tLU}*>^`TvPxtP%F`ZJQw@W0^>x;!^@?k_)9#bF$j0)S3;mH-IR5y82l|%=F z2lR8zhP?XNP-ucZZ6A+o$xOyF!w;RaLHGh57GZ|TCXhJqY~GCh)aXEV$1O&$c}La1 zjuJxkY9SM4av^Hb;i7efiYaMwI%jGy`3NdY)+mcJhF(3XEiSlU3c|jMBi|;m-c?~T z+x0_@;SxcoY=(6xNgO$bBt~Pj8`-<1S|;Bsjrzw3@zSjt^JC3X3*$HI79i~!$RmTz zsblZsLYs7L$|=1CB$8qS!tXrWs!F@BVuh?kN(PvE5Av-*r^iYu+L^j^m9JG^#=m>@ z=1soa)H*w6KzoR$B8mBCXoU;f5^bVuwQ3~2LKg!yxomG1#XPmn(?YH@E~_ED+W6mxs%x{%Z<$pW`~ON1~2XjP5v(0{C{+6Dm$00tsd3w=f=ZENy zOgb-=f}|Hb*LQ$YdWg<(u7x3`PKF)B7ZfZ6;1FrNM63 z?O6tE%EiU@6%rVuwIQjvGtOofZBGZT1Sh(xLIYt9c4VI8`!=UJd2BfLjdRI#SbVAX ziT(f*RI^T!IL5Ac>ql7uduF#nuCRJ1)2bdvAyMxp-5^Ww5p#X{rb5)(X|fEhDHHW{ zw(Lfc$g;+Q`B0AiPGtmK%*aWfQQ$d!*U<|-@n2HZvCWSiw^I>#vh+LyC;aaVWGbmkENr z&kl*8o^_FW$T?rDYLO1Pyi%>@&kJKQoH2E0F`HjcN}Zlnx1ddoDA>G4Xu_jyp6vuT zPvC}pT&Owx+qB`zUeR|4G;OH(<<^_bzkjln0k40t`PQxc$7h(T8Ya~X+9gDc8Z9{Z z&y0RAU}#_kQGrM;__MK9vwIwK^aoqFhk~dK!ARf1zJqHMxF2?7-8|~yoO@_~Ed;_wvT%Vs{9RK$6uUQ|&@#6vyBsFK9eZW1Ft#D2)VpQRwpR(;x^ zdoTgMqfF9iBl%{`QDv7B0~8{8`8k`C4@cbZAXBu00v#kYl!#_Wug{)2PwD5cNp?K^ z9+|d-4z|gZ!L{57>!Ogfbzchm>J1)Y%?NThxIS8frAw@z>Zb9v%3_3~F@<=LG%r*U zaTov}{{^z~SeX!qgSYow`_5)ij*QtGp4lvF`aIGQ>@3ZTkDmsl#@^5*NGjOuu82}o zzLF~Q9SW+mP=>88%eSA1W4_W7-Q>rdq^?t=m6}^tDPaBRGFLg%ak93W!kOp#EO{6& zP%}Iff5HZQ9VW$~+9r=|Quj#z*=YwcnssS~9|ub2>v|u1JXP47vZ1&L1O%Z1DsOrDfSIMHU{VT>&>H=9}G3i@2rP+rx@eU@uE8rJNec zij~#FmuEBj03F1~ct@C@$>y)zB+tVyjV3*n`mtAhIM0$58vM9jOQC}JJOem|EpwqeMuYPxu3sv}oMS?S#o6GGK@8PN59)m&K4Dc&X% z(;XL_kKeYkafzS3Wn5DD>Yiw{LACy_#jY4op(>9q>>-*9@C0M+=b#bknAWZ37^(Ij zq>H%<@>o4a#6NydoF{_M4i4zB_KG)#PSye9bk0Ou8h%1Dtl7Q_y#7*n%g)?m>xF~( zjqvOwC;*qvN_3(*a+w2|ao0D?@okOvg8JskUw(l7n`0fncglavwKd?~l_ryKJ^Ky! zKCHkIC-o7%fFvPa$)YNh022lakMar^dgL=t#@XLyNHHw!b?%WlM)R@^!)I!smZL@k zBi=6wE5)2v&!UNV(&)oOYW(6Qa!nUjDKKBf-~Da=#^HE4(@mWk)LPvhyN3i4goB$3K8iV7uh zsv+a?#c4&NWeK(3AH;ETrMOIFgu{_@%XRwCZ;L=^8Ts)hix4Pf3yJRQ<8xb^CkdmC z?c_gB)XmRsk`9ch#tx4*hO=#qS7={~Vb4*tTf<5P%*-XMfUUYkI9T1cEF;ObfxxI-yNuA=I$dCtz3ey znVkctYD*`fUuZ(57+^B*R=Q}~{1z#2!ca?)+YsRQb+lt^LmEvZt_`=j^wqig+wz@n@ z`LIMQJT3bxMzuKg8EGBU+Q-6cs5(@5W?N>JpZL{$9VF)veF`L5%DSYTNQEypW%6$u zm_~}T{HeHj1bAlKl8ii92l9~$dm=UM21kLemA&b$;^!wB7#IKWGnF$TVq!!lBlG4 z{?Rjz?P(uvid+|i$VH?`-C&Gcb3{(~Vpg`w+O);Wk1|Mrjxrht0GfRUnZqz2MhrXa zqgVC9nemD5)H$to=~hp)c=l9?#~Z_7i~=U-`FZxb-|TR9@YCxx;Zjo-WpMNOn2)z) zFPGGVl%3N$f`gp$gPnWC+f4(rmts%fidpo^BJx72zAd7|*Xi{2VXmbOm)1`w^tm9% znM=0Fg4bDxH5PxPEm{P3#A(mxqlM7SIARP?|2&+c7qmU8kP&iApzL|F>Dz)Ixp_`O zP%xrP1M6@oYhgo$ZWwrAsYLa4 z|I;DAvJxno9HkQrhLPQk-8}=De{9U3U%)dJ$955?_AOms!9gia%)0E$Mp}$+0er@< zq7J&_SzvShM?e%V?_zUu{niL@gt5UFOjFJUJ}L?$f%eU%jUSoujr{^O=?=^{19`ON zlRIy8Uo_nqcPa6@yyz`CM?pMJ^^SN^Fqtt`GQ8Q#W4kE7`V9^LT}j#pMChl!j#g#J zr-=CCaV%xyFeQ9SK+mG(cTwW*)xa(eK;_Z(jy)woZp~> zA(4}-&VH+TEeLzPTqw&FOoK(ZjD~m{KW05fiGLe@E3Z2`rLukIDahE*`u!ubU)9`o zn^-lyht#E#-dt~S>}4y$-mSbR8{T@}22cn^refuQ08NjLOv?JiEWjyOnzk<^R5%gO zhUH_B{oz~u#IYwVnUg8?3P*#DqD8#X;%q%HY**=I>>-S|!X*-!x1{^l#OnR56O>iD zc;i;KS+t$koh)E3)w0OjWJl_aW2;xF=9D9Kr>)(5}4FqUbk# zI#$N8o0w;IChL49m9CJTzoC!|u{Ljd%ECgBOf$}&jA^$(V#P#~)`&g`H8E{uv52pp zwto`xUL-L&WTAVREEm$0g_gYPL(^vHq(*t1WCH_6alhkeW&GCZ3hL)|{O-jiFOBrF z!EW=Jej|dqQitT6!B-7&io2K)WIm~Q)v@yq%U|VpV+I?{y0@Yd%n8~-NuuM*pM~KA z85YB};IS~M(c<}4Hxx>qRK0cdl&e?t253N%vefkgds>Ubn8X}j6Vpgs>a#nFq$osY z1ZRwLqFv=+BTb=i%D2Wv>_yE0z}+niZ4?rE|*a3d7^kndWGwnFqt+iZ(7+aln<}jzbAQ(#Z2SS}3S$%Bd}^ zc9ghB%O)Z_mTZMRC&H#)I#fiLuIkGa^`4e~9oM5zKPx?zjkC&Xy0~r{;S?FS%c7w< zWbMpzc(xSw?9tGxG~_l}Acq}zjt5ClaB7-!vzqnlrX;}$#+PyQ9oU)_DfePh2E1<7 ztok6g6K^k^DuHR*iJ?jw?bs_whk|bx`dxu^nC6#e{1*m~z1eq7m}Cf$*^Eua(oi_I zAL+3opNhJteu&mWQ@kQWPucmiP)4|nFG`b2tpC;h{-PI@`+h?9v=9mn|0R-n8#t=+Z*FD(c5 zjj79Jxkgck*DV=wpFgRZuwr%}KTm+dx?RT@aUHJdaX-ODh~gByS?WGx&czAkvkg;x zrf92l8$Or_zOwJVwh>5rB`Q5_5}ef6DjS*$x30nZbuO3dijS*wvNEqTY5p1_A0gWr znH<(Qvb!os14|R)n2Ost>jS2;d1zyLHu`Svm|&dZD+PpP{Bh>U&`Md;gRl64q;>{8MJJM$?UNUd`aC>BiLe>*{ zJY15->yW+<3rLgYeTruFDtk1ovU<$(_y7#HgUq>)r0{^}Xbth}V#6?%5jeFYt;SG^ z3qF)=uWRU;Jj)Q}cpY8-H+l_n$2$6{ZR?&*IGr{>ek!69ZH0ZoJ*Ji+ezzlJ^%qL3 zO5a`6gwFw(moEzqxh=yJ9M1FTn!eo&qD#y5AZXErHs%22?A+JmS&GIolml!)rZTnUDM3YgzYfT#;OXn)`PWv3Ta z!-i|-Wojv*k&bC}_JJDjiAK(Ba|YZgUI{f}TdEOFT2+}nPmttytw7j%@bQZDV1vvj z^rp{gRkCDmYJHGrE1~e~AE!-&6B6`7UxVQuvRrfdFkGX8H~SNP_X4EodVd;lXd^>eV1jN+Tt4}Rsn)R0LxBz0c=NXU|pUe!MQQFkGBWbR3&(jLm z%RSLc#p}5_dO{GD=DEFr=Fc% z85CBF>*t!6ugI?soX(*JNxBp+-DdZ4X0LldiK}+WWGvXV(C(Ht|!3$psR=&c*HIM=BmX;pRIpz@Ale{9dhGe(U2|Giv;# zOc|;?p67J=Q(kamB*aus=|XP|m{jN^6@V*Bpm?ye56Njh#vyJqE=DweC;?Rv7faX~ zde03n^I~0B2vUmr;w^X37tVxUK?4}ifsSH5_kpKZIzpYu0;Kv}SBGfI2AKNp+VN#z`nI{UNDRbo-wqa4NEls zICRJpu)??cj^*WcZ^MAv+;bDbh~gpN$1Cor<{Y2oyIDws^JsfW^5AL$azE(T0p&pP z1Mv~6Q44R&RHoH95&OuGx2srIr<@zYJTOMKiVs;Bx3py89I87LOb@%mr`0)#;7_~Z zzcZj8?w=)>%5@HoCHE_&hnu(n_yQ-L(~VjpjjkbT7e)Dk5??fApg(d>vwLRJ-x{um z*Nt?DqTSxh_MIyogY!vf1mU1`Gld-&L)*43f6dilz`Q@HEz;+>MDDYv9u!s;WXeao zUq=TaL$P*IFgJzrGc>j1dDOd zed+=ZBo?w4mr$2)Ya}?vedDopomhW1`#P<%YOJ_j=WwClX0xJH-f@s?^tmzs_j7t!k zK@j^zS0Q|mM4tVP5Ram$VbS6|YDY&y?Q1r1joe9dj08#CM{RSMTU}(RCh`hp_Rkl- zGd|Cv~G@F{DLhCizAm9AN!^{rNs8hu!G@8RpnGx7e`-+K$ffN<0qjR zGq^$dj_Tv!n*?zOSyk5skI7JVKJ)3jysnjIu-@VSzQiP8r6MzudCU=~?v-U8yzo^7 zGf~SUTvEp+S*!X9uX!sq=o}lH;r{pzk~M*VA(uyQ`3C8!{C;)&6)95fv(cK!%Cuz$ z_Zal57H6kPN>25KNiI6z6F)jzEkh#%OqU#-__Xzy)KyH};81#N6OfX$$IXWzOn`Q& z4f$Z1t>)8&8PcYfEwY5UadU1yg+U*(1m2ZlHoC-!2?gB!!fLhmTl))D@dhvkx#+Yj z1O=LV{(T%{^IeCuFK>%QR!VZ4GnO5tK8a+thWE zg4VytZrwcS?7^ zuZfhYnB8dwd%VLO?DK7pV5Wi<(`~DYqOXn8#jUIL^)12*Dbhk4GmL_E2`WX&iT16o zk(t|hok(Y|v-wzn?4x34T)|+SfZP>fiq!><*%vnxGN~ypST-FtC+@TPv*vYv@iU!_ z@2gf|PrgQ?Ktf*9^CnJ(x*CtZVB8!OBfg0%!wL;Z8(tYYre0vcnPGlyCc$V(Ipl*P z_(J!a=o@vp^%Efme!K74(Ke7A>Y}|sxV+JL^aYa{~m%5#$$+R1? zGaQhZTTX!#s#=Xtpegqero$RNt&`4xn3g$)=y*;=N=Qai)}~`xtxI_N*#MMCIq#HFifT zz(-*m;pVH&+4bixL&Bbg)W5FN^bH87pAHp)zPkWNMfTFqS=l~AC$3FX3kQUSh_C?-ZftyClgM)o_D7cX$RGlEYblux0jv5 zTr|i-I3@ZPCGheCl~BGhImF)K4!9@?pC(gi3ozX=a!|r1)LFxy_8c&wY0<^{2cm|P zv6Y`QktY*;I)IUd5y3ne1CqpVanlY45z8hf4&$EUBnucDj16pDa4&GI&TArYhf*xh zdj>*%APH8(h~c>o@l#%T>R$e>rwVx_WUB|~V`p^JHsg*y12lzj&zF}w6W09HwB2yb z%Q~`es&(;7#*DUC_w-Dmt7|$*?TA_m;zB+-u{2;Bg{O}nV7G_@7~<)Bv8fH^G$XG8$(&{A zwXJK5LRK%M34(t$&NI~MHT{UQ9qN-V_yn|%PqC81EIiSzmMM=2zb`mIwiP_b)x+2M z7Gd`83h79j#SItpQ}luuf2uOU`my_rY5T{6P#BNlb%h%<#MZb=m@y5aW;#o1^2Z)SWo+b`y0gV^iRcZtz5!-05vF z7wNo=hc6h4hc&s@uL^jqRvD6thVYtbErDK9k!;+a0xoE0WL7zLixjn5;$fXvT=O3I zT6jI&^A7k6R{&5#lVjz#8%_RiAa2{di{`kx79K+j72$H(!ass|B%@l%KeeKchYLe_ z>!(JC2fxsv>XVen+Y42GeYPxMWqm`6F$(E<6^s|g(slNk!lL*6v^W2>f6hh^mE$s= z3D$)}{V5(Qm&A6bp%2Q}*GZ5Qrf}n7*Hr51?bJOyA-?B4vg6y_EX<*-e20h{=0Mxs zbuQGZ$fLyO5v$nQ&^kuH+mNq9O#MWSfThtH|0q1i!NrWj^S}_P;Q1OkYLW6U^?_7G zx2wg?CULj7))QU(n{$0JE%1t2dWrMi2g-Os{v|8^wK{@qlj%+1b^?NI z$}l2tjp0g>K3O+p%yK<9!XqmQ?E9>z&(|^Pi~aSRwI5x$jaA62GFz9%fmO3t3a>cq zK8Xbv=5Ps~4mKN5+Eqw12(!PEyedFXv~VLxMB~HwT1Vfo51pQ#D8e$e4pFZ{&RC2P z5gTIzl{3!&(tor^BwZfR8j4k{7Rq#`riKXP2O-Bh66#WWK2w=z;iD9GLl+3 zpHIaI4#lQ&S-xBK8PiQ%dwOh?%BO~DCo06pN7<^dnZCN@NzY{_Z1>rrB0U|nC&+!2 z2y!oBcTd2;@lzyk(B=TkyZ)zy0deK05*Q0zk+o$@nun`VI1Er7pjq>8V zNmlW{p7S^Btgb(TA}jL(uR>`0w8gHP^T~Sh5Tkip^spk4SBAhC{TZU}_Z)UJw-}zm zPq{KBm!k)?P{`-(9?LFt&YN4s%SIZ-9lJ!Ws~B%exHOeVFk3~}HewnnH(d)qkLQ_d z6h>O)pEE{vbOVw}E+jdYC^wM+AAhaI(YAibUc@B#_mDss0Ji&BK{WG`4 zOk>vSNq(Bq2IB@s>>Rxm6Wv?h;ZXkpb1l8u|+_qXWdC*jjcPCixq;!%BVPSp#hP zqo`%cNf&YoQXHC$D=D45RiT|5ngPlh?0T~?lUf*O)){K@*Kbh?3RW1j9-T?%lDk@y z4+~?wKI%Y!-=O|_IuKz|=)F;V7ps=5@g)RrE;;tvM$gUhG>jHcw2Hr@fS+k^Zr~>G z^JvPrZc}_&d_kEsqAEMTMJw!!CBw)u&ZVzmq+ZworuaE&TT>$pYsd9|g9O^0orAe8 z221?Va!l1|Y5X1Y?{G7rt1sX#qFA^?RLG^VjoxPf63;AS=_mVDfGJKg73L zsGdnTUD40y(>S##2l|W2Cy!H(@@5KBa(#gs`vlz}Y~$ot5VsqPQ{{YtjYFvIumZzt zA{CcxZLJR|4#{j7k~Tu*jkwz8QA|5G1$Cl895R`Zyp;irp1{KN){kB30O8P1W5;@bG znvX74roeMmQlUi=v9Y%(wl$ZC#9tKNFpvi3!C}f1m6Ct|l2g%psc{TJp)@yu)*e2> z((p0Fg*8gJ!|3WZke9;Z{8}&NRkv7iP=#_y-F}x^y?2m%-D_aj^)f04%mneyjo_;) z6qc_Zu$q37d~X``*eP~Q>I2gg%rrV8v=kDfpp$=%Vj}hF)^dsSWygoN(A$g*E=Do6FX?&(@F#7pbiJ`;c0c@Ul zDqW_90Wm#5f2L<(Lf3)3TeXtI7nhYwRm(F;*r_G6K@OPW4H(Y3O5SjUzBC}u3d|eQ8*8d@?;zUPE+i#QNMn=r(ap?2SH@vo*m z3HJ%XuG_S6;QbWy-l%qU;8x;>z>4pMW7>R}J%QLf%@1BY(4f_1iixd-6GlO7Vp*yU zp{VU^3?s?90i=!#>H`lxT!q8rk>W_$2~kbpz7eV{3wR|8E=8**5?qn8#n`*(bt1xRQrdGxyx2y%B$qmw#>ZV$c7%cO#%JM1lY$Y0q?Yuo> ze9KdJoiM)RH*SB%^;TAdX-zEjA7@%y=!0=Zg%iWK7jVI9b&Dk}0$Af&08KHo+ zOwDhFvA(E|ER%a^cdh@^wLUlmIv6?_3=BvX8jKk92L=Y}7Jf5OGMfh` zBdR1wFCi-i5@`9km{isRb0O%TX+f~)KNaEz{rXQa89`YIF;EN&gN)cigu6mNh>?Cm zAO&Im2flv6D{jwm+y<%WsPe4!89n~KN|7}Cb{Z;XweER73r}Qp2 zz}WP4j}U0&(uD&9yGy6`!+_v-S(yG*iytsTR#x_Rc>=6u^vnRDnf1gP{#2>`ffrAC% zTZ5WQ@hAK;P;>kX{D)mIXe4%a5p=LO1xXH@8T?mz7Q@d)$3pL{{B!2{-v70L*o1AO+|n5beiw~ zk@(>m?T3{2k2c;NWc^`4@P&Z?BjxXJ@;x1qhn)9Mn*IFdt_J-dIqx5#d`NfyfX~m( zIS~5)MfZ2Uy?_4W`47i}u0ZgPh<{D|w_d#;D}Q&U$Q-G}xM1A@1f{#%A$jh6Qp&0hQ<0bPOM z-{1Wm&p%%#eb_?x7i;bol EfAhh=DF6Tf literal 0 HcmV?d00001 diff --git a/hexagonaljava/.mvn/wrapper/maven-wrapper.properties b/hexagonaljava/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000..642d572ce9 --- /dev/null +++ b/hexagonaljava/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/hexagonaljava/mvnw b/hexagonaljava/mvnw new file mode 100755 index 0000000000..a16b5431b4 --- /dev/null +++ b/hexagonaljava/mvnw @@ -0,0 +1,310 @@ +#!/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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# 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 /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 + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -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 "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; 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="`which 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 + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# 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/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# 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. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +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 "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -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 + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/hexagonaljava/mvnw.cmd b/hexagonaljava/mvnw.cmd new file mode 100644 index 0000000000..c8d43372c9 --- /dev/null +++ b/hexagonaljava/mvnw.cmd @@ -0,0 +1,182 @@ +@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 Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@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 "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\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 DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_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 DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_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('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@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 "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\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% + +exit /B %ERROR_CODE% diff --git a/hexagonaljava/pom.xml b/hexagonaljava/pom.xml new file mode 100644 index 0000000000..d9ca173888 --- /dev/null +++ b/hexagonaljava/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.2.5.RELEASE + + + com.baeldung. + hexagonaljava + 0.0.1-SNAPSHOT + hexagonaljava + Demo project for Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + com.h2database + h2 + runtime + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java new file mode 100644 index 0000000000..603f8297d1 --- /dev/null +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.hexagonaljava; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HexagonaljavaApplication { + + public static void main(String[] args) { + SpringApplication.run(HexagonaljavaApplication.class, args); + } + +} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java new file mode 100644 index 0000000000..7db6117f83 --- /dev/null +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java @@ -0,0 +1,29 @@ +package com.baeldung.hexagonaljava.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.hexagonaljava.entity.Student; +import com.baeldung.hexagonaljava.service.StudentResultService; + +@RestController +public class StudentResultController { + + @Autowired + private StudentResultService studentResultService; + + @PostMapping(value = "/save") + public void saveStudent(@RequestBody Student student) { + studentResultService.save(student); + } + + @GetMapping(value = "/getTotalMarks/{id}") + public Double getTotalMarks(@PathVariable Integer id) { + return studentResultService.getTotalMarks(id); + } + +} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java new file mode 100644 index 0000000000..ef721e6eda --- /dev/null +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java @@ -0,0 +1,37 @@ +package com.baeldung.hexagonaljava.entity; + +import java.util.Map; + +public class Student { + + private Integer id; + + private String name; + + private Map marks; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Map getMarks() { + return marks; + } + + public void setMarks(Map marks) { + this.marks = marks; + } + +} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java new file mode 100644 index 0000000000..1d347346a2 --- /dev/null +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java @@ -0,0 +1,84 @@ +package com.baeldung.hexagonaljava.repository; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.jdbc.core.BatchPreparedStatementSetter; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.stereotype.Component; + +import com.baeldung.hexagonaljava.entity.Student; + +@Primary +@Component +public class StudentResultJdbcRepoImpl implements StudentResultRepo { + + @Autowired + JdbcTemplate jdbcTemplate; + + @Override + public void save(Student student) { + + jdbcTemplate.update("insert into student (id, name) " + "values(?, ?)", new Object[] { student.getId(), student.getName() }); + insertResult(student); + + } + + public void insertResult(Student student) { + + String insertQuery = "insert into " + "studentresult " + "(subject,marks,id) " + "values " + "(?,?,?)"; + + for (final Map.Entry entry : student.getMarks() + .entrySet()) { + + this.jdbcTemplate.batchUpdate(insertQuery, new BatchPreparedStatementSetter() { + + @Override + public void setValues(final PreparedStatement ps, final int i) throws SQLException { + + ps.setString(1, entry.getKey()); + ps.setDouble(2, entry.getValue()); + ps.setInt(3, student.getId()); + } + + public int getBatchSize() { + return student.getMarks() + .size(); + } + }); + } + + } + + @Override + public Student getStudent(Integer id) { + + String selectQuery = "select * from ( select * from student where id = ? ) s left join studentresult on s.id = studentresult.id"; + Student student = new Student(); + jdbcTemplate.query(selectQuery, new Object[] { id }, new RowCallbackHandler() { + public void processRow(ResultSet rs) throws SQLException { + while (rs.next()) { + + if (student.getId() == null) { + student.setId(rs.getInt("id")); + student.setName(rs.getString("name")); + student.setMarks(new HashMap()); + } + String subject = rs.getString("subject"); + Double marks = rs.getDouble("marks"); + student.getMarks() + .put(subject, marks); + + } + } + }); + return student; + } + +} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java new file mode 100644 index 0000000000..1ee4e2b9e5 --- /dev/null +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java @@ -0,0 +1,11 @@ +package com.baeldung.hexagonaljava.repository; + +import com.baeldung.hexagonaljava.entity.Student; + +public interface StudentResultRepo { + + void save(Student student); + + Student getStudent(Integer id); + +} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java new file mode 100644 index 0000000000..6c94aa0083 --- /dev/null +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java @@ -0,0 +1,26 @@ +package com.baeldung.hexagonaljava.repository; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.stereotype.Repository; + +import com.baeldung.hexagonaljava.entity.Student; + +@Repository +public class StudentResultRepoImpl implements StudentResultRepo { + + private Map studentsMap = new HashMap(); + + @Override + public void save(Student student) { + studentsMap.put(student.getId(), student); + + } + + @Override + public Student getStudent(Integer id) { + return studentsMap.get(id); + } + +} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java new file mode 100644 index 0000000000..d77ac5dca8 --- /dev/null +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java @@ -0,0 +1,11 @@ +package com.baeldung.hexagonaljava.service; + +import com.baeldung.hexagonaljava.entity.Student; + +public interface StudentResultService { + + public void save(Student student); + + public Double getTotalMarks(Integer id); + +} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java new file mode 100644 index 0000000000..d0b53e79f6 --- /dev/null +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java @@ -0,0 +1,32 @@ +package com.baeldung.hexagonaljava.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.baeldung.hexagonaljava.entity.Student; +import com.baeldung.hexagonaljava.repository.StudentResultRepo; + +@Component +public class StudentResultServiceImpl implements StudentResultService { + + @Autowired + private StudentResultRepo studentResultRepo; + + @Override + public void save(Student student) { + studentResultRepo.save(student); + + } + + @Override + public Double getTotalMarks(Integer id) { + Student student = studentResultRepo.getStudent(id); + double totalMarks = 0; + for (double marks : student.getMarks() + .values()) { + totalMarks += marks; + } + return totalMarks; + } + +} diff --git a/hexagonaljava/src/main/resources/application.properties b/hexagonaljava/src/main/resources/application.properties new file mode 100644 index 0000000000..5952b7eb01 --- /dev/null +++ b/hexagonaljava/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= +spring.h2.console.enabled=false diff --git a/hexagonaljava/src/main/resources/schema.sql b/hexagonaljava/src/main/resources/schema.sql new file mode 100644 index 0000000000..4dab9fbb1f --- /dev/null +++ b/hexagonaljava/src/main/resources/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE STUDENT ( + id INT PRIMARY KEY, + name VARCHAR(250) NOT NULL +); + +CREATE TABLE STUDENTRESULT( +subject VARCHAR(250) NOT NULL, +marks NUMERIC(8,2), +id VARCHAR(250), +FOREIGN KEY (id) references STUDENT(id) +); \ No newline at end of file diff --git a/hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java b/hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java new file mode 100644 index 0000000000..c61c51f7b2 --- /dev/null +++ b/hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java @@ -0,0 +1,13 @@ +package com.baeldung.hexagonaljava; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class HexagonaljavaApplicationTests { + + @Test + void contextLoads() { + } + +} From 635e2ae55c1bdc3c1ec74960d76abf96f2729bca Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Fri, 27 Mar 2020 00:40:04 +0530 Subject: [PATCH 002/309] removing unnecessary maven files from pull request and spaces in code --- hexagonaljava/.gitignore | 31 -- .../.mvn/wrapper/MavenWrapperDownloader.java | 117 ------- hexagonaljava/.mvn/wrapper/maven-wrapper.jar | Bin 50710 -> 0 bytes .../.mvn/wrapper/maven-wrapper.properties | 2 - hexagonaljava/mvnw | 310 ------------------ hexagonaljava/mvnw.cmd | 182 ---------- .../HexagonaljavaApplication.java | 1 - .../controller/StudentResultController.java | 1 - .../hexagonaljava/entity/Student.java | 1 - .../repository/StudentResultJdbcRepoImpl.java | 17 +- .../repository/StudentResultRepo.java | 1 - .../repository/StudentResultRepoImpl.java | 2 - .../service/StudentResultService.java | 5 +- .../service/StudentResultServiceImpl.java | 4 +- hexagonaljava/src/main/resources/schema.sql | 2 +- 15 files changed, 7 insertions(+), 669 deletions(-) delete mode 100644 hexagonaljava/.gitignore delete mode 100644 hexagonaljava/.mvn/wrapper/MavenWrapperDownloader.java delete mode 100644 hexagonaljava/.mvn/wrapper/maven-wrapper.jar delete mode 100644 hexagonaljava/.mvn/wrapper/maven-wrapper.properties delete mode 100755 hexagonaljava/mvnw delete mode 100644 hexagonaljava/mvnw.cmd diff --git a/hexagonaljava/.gitignore b/hexagonaljava/.gitignore deleted file mode 100644 index a2a3040aa8..0000000000 --- a/hexagonaljava/.gitignore +++ /dev/null @@ -1,31 +0,0 @@ -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/** -!**/src/test/** - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ - -### VS Code ### -.vscode/ diff --git a/hexagonaljava/.mvn/wrapper/MavenWrapperDownloader.java b/hexagonaljava/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index e76d1f3241..0000000000 --- a/hexagonaljava/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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(); - } - -} diff --git a/hexagonaljava/.mvn/wrapper/maven-wrapper.jar b/hexagonaljava/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index 2cc7d4a55c0cd0092912bf49ae38b3a9e3fd0054..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 50710 zcmbTd1CVCTmM+|7+wQV$+qP}n>auOywyU~q+qUhh+uxis_~*a##hm*_WW?9E7Pb7N%LRFiwbEGCJ0XP=%-6oeT$XZcYgtzC2~q zk(K08IQL8oTl}>>+hE5YRgXTB@fZ4TH9>7=79e`%%tw*SQUa9~$xKD5rS!;ZG@ocK zQdcH}JX?W|0_Afv?y`-NgLum62B&WSD$-w;O6G0Sm;SMX65z)l%m1e-g8Q$QTI;(Q z+x$xth4KFvH@Bs6(zn!iF#nenk^Y^ce;XIItAoCsow38eq?Y-Auh!1in#Rt-_D>H^ z=EjbclGGGa6VnaMGmMLj`x3NcwA43Jb(0gzl;RUIRAUDcR1~99l2SAPkVhoRMMtN} zXvC<tOmX83grD8GSo_Lo?%lNfhD#EBgPo z*nf@ppMC#B!T)Ae0RG$mlJWmGl7CkuU~B8-==5i;rS;8i6rJ=PoQxf446XDX9g|c> zU64ePyMlsI^V5Jq5A+BPe#e73+kpc_r1tv#B)~EZ;7^67F0*QiYfrk0uVW;Qb=NsG zN>gsuCwvb?s-KQIppEaeXtEMdc9dy6Dfduz-tMTms+i01{eD9JE&h?Kht*$eOl#&L zJdM_-vXs(V#$Ed;5wyNWJdPNh+Z$+;$|%qR(t`4W@kDhd*{(7-33BOS6L$UPDeE_53j${QfKN-0v-HG z(QfyvFNbwPK%^!eIo4ac1;b>c0vyf9}Xby@YY!lkz-UvNp zwj#Gg|4B~?n?G^{;(W;|{SNoJbHTMpQJ*Wq5b{l9c8(%?Kd^1?H1om1de0Da9M;Q=n zUfn{f87iVb^>Exl*nZ0hs(Yt>&V9$Pg`zX`AI%`+0SWQ4Zc(8lUDcTluS z5a_KerZWe}a-MF9#Cd^fi!y3%@RFmg&~YnYZ6<=L`UJ0v={zr)>$A;x#MCHZy1st7 ztT+N07NR+vOwSV2pvWuN1%lO!K#Pj0Fr>Q~R40{bwdL%u9i`DSM4RdtEH#cW)6}+I-eE< z&tZs+(Ogu(H_;$a$!7w`MH0r%h&@KM+<>gJL@O~2K2?VrSYUBbhCn#yy?P)uF3qWU z0o09mIik+kvzV6w>vEZy@&Mr)SgxPzUiDA&%07m17udz9usD82afQEps3$pe!7fUf z0eiidkJ)m3qhOjVHC_M(RYCBO%CZKZXFb8}s0-+}@CIn&EF(rRWUX2g^yZCvl0bI} zbP;1S)iXnRC&}5-Tl(hASKqdSnO?ASGJ*MIhOXIblmEudj(M|W!+I3eDc}7t`^mtg z)PKlaXe(OH+q-)qcQ8a@!llRrpGI8DsjhoKvw9T;TEH&?s=LH0w$EzI>%u;oD@x83 zJL7+ncjI9nn!TlS_KYu5vn%f*@qa5F;| zEFxY&B?g=IVlaF3XNm_03PA)=3|{n-UCgJoTr;|;1AU9|kPE_if8!Zvb}0q$5okF$ zHaJdmO&gg!9oN|M{!qGE=tb|3pVQ8PbL$}e;NgXz<6ZEggI}wO@aBP**2Wo=yN#ZC z4G$m^yaM9g=|&!^ft8jOLuzc3Psca*;7`;gnHm}tS0%f4{|VGEwu45KptfNmwxlE~ z^=r30gi@?cOm8kAz!EylA4G~7kbEiRlRIzwrb~{_2(x^$-?|#e6Bi_**(vyr_~9Of z!n>Gqf+Qwiu!xhi9f53=PM3`3tNF}pCOiPU|H4;pzjcsqbwg*{{kyrTxk<;mx~(;; z1NMrpaQ`57yn34>Jo3b|HROE(UNcQash!0p2-!Cz;{IRv#Vp5!3o$P8!%SgV~k&Hnqhp`5eLjTcy93cK!3Hm-$`@yGnaE=?;*2uSpiZTs_dDd51U%i z{|Zd9ou-;laGS_x=O}a+ zB||za<795A?_~Q=r=coQ+ZK@@ zId~hWQL<%)fI_WDIX#=(WNl!Dm$a&ROfLTd&B$vatq!M-2Jcs;N2vps$b6P1(N}=oI3<3luMTmC|0*{ zm1w8bt7vgX($!0@V0A}XIK)w!AzUn7vH=pZEp0RU0p?}ch2XC-7r#LK&vyc2=-#Q2 z^L%8)JbbcZ%g0Du;|8=q8B>X=mIQirpE=&Ox{TiuNDnOPd-FLI^KfEF729!!0x#Es z@>3ursjFSpu%C-8WL^Zw!7a0O-#cnf`HjI+AjVCFitK}GXO`ME&on|^=~Zc}^LBp9 zj=-vlN;Uc;IDjtK38l7}5xxQF&sRtfn4^TNtnzXv4M{r&ek*(eNbIu!u$>Ed%` z5x7+&)2P&4>0J`N&ZP8$vcR+@FS0126s6+Jx_{{`3ZrIMwaJo6jdrRwE$>IU_JTZ} z(||hyyQ)4Z1@wSlT94(-QKqkAatMmkT7pCycEB1U8KQbFX&?%|4$yyxCtm3=W`$4fiG0WU3yI@c zx{wfmkZAYE_5M%4{J-ygbpH|(|GD$2f$3o_Vti#&zfSGZMQ5_f3xt6~+{RX=$H8at z?GFG1Tmp}}lmm-R->ve*Iv+XJ@58p|1_jRvfEgz$XozU8#iJS})UM6VNI!3RUU!{5 zXB(+Eqd-E;cHQ>)`h0(HO_zLmzR3Tu-UGp;08YntWwMY-9i^w_u#wR?JxR2bky5j9 z3Sl-dQQU$xrO0xa&>vsiK`QN<$Yd%YXXM7*WOhnRdSFt5$aJux8QceC?lA0_if|s> ze{ad*opH_kb%M&~(~&UcX0nFGq^MqjxW?HJIP462v9XG>j(5Gat_)#SiNfahq2Mz2 zU`4uV8m$S~o9(W>mu*=h%Gs(Wz+%>h;R9Sg)jZ$q8vT1HxX3iQnh6&2rJ1u|j>^Qf`A76K%_ubL`Zu?h4`b=IyL>1!=*%!_K)=XC z6d}4R5L+sI50Q4P3upXQ3Z!~1ZXLlh!^UNcK6#QpYt-YC=^H=EPg3)z*wXo*024Q4b2sBCG4I# zlTFFY=kQ>xvR+LsuDUAk)q%5pEcqr(O_|^spjhtpb1#aC& zghXzGkGDC_XDa%t(X`E+kvKQ4zrQ*uuQoj>7@@ykWvF332)RO?%AA&Fsn&MNzmFa$ zWk&&^=NNjxLjrli_8ESU)}U|N{%j&TQmvY~lk!~Jh}*=^INA~&QB9em!in_X%Rl1&Kd~Z(u z9mra#<@vZQlOY+JYUwCrgoea4C8^(xv4ceCXcejq84TQ#sF~IU2V}LKc~Xlr_P=ry zl&Hh0exdCbVd^NPCqNNlxM3vA13EI8XvZ1H9#bT7y*U8Y{H8nwGpOR!e!!}*g;mJ#}T{ekSb}5zIPmye*If(}}_=PcuAW#yidAa^9-`<8Gr0 z)Fz=NiZ{)HAvw{Pl5uu)?)&i&Us$Cx4gE}cIJ}B4Xz~-q7)R_%owbP!z_V2=Aq%Rj z{V;7#kV1dNT9-6R+H}}(ED*_!F=~uz>&nR3gb^Ce%+0s#u|vWl<~JD3MvS0T9thdF zioIG3c#Sdsv;LdtRv3ml7%o$6LTVL>(H`^@TNg`2KPIk*8-IB}X!MT0`hN9Ddf7yN z?J=GxPL!uJ7lqwowsl?iRrh@#5C$%E&h~Z>XQcvFC*5%0RN-Opq|=IwX(dq(*sjs+ zqy99+v~m|6T#zR*e1AVxZ8djd5>eIeCi(b8sUk)OGjAsKSOg^-ugwl2WSL@d#?mdl zib0v*{u-?cq}dDGyZ%$XRY=UkQwt2oGu`zQneZh$=^! zj;!pCBWQNtvAcwcWIBM2y9!*W|8LmQy$H~5BEx)78J`4Z0(FJO2P^!YyQU{*Al+fs z){!4JvT1iLrJ8aU3k0t|P}{RN)_^v%$$r;+p0DY7N8CXzmS*HB*=?qaaF9D@#_$SN zSz{moAK<*RH->%r7xX~9gVW$l7?b|_SYI)gcjf0VAUJ%FcQP(TpBs; zg$25D!Ry_`8xpS_OJdeo$qh#7U+cepZ??TII7_%AXsT$B z=e)Bx#v%J0j``00Zk5hsvv6%T^*xGNx%KN-=pocSoqE5_R)OK%-Pbu^1MNzfds)mL zxz^F4lDKV9D&lEY;I+A)ui{TznB*CE$=9(wgE{m}`^<--OzV-5V4X2w9j(_!+jpTr zJvD*y6;39&T+==$F&tsRKM_lqa1HC}aGL0o`%c9mO=fts?36@8MGm7Vi{Y z^<7m$(EtdSr#22<(rm_(l_(`j!*Pu~Y>>xc>I9M#DJYDJNHO&4=HM%YLIp?;iR&$m z#_$ZWYLfGLt5FJZhr3jpYb`*%9S!zCG6ivNHYzNHcI%khtgHBliM^Ou}ZVD7ehU9 zS+W@AV=?Ro!=%AJ>Kcy9aU3%VX3|XM_K0A+ZaknKDyIS3S-Hw1C7&BSW5)sqj5Ye_ z4OSW7Yu-;bCyYKHFUk}<*<(@TH?YZPHr~~Iy%9@GR2Yd}J2!N9K&CN7Eq{Ka!jdu; zQNB*Y;i(7)OxZK%IHGt#Rt?z`I|A{q_BmoF!f^G}XVeTbe1Wnzh%1g>j}>DqFf;Rp zz7>xIs12@Ke0gr+4-!pmFP84vCIaTjqFNg{V`5}Rdt~xE^I;Bxp4)|cs8=f)1YwHz zqI`G~s2~qqDV+h02b`PQpUE#^^Aq8l%y2|ByQeXSADg5*qMprEAE3WFg0Q39`O+i1 z!J@iV!`Y~C$wJ!5Z+j5$i<1`+@)tBG$JL=!*uk=2k;T<@{|s1$YL079FvK%mPhyHV zP8^KGZnp`(hVMZ;s=n~3r2y;LTwcJwoBW-(ndU-$03{RD zh+Qn$ja_Z^OuMf3Ub|JTY74s&Am*(n{J3~@#OJNYuEVVJd9*H%)oFoRBkySGm`hx! zT3tG|+aAkXcx-2Apy)h^BkOyFTWQVeZ%e2@;*0DtlG9I3Et=PKaPt&K zw?WI7S;P)TWED7aSH$3hL@Qde?H#tzo^<(o_sv_2ci<7M?F$|oCFWc?7@KBj-;N$P zB;q!8@bW-WJY9do&y|6~mEruZAVe$!?{)N9rZZxD-|oltkhW9~nR8bLBGXw<632!l z*TYQn^NnUy%Ds}$f^=yQ+BM-a5X4^GHF=%PDrRfm_uqC zh{sKwIu|O0&jWb27;wzg4w5uA@TO_j(1X?8E>5Zfma|Ly7Bklq|s z9)H`zoAGY3n-+&JPrT!>u^qg9Evx4y@GI4$n-Uk_5wttU1_t?6><>}cZ-U+&+~JE) zPlDbO_j;MoxdLzMd~Ew|1o^a5q_1R*JZ=#XXMzg?6Zy!^hop}qoLQlJ{(%!KYt`MK z8umEN@Z4w!2=q_oe=;QttPCQy3Nm4F@x>@v4sz_jo{4m*0r%J(w1cSo;D_hQtJs7W z><$QrmG^+<$4{d2bgGo&3-FV}avg9zI|Rr(k{wTyl3!M1q+a zD9W{pCd%il*j&Ft z5H$nENf>>k$;SONGW`qo6`&qKs*T z2^RS)pXk9b@(_Fw1bkb)-oqK|v}r$L!W&aXA>IpcdNZ_vWE#XO8X`#Yp1+?RshVcd zknG%rPd*4ECEI0wD#@d+3NbHKxl}n^Sgkx==Iu%}HvNliOqVBqG?P2va zQ;kRJ$J6j;+wP9cS za#m;#GUT!qAV%+rdWolk+)6kkz4@Yh5LXP+LSvo9_T+MmiaP-eq6_k;)i6_@WSJ zlT@wK$zqHu<83U2V*yJ|XJU4farT#pAA&@qu)(PO^8PxEmPD4;Txpio+2)#!9 z>&=i7*#tc0`?!==vk>s7V+PL#S1;PwSY?NIXN2=Gu89x(cToFm))7L;< z+bhAbVD*bD=}iU`+PU+SBobTQ%S!=VL!>q$rfWsaaV}Smz>lO9JXT#`CcH_mRCSf4%YQAw`$^yY z3Y*^Nzk_g$xn7a_NO(2Eb*I=^;4f!Ra#Oo~LLjlcjke*k*o$~U#0ZXOQ5@HQ&T46l z7504MUgZkz2gNP1QFN8Y?nSEnEai^Rgyvl}xZfMUV6QrJcXp;jKGqB=D*tj{8(_pV zqyB*DK$2lgYGejmJUW)*s_Cv65sFf&pb(Yz8oWgDtQ0~k^0-wdF|tj}MOXaN@ydF8 zNr={U?=;&Z?wr^VC+`)S2xl}QFagy;$mG=TUs7Vi2wws5zEke4hTa2)>O0U?$WYsZ z<8bN2bB_N4AWd%+kncgknZ&}bM~eDtj#C5uRkp21hWW5gxWvc6b*4+dn<{c?w9Rmf zIVZKsPl{W2vQAlYO3yh}-{Os=YBnL8?uN5(RqfQ=-1cOiUnJu>KcLA*tQK3FU`_bM zM^T28w;nAj5EdAXFi&Kk1Nnl2)D!M{@+D-}bIEe+Lc4{s;YJc-{F#``iS2uk;2!Zp zF9#myUmO!wCeJIoi^A+T^e~20c+c2C}XltaR!|U-HfDA=^xF97ev}$l6#oY z&-&T{egB)&aV$3_aVA51XGiU07$s9vubh_kQG?F$FycvS6|IO!6q zq^>9|3U^*!X_C~SxX&pqUkUjz%!j=VlXDo$!2VLH!rKj@61mDpSr~7B2yy{>X~_nc zRI+7g2V&k zd**H++P9dg!-AOs3;GM`(g<+GRV$+&DdMVpUxY9I1@uK28$az=6oaa+PutlO9?6#? zf-OsgT>^@8KK>ggkUQRPPgC7zjKFR5spqQb3ojCHzj^(UH~v+!y*`Smv)VpVoPwa6 zWG18WJaPKMi*F6Zdk*kU^`i~NNTfn3BkJniC`yN98L-Awd)Z&mY? zprBW$!qL-OL7h@O#kvYnLsfff@kDIegt~?{-*5A7JrA;#TmTe?jICJqhub-G@e??D zqiV#g{)M!kW1-4SDel7TO{;@*h2=_76g3NUD@|c*WO#>MfYq6_YVUP+&8e4|%4T`w zXzhmVNziAHazWO2qXcaOu@R1MrPP{t)`N)}-1&~mq=ZH=w=;-E$IOk=y$dOls{6sRR`I5>|X zpq~XYW4sd;J^6OwOf**J>a7u$S>WTFPRkjY;BfVgQst)u4aMLR1|6%)CB^18XCz+r ztkYQ}G43j~Q&1em(_EkMv0|WEiKu;z2zhb(L%$F&xWwzOmk;VLBYAZ8lOCziNoPw1 zv2BOyXA`A8z^WH!nXhKXM`t0;6D*-uGds3TYGrm8SPnJJOQ^fJU#}@aIy@MYWz**H zvkp?7I5PE{$$|~{-ZaFxr6ZolP^nL##mHOErB^AqJqn^hFA=)HWj!m3WDaHW$C)i^ z9@6G$SzB=>jbe>4kqr#sF7#K}W*Cg-5y6kun3u&0L7BpXF9=#7IN8FOjWrWwUBZiU zT_se3ih-GBKx+Uw0N|CwP3D@-C=5(9T#BH@M`F2!Goiqx+Js5xC92|Sy0%WWWp={$(am!#l~f^W_oz78HX<0X#7 zp)p1u~M*o9W@O8P{0Qkg@Wa# z2{Heb&oX^CQSZWSFBXKOfE|tsAm#^U-WkDnU;IowZ`Ok4!mwHwH=s|AqZ^YD4!5!@ zPxJj+Bd-q6w_YG`z_+r;S86zwXb+EO&qogOq8h-Ect5(M2+>(O7n7)^dP*ws_3U6v zVsh)sk^@*c>)3EML|0<-YROho{lz@Nd4;R9gL{9|64xVL`n!m$-Jjrx?-Bacp!=^5 z1^T^eB{_)Y<9)y{-4Rz@9_>;_7h;5D+@QcbF4Wv7hu)s0&==&6u)33 zHRj+&Woq-vDvjwJCYES@$C4{$?f$Ibi4G()UeN11rgjF+^;YE^5nYprYoJNoudNj= zm1pXSeG64dcWHObUetodRn1Fw|1nI$D9z}dVEYT0lQnsf_E1x2vBLql7NrHH!n&Sq z6lc*mvU=WS6=v9Lrl}&zRiu_6u;6g%_DU{9b+R z#YHqX7`m9eydf?KlKu6Sb%j$%_jmydig`B*TN`cZL-g!R)iE?+Q5oOqBFKhx z%MW>BC^(F_JuG(ayE(MT{S3eI{cKiwOtPwLc0XO*{*|(JOx;uQOfq@lp_^cZo=FZj z4#}@e@dJ>Bn%2`2_WPeSN7si^{U#H=7N4o%Dq3NdGybrZgEU$oSm$hC)uNDC_M9xc zGzwh5Sg?mpBIE8lT2XsqTt3j3?We8}3bzLBTQd639vyg^$0#1epq8snlDJP2(BF)K zSx30RM+{f+b$g{9usIL8H!hCO117Xgv}ttPJm9wVRjPk;ePH@zxv%j9k5`TzdXLeT zFgFX`V7cYIcBls5WN0Pf6SMBN+;CrQ(|EsFd*xtwr#$R{Z9FP`OWtyNsq#mCgZ7+P z^Yn$haBJ)r96{ZJd8vlMl?IBxrgh=fdq_NF!1{jARCVz>jNdC)H^wfy?R94#MPdUjcYX>#wEx+LB#P-#4S-%YH>t-j+w zOFTI8gX$ard6fAh&g=u&56%3^-6E2tpk*wx3HSCQ+t7+*iOs zPk5ysqE}i*cQocFvA68xHfL|iX(C4h*67@3|5Qwle(8wT&!&{8*{f%0(5gH+m>$tq zp;AqrP7?XTEooYG1Dzfxc>W%*CyL16q|fQ0_jp%%Bk^k!i#Nbi(N9&T>#M{gez_Ws zYK=l}adalV(nH}I_!hNeb;tQFk3BHX7N}}R8%pek^E`X}%ou=cx8InPU1EE0|Hen- zyw8MoJqB5=)Z%JXlrdTXAE)eqLAdVE-=>wGHrkRet}>3Yu^lt$Kzu%$3#(ioY}@Gu zjk3BZuQH&~7H+C*uX^4}F*|P89JX;Hg2U!pt>rDi(n(Qe-c}tzb0#6_ItoR0->LSt zR~UT<-|@TO%O`M+_e_J4wx7^)5_%%u+J=yF_S#2Xd?C;Ss3N7KY^#-vx+|;bJX&8r zD?|MetfhdC;^2WG`7MCgs>TKKN=^=!x&Q~BzmQio_^l~LboTNT=I zC5pme^P@ER``p$2md9>4!K#vV-Fc1an7pl>_|&>aqP}+zqR?+~Z;f2^`a+-!Te%V? z;H2SbF>jP^GE(R1@%C==XQ@J=G9lKX+Z<@5}PO(EYkJh=GCv#)Nj{DkWJM2}F&oAZ6xu8&g7pn1ps2U5srwQ7CAK zN&*~@t{`31lUf`O;2w^)M3B@o)_mbRu{-`PrfNpF!R^q>yTR&ETS7^-b2*{-tZAZz zw@q5x9B5V8Qd7dZ!Ai$9hk%Q!wqbE1F1c96&zwBBaRW}(^axoPpN^4Aw}&a5dMe+*Gomky_l^54*rzXro$ z>LL)U5Ry>~FJi=*{JDc)_**c)-&faPz`6v`YU3HQa}pLtb5K)u%K+BOqXP0)rj5Au$zB zW1?vr?mDv7Fsxtsr+S6ucp2l#(4dnr9sD*v+@*>g#M4b|U?~s93>Pg{{a5|rm2xfI z`>E}?9S@|IoUX{Q1zjm5YJT|3S>&09D}|2~BiMo=z4YEjXlWh)V&qs;*C{`UMxp$9 zX)QB?G$fPD6z5_pNs>Jeh{^&U^)Wbr?2D6-q?)`*1k@!UvwQgl8eG$r+)NnFoT)L6 zg7lEh+E6J17krfYJCSjWzm67hEth24pomhz71|Qodn#oAILN)*Vwu2qpJirG)4Wnv}9GWOFrQg%Je+gNrPl8mw7ykE8{ z=|B4+uwC&bpp%eFcRU6{mxRV32VeH8XxX>v$du<$(DfinaaWxP<+Y97Z#n#U~V zVEu-GoPD=9$}P;xv+S~Ob#mmi$JQmE;Iz4(){y*9pFyW-jjgdk#oG$fl4o9E8bo|L zWjo4l%n51@Kz-n%zeSCD`uB?T%FVk+KBI}=ve zvlcS#wt`U6wrJo}6I6Rwb=1GzZfwE=I&Ne@p7*pH84XShXYJRgvK)UjQL%R9Zbm(m zxzTQsLTON$WO7vM)*vl%Pc0JH7WhP;$z@j=y#avW4X8iqy6mEYr@-}PW?H)xfP6fQ z&tI$F{NNct4rRMSHhaelo<5kTYq+(?pY)Ieh8*sa83EQfMrFupMM@nfEV@EmdHUv9 z35uzIrIuo4#WnF^_jcpC@uNNaYTQ~uZWOE6P@LFT^1@$o&q+9Qr8YR+ObBkpP9=F+$s5+B!mX2~T zAuQ6RenX?O{IlLMl1%)OK{S7oL}X%;!XUxU~xJN8xk z`xywS*naF(J#?vOpB(K=o~lE;m$zhgPWDB@=p#dQIW>xe_p1OLoWInJRKbEuoncf; zmS1!u-ycc1qWnDg5Nk2D)BY%jmOwCLC+Ny>`f&UxFowIsHnOXfR^S;&F(KXd{ODlm z$6#1ccqt-HIH9)|@fHnrKudu!6B$_R{fbCIkSIb#aUN|3RM>zuO>dpMbROZ`^hvS@ z$FU-;e4W}!ubzKrU@R*dW*($tFZ>}dd*4_mv)#O>X{U@zSzQt*83l9mI zI$8O<5AIDx`wo0}f2fsPC_l>ONx_`E7kdXu{YIZbp1$(^oBAH({T~&oQ&1{X951QW zmhHUxd)t%GQ9#ak5fTjk-cahWC;>^Rg7(`TVlvy0W@Y!Jc%QL3Ozu# zDPIqBCy&T2PWBj+d-JA-pxZlM=9ja2ce|3B(^VCF+a*MMp`(rH>Rt6W1$;r{n1(VK zLs>UtkT43LR2G$AOYHVailiqk7naz2yZGLo*xQs!T9VN5Q>eE(w zw$4&)&6xIV$IO^>1N-jrEUg>O8G4^@y+-hQv6@OmF@gy^nL_n1P1-Rtyy$Bl;|VcV zF=p*&41-qI5gG9UhKmmnjs932!6hceXa#-qfK;3d*a{)BrwNFeKU|ge?N!;zk+kB! zMD_uHJR#%b54c2tr~uGPLTRLg$`fupo}cRJeTwK;~}A>(Acy4k-Xk&Aa1&eWYS1ULWUj@fhBiWY$pdfy+F z@G{OG{*v*mYtH3OdUjwEr6%_ZPZ3P{@rfbNPQG!BZ7lRyC^xlMpWH`@YRar`tr}d> z#wz87t?#2FsH-jM6m{U=gp6WPrZ%*w0bFm(T#7m#v^;f%Z!kCeB5oiF`W33W5Srdt zdU?YeOdPG@98H7NpI{(uN{FJdu14r(URPH^F6tOpXuhU7T9a{3G3_#Ldfx_nT(Hec zo<1dyhsVsTw;ZkVcJ_0-h-T3G1W@q)_Q30LNv)W?FbMH+XJ* zy=$@39Op|kZv`Rt>X`zg&at(?PO^I=X8d9&myFEx#S`dYTg1W+iE?vt#b47QwoHI9 zNP+|3WjtXo{u}VG(lLUaW0&@yD|O?4TS4dfJI`HC-^q;M(b3r2;7|FONXphw-%7~* z&;2!X17|05+kZOpQ3~3!Nb>O94b&ZSs%p)TK)n3m=4eiblVtSx@KNFgBY_xV6ts;NF;GcGxMP8OKV^h6LmSb2E#Qnw ze!6Mnz7>lE9u{AgQ~8u2zM8CYD5US8dMDX-5iMlgpE9m*s+Lh~A#P1er*rF}GHV3h z=`STo?kIXw8I<`W0^*@mB1$}pj60R{aJ7>C2m=oghKyxMbFNq#EVLgP0cH3q7H z%0?L93-z6|+jiN|@v>ix?tRBU(v-4RV`}cQH*fp|)vd3)8i9hJ3hkuh^8dz{F5-~_ zUUr1T3cP%cCaTooM8dj|4*M=e6flH0&8ve32Q)0dyisl))XkZ7Wg~N}6y`+Qi2l+e zUd#F!nJp{#KIjbQdI`%oZ`?h=5G^kZ_uN`<(`3;a!~EMsWV|j-o>c?x#;zR2ktiB! z);5rrHl?GPtr6-o!tYd|uK;Vbsp4P{v_4??=^a>>U4_aUXPWQ$FPLE4PK$T^3Gkf$ zHo&9$U&G`d(Os6xt1r?sg14n)G8HNyWa^q8#nf0lbr4A-Fi;q6t-`pAx1T*$eKM*$ z|CX|gDrk#&1}>5H+`EjV$9Bm)Njw&7-ZR{1!CJTaXuP!$Pcg69`{w5BRHysB$(tWUes@@6aM69kb|Lx$%BRY^-o6bjH#0!7b;5~{6J+jKxU!Kmi# zndh@+?}WKSRY2gZ?Q`{(Uj|kb1%VWmRryOH0T)f3cKtG4oIF=F7RaRnH0Rc_&372={_3lRNsr95%ZO{IX{p@YJ^EI%+gvvKes5cY+PE@unghjdY5#9A!G z70u6}?zmd?v+{`vCu-53_v5@z)X{oPC@P)iA3jK$`r zSA2a7&!^zmUiZ82R2=1cumBQwOJUPz5Ay`RLfY(EiwKkrx%@YN^^XuET;tE zmr-6~I7j!R!KrHu5CWGSChO6deaLWa*9LLJbcAJsFd%Dy>a!>J`N)Z&oiU4OEP-!Ti^_!p}O?7`}i7Lsf$-gBkuY*`Zb z7=!nTT;5z$_5$=J=Ko+Cp|Q0J=%oFr>hBgnL3!tvFoLNhf#D0O=X^h+x08iB;@8pXdRHxX}6R4k@i6%vmsQwu^5z zk1ip`#^N)^#Lg#HOW3sPI33xqFB4#bOPVnY%d6prwxf;Y-w9{ky4{O6&94Ra8VN@K zb-lY;&`HtxW@sF!doT5T$2&lIvJpbKGMuDAFM#!QPXW87>}=Q4J3JeXlwHys?!1^#37q_k?N@+u&Ns20pEoBeZC*np;i;M{2C0Z4_br2gsh6eL z#8`#sn41+$iD?^GL%5?cbRcaa-Nx0vE(D=*WY%rXy3B%gNz0l?#noGJGP728RMY#q z=2&aJf@DcR?QbMmN)ItUe+VM_U!ryqA@1VVt$^*xYt~-qvW!J4Tp<-3>jT=7Zow5M z8mSKp0v4b%a8bxFr>3MwZHSWD73D@+$5?nZAqGM#>H@`)mIeC#->B)P8T$zh-Pxnc z8)~Zx?TWF4(YfKuF3WN_ckpCe5;x4V4AA3(i$pm|78{%!q?|~*eH0f=?j6i)n~Hso zmTo>vqEtB)`%hP55INf7HM@taH)v`Fw40Ayc*R!T?O{ziUpYmP)AH`euTK!zg9*6Z z!>M=$3pd0!&TzU=hc_@@^Yd3eUQpX4-33}b{?~5t5lgW=ldJ@dUAH%`l5US1y_`40 zs(X`Qk}vvMDYYq+@Rm+~IyCX;iD~pMgq^KY)T*aBz@DYEB={PxA>)mI6tM*sx-DmGQHEaHwRrAmNjO!ZLHO4b;;5mf@zzlPhkP($JeZGE7 z?^XN}Gf_feGoG~BjUgVa*)O`>lX=$BSR2)uD<9 z>o^|nb1^oVDhQbfW>>!;8-7<}nL6L^V*4pB=>wwW+RXAeRvKED(n1;R`A6v$6gy0I(;Vf?!4;&sgn7F%LpM}6PQ?0%2Z@b{It<(G1CZ|>913E0nR2r^Pa*Bp z@tFGi*CQ~@Yc-?{cwu1 zsilf=k^+Qs>&WZG(3WDixisHpR>`+ihiRwkL(3T|=xsoNP*@XX3BU8hr57l3k;pni zI``=3Nl4xh4oDj<%>Q1zYXHr%Xg_xrK3Nq?vKX3|^Hb(Bj+lONTz>4yhU-UdXt2>j z<>S4NB&!iE+ao{0Tx^N*^|EZU;0kJkx@zh}S^P{ieQjGl468CbC`SWnwLRYYiStXm zOxt~Rb3D{dz=nHMcY)#r^kF8|q8KZHVb9FCX2m^X*(|L9FZg!5a7((!J8%MjT$#Fs)M1Pb zq6hBGp%O1A+&%2>l0mpaIzbo&jc^!oN^3zxap3V2dNj3x<=TwZ&0eKX5PIso9j1;e zwUg+C&}FJ`k(M|%%}p=6RPUq4sT3-Y;k-<68ciZ~_j|bt>&9ZLHNVrp#+pk}XvM{8 z`?k}o-!if>hVlCP9j%&WI2V`5SW)BCeR5>MQhF)po=p~AYN%cNa_BbV6EEh_kk^@a zD>4&>uCGCUmyA-c)%DIcF4R6!>?6T~Mj_m{Hpq`*(wj>foHL;;%;?(((YOxGt)Bhx zuS+K{{CUsaC++%}S6~CJ=|vr(iIs-je)e9uJEU8ZJAz)w166q)R^2XI?@E2vUQ!R% zn@dxS!JcOimXkWJBz8Y?2JKQr>`~SmE2F2SL38$SyR1^yqj8_mkBp)o$@+3BQ~Mid z9U$XVqxX3P=XCKj0*W>}L0~Em`(vG<>srF8+*kPrw z20{z(=^w+ybdGe~Oo_i|hYJ@kZl*(9sHw#Chi&OIc?w`nBODp?ia$uF%Hs(X>xm?j zqZQ`Ybf@g#wli`!-al~3GWiE$K+LCe=Ndi!#CVjzUZ z!sD2O*;d28zkl))m)YN7HDi^z5IuNo3^w(zy8 zszJG#mp#Cj)Q@E@r-=NP2FVxxEAeOI2e=|KshybNB6HgE^(r>HD{*}S}mO>LuRGJT{*tfTzw_#+er-0${}%YPe@CMJ1Ng#j#)i)SnY@ss3gL;g zg2D~#Kpdfu#G;q1qz_TwSz1VJT(b3zby$Vk&;Y#1(A)|xj`_?i5YQ;TR%jice5E;0 zYHg;`zS5{S*9xI6o^j>rE8Ua*XhIw{_-*&@(R|C(am8__>+Ws&Q^ymy*X4~hR2b5r zm^p3sw}yv=tdyncy_Ui7{BQS732et~Z_@{-IhHDXAV`(Wlay<#hb>%H%WDi+K$862nA@BDtM#UCKMu+kM`!JHyWSi?&)A7_ z3{cyNG%a~nnH_!+;g&JxEMAmh-Z}rC!o7>OVzW&PoMyTA_g{hqXG)SLraA^OP**<7 zjWbr7z!o2n3hnx7A=2O=WL;`@9N{vQIM@&|G-ljrPvIuJHYtss0Er0fT5cMXNUf1B z7FAwBDixt0X7C3S)mPe5g`YtME23wAnbU)+AtV}z+e8G;0BP=bI;?(#|Ep!vVfDbK zvx+|CKF>yt0hWQ3drchU#XBU+HiuG*V^snFAPUp-5<#R&BUAzoB!aZ+e*KIxa26V}s6?nBK(U-7REa573wg-jqCg>H8~>O{ z*C0JL-?X-k_y%hpUFL?I>0WV{oV`Nb)nZbJG01R~AG>flIJf)3O*oB2i8~;!P?Wo_ z0|QEB*fifiL6E6%>tlAYHm2cjTFE@*<);#>689Z6S#BySQ@VTMhf9vYQyLeDg1*F} zjq>i1*x>5|CGKN{l9br3kB0EHY|k4{%^t7-uhjd#NVipUZa=EUuE5kS1_~qYX?>hJ z$}!jc9$O$>J&wnu0SgfYods^z?J4X;X7c77Me0kS-dO_VUQ39T(Kv(Y#s}Qqz-0AH z^?WRL(4RzpkD+T5FG_0NyPq-a-B7A5LHOCqwObRJi&oRi(<;OuIN7SV5PeHU$<@Zh zPozEV`dYmu0Z&Tqd>t>8JVde9#Pt+l95iHe$4Xwfy1AhI zDM4XJ;bBTTvRFtW>E+GzkN)9k!hA5z;xUOL2 zq4}zn-DP{qc^i|Y%rvi|^5k-*8;JZ~9a;>-+q_EOX+p1Wz;>i7c}M6Nv`^NY&{J-> z`(mzDJDM}QPu5i44**2Qbo(XzZ-ZDu%6vm8w@DUarqXj41VqP~ zs&4Y8F^Waik3y1fQo`bVUH;b=!^QrWb)3Gl=QVKr+6sxc=ygauUG|cm?|X=;Q)kQ8 zM(xrICifa2p``I7>g2R~?a{hmw@{!NS5`VhH8+;cV(F>B94M*S;5#O`YzZH1Z%yD? zZ61w(M`#aS-*~Fj;x|J!KM|^o;MI#Xkh0ULJcA?o4u~f%Z^16ViA27FxU5GM*rKq( z7cS~MrZ=f>_OWx8j#-Q3%!aEU2hVuTu(7`TQk-Bi6*!<}0WQi;_FpO;fhpL4`DcWp zGOw9vx0N~6#}lz(r+dxIGZM3ah-8qrqMmeRh%{z@dbUD2w15*_4P?I~UZr^anP}DB zU9CCrNiy9I3~d#&!$DX9e?A});BjBtQ7oGAyoI$8YQrkLBIH@2;lt4E^)|d6Jwj}z z&2_E}Y;H#6I4<10d_&P0{4|EUacwFHauvrjAnAm6yeR#}f}Rk27CN)vhgRqEyPMMS7zvunj2?`f;%?alsJ+-K+IzjJx>h8 zu~m_y$!J5RWAh|C<6+uiCNsOKu)E72M3xKK(a9Okw3e_*O&}7llNV!=P87VM2DkAk zci!YXS2&=P0}Hx|wwSc9JP%m8dMJA*q&VFB0yMI@5vWoAGraygwn){R+Cj6B1a2Px z5)u(K5{+;z2n*_XD!+Auv#LJEM)(~Hx{$Yb^ldQmcYF2zNH1V30*)CN_|1$v2|`LnFUT$%-tO0Eg|c5$BB~yDfzS zcOXJ$wpzVK0MfTjBJ0b$r#_OvAJ3WRt+YOLlJPYMx~qp>^$$$h#bc|`g0pF-Ao43? z>*A+8lx>}L{p(Tni2Vvk)dtzg$hUKjSjXRagj)$h#8=KV>5s)J4vGtRn5kP|AXIz! zPgbbVxW{2o4s-UM;c#We8P&mPN|DW7_uLF!a|^0S=wr6Esx9Z$2|c1?GaupU6$tb| zY_KU`(_29O_%k(;>^|6*pZURH3`@%EuKS;Ns z1lujmf;r{qAN&Q0&m{wJSZ8MeE7RM5+Sq;ul_ z`+ADrd_Um+G37js6tKsArNB}n{p*zTUxQr>3@wA;{EUbjNjlNd6$Mx zg0|MyU)v`sa~tEY5$en7^PkC=S<2@!nEdG6L=h(vT__0F=S8Y&eM=hal#7eM(o^Lu z2?^;05&|CNliYrq6gUv;|i!(W{0N)LWd*@{2q*u)}u*> z7MQgk6t9OqqXMln?zoMAJcc zMKaof_Up})q#DzdF?w^%tTI7STI^@8=Wk#enR*)&%8yje>+tKvUYbW8UAPg55xb70 zEn5&Ba~NmOJlgI#iS8W3-@N%>V!#z-ZRwfPO1)dQdQkaHsiqG|~we2ALqG7Ruup(DqSOft2RFg_X%3w?6VqvV1uzX_@F(diNVp z4{I|}35=11u$;?|JFBEE*gb;T`dy+8gWJ9~pNsecrO`t#V9jW-6mnfO@ff9od}b(3s4>p0i30gbGIv~1@a^F2kl7YO;DxmF3? zWi-RoXhzRJV0&XE@ACc?+@6?)LQ2XNm4KfalMtsc%4!Fn0rl zpHTrHwR>t>7W?t!Yc{*-^xN%9P0cs0kr=`?bQ5T*oOo&VRRu+1chM!qj%2I!@+1XF z4GWJ=7ix9;Wa@xoZ0RP`NCWw0*8247Y4jIZ>GEW7zuoCFXl6xIvz$ezsWgKdVMBH> z{o!A7f;R-@eK9Vj7R40xx)T<2$?F2E<>Jy3F;;=Yt}WE59J!1WN367 zA^6pu_zLoZIf*x031CcwotS{L8bJE(<_F%j_KJ2P_IusaZXwN$&^t716W{M6X2r_~ zaiMwdISX7Y&Qi&Uh0upS3TyEIXNDICQlT5fHXC`aji-c{U(J@qh-mWl-uMN|T&435 z5)a1dvB|oe%b2mefc=Vpm0C%IUYYh7HI*;3UdgNIz}R##(#{(_>82|zB0L*1i4B5j-xi9O4x10rs_J6*gdRBX=@VJ+==sWb&_Qc6tSOowM{BX@(zawtjl zdU!F4OYw2@Tk1L^%~JCwb|e#3CC>srRHQ*(N%!7$Mu_sKh@|*XtR>)BmWw!;8-mq7 zBBnbjwx8Kyv|hd*`5}84flTHR1Y@@uqjG`UG+jN_YK&RYTt7DVwfEDXDW4U+iO{>K zw1hr{_XE*S*K9TzzUlJH2rh^hUm2v7_XjwTuYap|>zeEDY$HOq3X4Tz^X}E9z)x4F zs+T?Ed+Hj<#jY-`Va~fT2C$=qFT-5q$@p9~0{G&eeL~tiIAHXA!f6C(rAlS^)&k<- zXU|ZVs}XQ>s5iONo~t!XXZgtaP$Iau;JT%h)>}v54yut~pykaNye4axEK#5@?TSsQ zE;Jvf9I$GVb|S`7$pG)4vgo9NXsKr?u=F!GnA%VS2z$@Z(!MR9?EPcAqi5ft)Iz6sNl`%kj+_H-X`R<>BFrBW=fSlD|{`D%@Rcbu2?%>t7i34k?Ujb)2@J-`j#4 zLK<69qcUuniIan-$A1+fR=?@+thwDIXtF1Tks@Br-xY zfB+zblrR(ke`U;6U~-;p1Kg8Lh6v~LjW@9l2P6s+?$2!ZRPX`(ZkRGe7~q(4&gEi<$ch`5kQ?*1=GSqkeV z{SA1EaW_A!t{@^UY2D^YO0(H@+kFVzZaAh0_`A`f(}G~EP~?B|%gtxu&g%^x{EYSz zk+T;_c@d;+n@$<>V%P=nk36?L!}?*=vK4>nJSm+1%a}9UlmTJTrfX4{Lb7smNQn@T zw9p2%(Zjl^bWGo1;DuMHN(djsEm)P8mEC2sL@KyPjwD@d%QnZ$ zMJ3cnn!_!iP{MzWk%PI&D?m?C(y2d|2VChluN^yHya(b`h>~GkI1y;}O_E57zOs!{ zt2C@M$^PR2U#(dZmA-sNreB@z-yb0Bf7j*yONhZG=onhx>t4)RB`r6&TP$n zgmN*)eCqvgriBO-abHQ8ECN0bw?z5Bxpx z=jF@?zFdVn?@gD5egM4o$m`}lV(CWrOKKq(sv*`mNcHcvw&Xryfw<{ch{O&qc#WCTXX6=#{MV@q#iHYba!OUY+MGeNTjP%Fj!WgM&`&RlI^=AWTOqy-o zHo9YFt!gQ*p7{Fl86>#-JLZo(b^O`LdFK~OsZBRR@6P?ad^Ujbqm_j^XycM4ZHFyg ziUbIFW#2tj`65~#2V!4z7DM8Z;fG0|APaQ{a2VNYpNotB7eZ5kp+tPDz&Lqs0j%Y4tA*URpcfi z_M(FD=fRGdqf430j}1z`O0I=;tLu81bwJXdYiN7_&a-?ly|-j*+=--XGvCq#32Gh(=|qj5F?kmihk{%M&$}udW5)DHK zF_>}5R8&&API}o0osZJRL3n~>76nUZ&L&iy^s>PMnNcYZ|9*1$v-bzbT3rpWsJ+y{ zPrg>5Zlery96Um?lc6L|)}&{992{_$J&=4%nRp9BAC6!IB=A&=tF>r8S*O-=!G(_( zwXbX_rGZgeiK*&n5E;f=k{ktyA1(;x_kiMEt0*gpp_4&(twlS2e5C?NoD{n>X2AT# zY@Zp?#!b1zNq96MQqeO*M1MMBin5v#RH52&Xd~DO6-BZLnA6xO1$sou(YJ1Dlc{WF zVa%2DyYm`V#81jP@70IJ;DX@y*iUt$MLm)ByAD$eUuji|5{ptFYq(q)mE(5bOpxjM z^Q`AHWq44SG3`_LxC9fwR)XRVIp=B%<(-lOC3jI#bb@dK(*vjom!=t|#<@dZql%>O z15y^{4tQoeW9Lu%G&V$90x6F)xN6y_oIn;!Q zs)8jT$;&;u%Y>=T3hg34A-+Y*na=|glcStr5D;&5*t5*DmD~x;zQAV5{}Ya`?RRGa zT*t9@$a~!co;pD^!J5bo?lDOWFx%)Y=-fJ+PDGc0>;=q=s?P4aHForSB+)v0WY2JH z?*`O;RHum6j%#LG)Vu#ciO#+jRC3!>T(9fr+XE7T2B7Z|0nR5jw@WG)kDDzTJ=o4~ zUpeyt7}_nd`t}j9BKqryOha{34erm)RmST)_9Aw)@ zHbiyg5n&E{_CQR@h<}34d7WM{s{%5wdty1l+KX8*?+-YkNK2Be*6&jc>@{Fd;Ps|| z26LqdI3#9le?;}risDq$K5G3yoqK}C^@-8z^wj%tdgw-6@F#Ju{Sg7+y)L?)U$ez> zoOaP$UFZ?y5BiFycir*pnaAaY+|%1%8&|(@VB)zweR%?IidwJyK5J!STzw&2RFx zZV@qeaCB01Hu#U9|1#=Msc8Pgz5P*4Lrp!Q+~(G!OiNR{qa7|r^H?FC6gVhkk3y7=uW#Sh;&>78bZ}aK*C#NH$9rX@M3f{nckYI+5QG?Aj1DM)@~z_ zw!UAD@gedTlePB*%4+55naJ8ak_;))#S;4ji!LOqY5VRI){GMwHR~}6t4g>5C_#U# ztYC!tjKjrKvRy=GAsJVK++~$|+s!w9z3H4G^mACv=EErXNSmH7qN}%PKcN|8%9=i)qS5+$L zu&ya~HW%RMVJi4T^pv?>mw*Gf<)-7gf#Qj|e#w2|v4#t!%Jk{&xlf;$_?jW*n!Pyx zkG$<18kiLOAUPuFfyu-EfWX%4jYnjBYc~~*9JEz6oa)_R|8wjZA|RNrAp%}14L7fW zi7A5Wym*K+V8pkqqO-X#3ft{0qs?KVt^)?kS>AicmeO&q+~J~ zp0YJ_P~_a8j= zsAs~G=8F=M{4GZL{|B__UorX@MRNQLn?*_gym4aW(~+i13knnk1P=khoC-ViMZk+x zLW(l}oAg1H`dU+Fv**;qw|ANDSRs>cGqL!Yw^`; zv;{E&8CNJcc)GHzTYM}f&NPw<6j{C3gaeelU#y!M)w-utYEHOCCJo|Vgp7K6C_$14 zqIrLUB0bsgz^D%V%fbo2f9#yb#CntTX?55Xy|Kps&Xek*4_r=KDZ z+`TQuv|$l}MWLzA5Ay6Cvsa^7xvwXpy?`w(6vx4XJ zWuf1bVSb#U8{xlY4+wlZ$9jjPk)X_;NFMqdgq>m&W=!KtP+6NL57`AMljW+es zzqjUjgz;V*kktJI?!NOg^s_)ph45>4UDA!Vo0hn>KZ+h-3=?Y3*R=#!fOX zP$Y~+14$f66ix?UWB_6r#fMcC^~X4R-<&OD1CSDNuX~y^YwJ>sW0j`T<2+3F9>cLo z#!j57$ll2K9(%$4>eA7(>FJX5e)pR5&EZK!IMQzOfik#FU*o*LGz~7u(8}XzIQRy- z!U7AlMTIe|DgQFmc%cHy_9^{o`eD%ja_L>ckU6$O4*U**o5uR7`FzqkU8k4gxtI=o z^P^oGFPm5jwZMI{;nH}$?p@uV8FT4r=|#GziKXK07bHJLtK}X%I0TON$uj(iJ`SY^ zc$b2CoxCQ>7LH@nxcdW&_C#fMYBtTxcg46dL{vf%EFCZ~eErMvZq&Z%Lhumnkn^4A zsx$ay(FnN7kYah}tZ@0?-0Niroa~13`?hVi6`ndno`G+E8;$<6^gsE-K3)TxyoJ4M zb6pj5=I8^FD5H@`^V#Qb2^0cx7wUz&cruA5g>6>qR5)O^t1(-qqP&1g=qvY#s&{bx zq8Hc%LsbK1*%n|Y=FfojpE;w~)G0-X4i*K3{o|J7`krhIOd*c*$y{WIKz2n2*EXEH zT{oml3Th5k*vkswuFXdGDlcLj15Nec5pFfZ*0?XHaF_lVuiB%Pv&p7z)%38}%$Gup zVTa~C8=cw%6BKn_|4E?bPNW4PT7}jZQLhDJhvf4z;~L)506IE0 zX!tWXX(QOQPRj-p80QG79t8T2^az4Zp2hOHziQlvT!|H)jv{Ixodabzv6lBj)6WRB z{)Kg@$~~(7$-az?lw$4@L%I&DI0Lo)PEJJziWP33a3azb?jyXt1v0N>2kxwA6b%l> zZqRpAo)Npi&loWbjFWtEV)783BbeIAhqyuc+~>i7aQ8shIXt)bjCWT6$~ro^>99G} z2XfmT0(|l!)XJb^E!#3z4oEGIsL(xd; zYX1`1I(cG|u#4R4T&C|m*9KB1`UzKvho5R@1eYtUL9B72{i(ir&ls8g!pD ztR|25xGaF!4z5M+U@@lQf(12?xGy`!|3E}7pI$k`jOIFjiDr{tqf0va&3pOn6Pu)% z@xtG2zjYuJXrV)DUrIF*y<1O1<$#54kZ#2;=X51J^F#0nZ0(;S$OZDt_U2bx{RZ=Q zMMdd$fH|!s{ zXq#l;{`xfV`gp&C>A`WrQU?d{!Ey5(1u*VLJt>i27aZ-^&2IIk=zP5p+{$q(K?2(b z8?9h)kvj9SF!Dr zoyF}?V|9;6abHxWk2cEvGs$-}Pg}D+ZzgkaN&$Snp%;5m%zh1E#?Wac-}x?BYlGN#U#Mek*}kek#I9XaHt?mz3*fDrRTQ#&#~xyeqJk1QJ~E$7qsw6 z?sV;|?*=-{M<1+hXoj?@-$y+(^BJ1H~wQ9G8C0#^aEAyhDduNX@haoa=PuPp zYsGv8UBfQaRHgBgLjmP^eh>fLMeh{8ic)?xz?#3kX-D#Z{;W#cd_`9OMFIaJg-=t`_3*!YDgtNQ2+QUEAJB9M{~AvT$H`E)IKmCR21H532+ata8_i_MR@ z2Xj<3w<`isF~Ah$W{|9;51ub*f4#9ziKrOR&jM{x7I_7()O@`F*5o$KtZ?fxU~g`t zUovNEVKYn$U~VX8eR)qb`7;D8pn*Pp$(otYTqL)5KH$lUS-jf}PGBjy$weoceAcPp z&5ZYB$r&P$MN{0H0AxCe4Qmd3T%M*5d4i%#!nmBCN-WU-4m4Tjxn-%j3HagwTxCZ9 z)j5vO-C7%s%D!&UfO>bi2oXiCw<-w{vVTK^rVbv#W=WjdADJy8$khnU!`ZWCIU`># zyjc^1W~pcu>@lDZ{zr6gv%)2X4n27~Ve+cQqcND%0?IFSP4sH#yIaXXYAq^z3|cg` z`I3$m%jra>e2W-=DiD@84T!cb%||k)nPmEE09NC%@PS_OLhkrX*U!cgD*;;&gIaA(DyVT4QD+q_xu z>r`tg{hiGY&DvD-)B*h+YEd+Zn)WylQl}<4>(_NlsKXCRV;a)Rcw!wtelM2_rWX`j zTh5A|i6=2BA(iMCnj_fob@*eA;V?oa4Z1kRBGaU07O70fb6-qmA$Hg$ps@^ka1=RO zTbE_2#)1bndC3VuK@e!Sftxq4=Uux}fDxXE#Q5_x=E1h>T5`DPHz zbH<_OjWx$wy7=%0!mo*qH*7N4tySm+R0~(rbus`7;+wGh;C0O%x~fEMkt!eV>U$`i z5>Q(o z=t$gPjgGh0&I7KY#k50V7DJRX<%^X z>6+ebc9efB3@eE2Tr){;?_w`vhgF>`-GDY(YkR{9RH(MiCnyRtd!LxXJ75z+?2 zGi@m^+2hKJ5sB1@Xi@s_@p_Kwbc<*LQ_`mr^Y%j}(sV_$`J(?_FWP)4NW*BIL~sR>t6 zM;qTJZ~GoY36&{h-Pf}L#y2UtR}>ZaI%A6VkU>vG4~}9^i$5WP2Tj?Cc}5oQxe2=q z8BeLa$hwCg_psjZyC2+?yX4*hJ58Wu^w9}}7X*+i5Rjqu5^@GzXiw#SUir1G1`jY% zOL=GE_ENYxhcyUrEt9XlMNP6kx6h&%6^u3@zB8KUCAa18T(R2J`%JjWZ z!{7cXaEW+Qu*iJPu+m>QqW}Lo$4Z+!I)0JNzZ&_M%=|B1yejFRM04bGAvu{=lNPd+ zJRI^DRQ(?FcVUD+bgEcAi@o(msqys9RTCG#)TjI!9~3-dc`>gW;HSJuQvH~d`MQs86R$|SKXHh zqS9Qy)u;T`>>a!$LuaE2keJV%;8g)tr&Nnc;EkvA-RanHXsy)D@XN0a>h}z2j81R; zsUNJf&g&rKpuD0WD@=dDrPHdBoK42WoBU|nMo17o(5^;M|dB4?|FsAGVrSyWcI`+FVw^vTVC`y}f(BwJl zrw3Sp151^9=}B})6@H*i4-dIN_o^br+BkcLa^H56|^2XsT0dESw2 zMX>(KqNl=x2K5=zIKg}2JpGAZu{I_IO}0$EQ5P{4zol**PCt3F4`GX}2@vr8#Y)~J zKb)gJeHcFnR@4SSh%b;c%J`l=W*40UPjF#q{<}ywv-=vHRFmDjv)NtmC zQx9qm)d%0zH&qG7AFa3VAU1S^(n8VFTC~Hb+HjYMjX8r#&_0MzlNR*mnLH5hi}`@{ zK$8qiDDvS_(L9_2vHgzEQ${DYSE;DqB!g*jhJghE&=LTnbgl&Xepo<*uRtV{2wDHN z)l;Kg$TA>Y|K8Lc&LjWGj<+bp4Hiye_@BfU(y#nF{fpR&|Ltbye?e^j0}8JC4#xi% zv29ZR%8%hk=3ZDvO-@1u8KmQ@6p%E|dlHuy#H1&MiC<*$YdLkHmR#F3ae;bKd;@*i z2_VfELG=B}JMLCO-6UQy^>RDE%K4b>c%9ki`f~Z2Qu8hO7C#t%Aeg8E%+}6P7Twtg z-)dj(w}_zFK&86KR@q9MHicUAucLVshUdmz_2@32(V`y3`&Kf8Q2I)+!n0mR=rrDU zXvv^$ho;yh*kNqJ#r1}b0|i|xRUF6;lhx$M*uG3SNLUTC@|htC z-=fsw^F%$qqz4%QdjBrS+ov}Qv!z00E+JWas>p?z@=t!WWU3K*?Z(0meTuTOC7OTx zU|kFLE0bLZ+WGcL$u4E}5dB0g`h|uwv3=H6f+{5z9oLv-=Q45+n~V4WwgO=CabjM% zBAN+RjM65(-}>Q2V#i1Na@a0`08g&y;W#@sBiX6Tpy8r}*+{RnyGUT`?XeHSqo#|J z^ww~c;ou|iyzpErDtlVU=`8N7JSu>4M z_pr9=tX0edVn9B}YFO2y(88j#S{w%E8vVOpAboK*27a7e4Ekjt0)hIX99*1oE;vex z7#%jhY=bPijA=Ce@9rRO(Vl_vnd00!^TAc<+wVvRM9{;hP*rqEL_(RzfK$er_^SN; z)1a8vo8~Dr5?;0X0J62Cusw$A*c^Sx1)dom`-)Pl7hsW4i(r*^Mw`z5K>!2ixB_mu z*Ddqjh}zceRFdmuX1akM1$3>G=#~|y?eYv(e-`Qy?bRHIq=fMaN~fB zUa6I8Rt=)jnplP>yuS+P&PxeWpJ#1$F`iqRl|jF$WL_aZFZl@kLo&d$VJtu&w?Q0O zzuXK>6gmygq(yXJy0C1SL}T8AplK|AGNUOhzlGeK_oo|haD@)5PxF}rV+5`-w{Aag zus45t=FU*{LguJ11Sr-28EZkq;!mJO7AQGih1L4rEyUmp>B!%X0YemsrV3QFvlgt* z5kwlPzaiJ+kZ^PMd-RRbl(Y?F*m`4*UIhIuf#8q>H_M=fM*L_Op-<_r zBZagV=4B|EW+KTja?srADTZXCd3Yv%^Chfpi)cg{ED${SI>InNpRj5!euKv?=Xn92 zsS&FH(*w`qLIy$doc>RE&A5R?u zzkl1sxX|{*fLpXvIW>9d<$ePROttn3oc6R!sN{&Y+>Jr@yeQN$sFR z;w6A<2-0%UA?c8Qf;sX7>>uKRBv3Ni)E9pI{uVzX|6Bb0U)`lhLE3hK58ivfRs1}d zNjlGK0hdq0qjV@q1qI%ZFMLgcpWSY~mB^LK)4GZ^h_@H+3?dAe_a~k*;9P_d7%NEFP6+ zgV(oGr*?W(ql?6SQ~`lUsjLb%MbfC4V$)1E0Y_b|OIYxz4?O|!kRb?BGrgiH5+(>s zoqM}v*;OBfg-D1l`M6T6{K`LG+0dJ1)!??G5g(2*vlNkm%Q(MPABT$r13q?|+kL4- zf)Mi5r$sn;u41aK(K#!m+goyd$c!KPl~-&-({j#D4^7hQkV3W|&>l_b!}!z?4($OA z5IrkfuT#F&S1(`?modY&I40%gtroig{YMvF{K{>5u^I51k8RriGd${z)=5k2tG zM|&Bp5kDTfb#vfuTTd?)a=>bX=lokw^y9+2LS?kwHQIWI~pYgy7 zb?A-RKVm_vM5!9?C%qYdfRAw& zAU7`up~%g=p@}pg#b7E)BFYx3g%(J36Nw(Dij!b>cMl@CSNbrW!DBDbTD4OXk!G4x zi}JBKc8HBYx$J~31PXH+4^x|UxK~(<@I;^3pWN$E=sYma@JP|8YL`L(zI6Y#c%Q{6 z*APf`DU$S4pr#_!60BH$FGViP14iJmbrzSrOkR;f3YZa{#E7Wpd@^4E-zH8EgPc-# zKWFPvh%WbqU_%ZEt`=Q?odKHc7@SUmY{GK`?40VuL~o)bS|is$Hn=<=KGHOsEC5tB zFb|q}gGlL97NUf$G$>^1b^3E18PZ~Pm9kX%*ftnolljiEt@2#F2R5ah$zbXd%V_Ev zyDd{1o_uuoBga$fB@Fw!V5F3jIr=a-ykqrK?WWZ#a(bglI_-8pq74RK*KfQ z0~Dzus7_l;pMJYf>Bk`)`S8gF!To-BdMnVw5M-pyu+aCiC5dwNH|6fgRsIKZcF&)g zr}1|?VOp}I3)IR@m1&HX1~#wsS!4iYqES zK}4J{Ei>;e3>LB#Oly>EZkW14^@YmpbgxCDi#0RgdM${&wxR+LiX}B+iRioOB0(pDKpVEI;ND?wNx>%e|m{RsqR_{(nmQ z3ZS}@t!p4a(BKx_-CYwrcyJ5u1TO9bcXti$8sy>xcLKqKCc#~UOZYD{llKTSFEjJ~ zyNWt>tLU}*>^`TvPxtP%F`ZJQw@W0^>x;!^@?k_)9#bF$j0)S3;mH-IR5y82l|%=F z2lR8zhP?XNP-ucZZ6A+o$xOyF!w;RaLHGh57GZ|TCXhJqY~GCh)aXEV$1O&$c}La1 zjuJxkY9SM4av^Hb;i7efiYaMwI%jGy`3NdY)+mcJhF(3XEiSlU3c|jMBi|;m-c?~T z+x0_@;SxcoY=(6xNgO$bBt~Pj8`-<1S|;Bsjrzw3@zSjt^JC3X3*$HI79i~!$RmTz zsblZsLYs7L$|=1CB$8qS!tXrWs!F@BVuh?kN(PvE5Av-*r^iYu+L^j^m9JG^#=m>@ z=1soa)H*w6KzoR$B8mBCXoU;f5^bVuwQ3~2LKg!yxomG1#XPmn(?YH@E~_ED+W6mxs%x{%Z<$pW`~ON1~2XjP5v(0{C{+6Dm$00tsd3w=f=ZENy zOgb-=f}|Hb*LQ$YdWg<(u7x3`PKF)B7ZfZ6;1FrNM63 z?O6tE%EiU@6%rVuwIQjvGtOofZBGZT1Sh(xLIYt9c4VI8`!=UJd2BfLjdRI#SbVAX ziT(f*RI^T!IL5Ac>ql7uduF#nuCRJ1)2bdvAyMxp-5^Ww5p#X{rb5)(X|fEhDHHW{ zw(Lfc$g;+Q`B0AiPGtmK%*aWfQQ$d!*U<|-@n2HZvCWSiw^I>#vh+LyC;aaVWGbmkENr z&kl*8o^_FW$T?rDYLO1Pyi%>@&kJKQoH2E0F`HjcN}Zlnx1ddoDA>G4Xu_jyp6vuT zPvC}pT&Owx+qB`zUeR|4G;OH(<<^_bzkjln0k40t`PQxc$7h(T8Ya~X+9gDc8Z9{Z z&y0RAU}#_kQGrM;__MK9vwIwK^aoqFhk~dK!ARf1zJqHMxF2?7-8|~yoO@_~Ed;_wvT%Vs{9RK$6uUQ|&@#6vyBsFK9eZW1Ft#D2)VpQRwpR(;x^ zdoTgMqfF9iBl%{`QDv7B0~8{8`8k`C4@cbZAXBu00v#kYl!#_Wug{)2PwD5cNp?K^ z9+|d-4z|gZ!L{57>!Ogfbzchm>J1)Y%?NThxIS8frAw@z>Zb9v%3_3~F@<=LG%r*U zaTov}{{^z~SeX!qgSYow`_5)ij*QtGp4lvF`aIGQ>@3ZTkDmsl#@^5*NGjOuu82}o zzLF~Q9SW+mP=>88%eSA1W4_W7-Q>rdq^?t=m6}^tDPaBRGFLg%ak93W!kOp#EO{6& zP%}Iff5HZQ9VW$~+9r=|Quj#z*=YwcnssS~9|ub2>v|u1JXP47vZ1&L1O%Z1DsOrDfSIMHU{VT>&>H=9}G3i@2rP+rx@eU@uE8rJNec zij~#FmuEBj03F1~ct@C@$>y)zB+tVyjV3*n`mtAhIM0$58vM9jOQC}JJOem|EpwqeMuYPxu3sv}oMS?S#o6GGK@8PN59)m&K4Dc&X% z(;XL_kKeYkafzS3Wn5DD>Yiw{LACy_#jY4op(>9q>>-*9@C0M+=b#bknAWZ37^(Ij zq>H%<@>o4a#6NydoF{_M4i4zB_KG)#PSye9bk0Ou8h%1Dtl7Q_y#7*n%g)?m>xF~( zjqvOwC;*qvN_3(*a+w2|ao0D?@okOvg8JskUw(l7n`0fncglavwKd?~l_ryKJ^Ky! zKCHkIC-o7%fFvPa$)YNh022lakMar^dgL=t#@XLyNHHw!b?%WlM)R@^!)I!smZL@k zBi=6wE5)2v&!UNV(&)oOYW(6Qa!nUjDKKBf-~Da=#^HE4(@mWk)LPvhyN3i4goB$3K8iV7uh zsv+a?#c4&NWeK(3AH;ETrMOIFgu{_@%XRwCZ;L=^8Ts)hix4Pf3yJRQ<8xb^CkdmC z?c_gB)XmRsk`9ch#tx4*hO=#qS7={~Vb4*tTf<5P%*-XMfUUYkI9T1cEF;ObfxxI-yNuA=I$dCtz3ey znVkctYD*`fUuZ(57+^B*R=Q}~{1z#2!ca?)+YsRQb+lt^LmEvZt_`=j^wqig+wz@n@ z`LIMQJT3bxMzuKg8EGBU+Q-6cs5(@5W?N>JpZL{$9VF)veF`L5%DSYTNQEypW%6$u zm_~}T{HeHj1bAlKl8ii92l9~$dm=UM21kLemA&b$;^!wB7#IKWGnF$TVq!!lBlG4 z{?Rjz?P(uvid+|i$VH?`-C&Gcb3{(~Vpg`w+O);Wk1|Mrjxrht0GfRUnZqz2MhrXa zqgVC9nemD5)H$to=~hp)c=l9?#~Z_7i~=U-`FZxb-|TR9@YCxx;Zjo-WpMNOn2)z) zFPGGVl%3N$f`gp$gPnWC+f4(rmts%fidpo^BJx72zAd7|*Xi{2VXmbOm)1`w^tm9% znM=0Fg4bDxH5PxPEm{P3#A(mxqlM7SIARP?|2&+c7qmU8kP&iApzL|F>Dz)Ixp_`O zP%xrP1M6@oYhgo$ZWwrAsYLa4 z|I;DAvJxno9HkQrhLPQk-8}=De{9U3U%)dJ$955?_AOms!9gia%)0E$Mp}$+0er@< zq7J&_SzvShM?e%V?_zUu{niL@gt5UFOjFJUJ}L?$f%eU%jUSoujr{^O=?=^{19`ON zlRIy8Uo_nqcPa6@yyz`CM?pMJ^^SN^Fqtt`GQ8Q#W4kE7`V9^LT}j#pMChl!j#g#J zr-=CCaV%xyFeQ9SK+mG(cTwW*)xa(eK;_Z(jy)woZp~> zA(4}-&VH+TEeLzPTqw&FOoK(ZjD~m{KW05fiGLe@E3Z2`rLukIDahE*`u!ubU)9`o zn^-lyht#E#-dt~S>}4y$-mSbR8{T@}22cn^refuQ08NjLOv?JiEWjyOnzk<^R5%gO zhUH_B{oz~u#IYwVnUg8?3P*#DqD8#X;%q%HY**=I>>-S|!X*-!x1{^l#OnR56O>iD zc;i;KS+t$koh)E3)w0OjWJl_aW2;xF=9D9Kr>)(5}4FqUbk# zI#$N8o0w;IChL49m9CJTzoC!|u{Ljd%ECgBOf$}&jA^$(V#P#~)`&g`H8E{uv52pp zwto`xUL-L&WTAVREEm$0g_gYPL(^vHq(*t1WCH_6alhkeW&GCZ3hL)|{O-jiFOBrF z!EW=Jej|dqQitT6!B-7&io2K)WIm~Q)v@yq%U|VpV+I?{y0@Yd%n8~-NuuM*pM~KA z85YB};IS~M(c<}4Hxx>qRK0cdl&e?t253N%vefkgds>Ubn8X}j6Vpgs>a#nFq$osY z1ZRwLqFv=+BTb=i%D2Wv>_yE0z}+niZ4?rE|*a3d7^kndWGwnFqt+iZ(7+aln<}jzbAQ(#Z2SS}3S$%Bd}^ zc9ghB%O)Z_mTZMRC&H#)I#fiLuIkGa^`4e~9oM5zKPx?zjkC&Xy0~r{;S?FS%c7w< zWbMpzc(xSw?9tGxG~_l}Acq}zjt5ClaB7-!vzqnlrX;}$#+PyQ9oU)_DfePh2E1<7 ztok6g6K^k^DuHR*iJ?jw?bs_whk|bx`dxu^nC6#e{1*m~z1eq7m}Cf$*^Eua(oi_I zAL+3opNhJteu&mWQ@kQWPucmiP)4|nFG`b2tpC;h{-PI@`+h?9v=9mn|0R-n8#t=+Z*FD(c5 zjj79Jxkgck*DV=wpFgRZuwr%}KTm+dx?RT@aUHJdaX-ODh~gByS?WGx&czAkvkg;x zrf92l8$Or_zOwJVwh>5rB`Q5_5}ef6DjS*$x30nZbuO3dijS*wvNEqTY5p1_A0gWr znH<(Qvb!os14|R)n2Ost>jS2;d1zyLHu`Svm|&dZD+PpP{Bh>U&`Md;gRl64q;>{8MJJM$?UNUd`aC>BiLe>*{ zJY15->yW+<3rLgYeTruFDtk1ovU<$(_y7#HgUq>)r0{^}Xbth}V#6?%5jeFYt;SG^ z3qF)=uWRU;Jj)Q}cpY8-H+l_n$2$6{ZR?&*IGr{>ek!69ZH0ZoJ*Ji+ezzlJ^%qL3 zO5a`6gwFw(moEzqxh=yJ9M1FTn!eo&qD#y5AZXErHs%22?A+JmS&GIolml!)rZTnUDM3YgzYfT#;OXn)`PWv3Ta z!-i|-Wojv*k&bC}_JJDjiAK(Ba|YZgUI{f}TdEOFT2+}nPmttytw7j%@bQZDV1vvj z^rp{gRkCDmYJHGrE1~e~AE!-&6B6`7UxVQuvRrfdFkGX8H~SNP_X4EodVd;lXd^>eV1jN+Tt4}Rsn)R0LxBz0c=NXU|pUe!MQQFkGBWbR3&(jLm z%RSLc#p}5_dO{GD=DEFr=Fc% z85CBF>*t!6ugI?soX(*JNxBp+-DdZ4X0LldiK}+WWGvXV(C(Ht|!3$psR=&c*HIM=BmX;pRIpz@Ale{9dhGe(U2|Giv;# zOc|;?p67J=Q(kamB*aus=|XP|m{jN^6@V*Bpm?ye56Njh#vyJqE=DweC;?Rv7faX~ zde03n^I~0B2vUmr;w^X37tVxUK?4}ifsSH5_kpKZIzpYu0;Kv}SBGfI2AKNp+VN#z`nI{UNDRbo-wqa4NEls zICRJpu)??cj^*WcZ^MAv+;bDbh~gpN$1Cor<{Y2oyIDws^JsfW^5AL$azE(T0p&pP z1Mv~6Q44R&RHoH95&OuGx2srIr<@zYJTOMKiVs;Bx3py89I87LOb@%mr`0)#;7_~Z zzcZj8?w=)>%5@HoCHE_&hnu(n_yQ-L(~VjpjjkbT7e)Dk5??fApg(d>vwLRJ-x{um z*Nt?DqTSxh_MIyogY!vf1mU1`Gld-&L)*43f6dilz`Q@HEz;+>MDDYv9u!s;WXeao zUq=TaL$P*IFgJzrGc>j1dDOd zed+=ZBo?w4mr$2)Ya}?vedDopomhW1`#P<%YOJ_j=WwClX0xJH-f@s?^tmzs_j7t!k zK@j^zS0Q|mM4tVP5Ram$VbS6|YDY&y?Q1r1joe9dj08#CM{RSMTU}(RCh`hp_Rkl- zGd|Cv~G@F{DLhCizAm9AN!^{rNs8hu!G@8RpnGx7e`-+K$ffN<0qjR zGq^$dj_Tv!n*?zOSyk5skI7JVKJ)3jysnjIu-@VSzQiP8r6MzudCU=~?v-U8yzo^7 zGf~SUTvEp+S*!X9uX!sq=o}lH;r{pzk~M*VA(uyQ`3C8!{C;)&6)95fv(cK!%Cuz$ z_Zal57H6kPN>25KNiI6z6F)jzEkh#%OqU#-__Xzy)KyH};81#N6OfX$$IXWzOn`Q& z4f$Z1t>)8&8PcYfEwY5UadU1yg+U*(1m2ZlHoC-!2?gB!!fLhmTl))D@dhvkx#+Yj z1O=LV{(T%{^IeCuFK>%QR!VZ4GnO5tK8a+thWE zg4VytZrwcS?7^ zuZfhYnB8dwd%VLO?DK7pV5Wi<(`~DYqOXn8#jUIL^)12*Dbhk4GmL_E2`WX&iT16o zk(t|hok(Y|v-wzn?4x34T)|+SfZP>fiq!><*%vnxGN~ypST-FtC+@TPv*vYv@iU!_ z@2gf|PrgQ?Ktf*9^CnJ(x*CtZVB8!OBfg0%!wL;Z8(tYYre0vcnPGlyCc$V(Ipl*P z_(J!a=o@vp^%Efme!K74(Ke7A>Y}|sxV+JL^aYa{~m%5#$$+R1? zGaQhZTTX!#s#=Xtpegqero$RNt&`4xn3g$)=y*;=N=Qai)}~`xtxI_N*#MMCIq#HFifT zz(-*m;pVH&+4bixL&Bbg)W5FN^bH87pAHp)zPkWNMfTFqS=l~AC$3FX3kQUSh_C?-ZftyClgM)o_D7cX$RGlEYblux0jv5 zTr|i-I3@ZPCGheCl~BGhImF)K4!9@?pC(gi3ozX=a!|r1)LFxy_8c&wY0<^{2cm|P zv6Y`QktY*;I)IUd5y3ne1CqpVanlY45z8hf4&$EUBnucDj16pDa4&GI&TArYhf*xh zdj>*%APH8(h~c>o@l#%T>R$e>rwVx_WUB|~V`p^JHsg*y12lzj&zF}w6W09HwB2yb z%Q~`es&(;7#*DUC_w-Dmt7|$*?TA_m;zB+-u{2;Bg{O}nV7G_@7~<)Bv8fH^G$XG8$(&{A zwXJK5LRK%M34(t$&NI~MHT{UQ9qN-V_yn|%PqC81EIiSzmMM=2zb`mIwiP_b)x+2M z7Gd`83h79j#SItpQ}luuf2uOU`my_rY5T{6P#BNlb%h%<#MZb=m@y5aW;#o1^2Z)SWo+b`y0gV^iRcZtz5!-05vF z7wNo=hc6h4hc&s@uL^jqRvD6thVYtbErDK9k!;+a0xoE0WL7zLixjn5;$fXvT=O3I zT6jI&^A7k6R{&5#lVjz#8%_RiAa2{di{`kx79K+j72$H(!ass|B%@l%KeeKchYLe_ z>!(JC2fxsv>XVen+Y42GeYPxMWqm`6F$(E<6^s|g(slNk!lL*6v^W2>f6hh^mE$s= z3D$)}{V5(Qm&A6bp%2Q}*GZ5Qrf}n7*Hr51?bJOyA-?B4vg6y_EX<*-e20h{=0Mxs zbuQGZ$fLyO5v$nQ&^kuH+mNq9O#MWSfThtH|0q1i!NrWj^S}_P;Q1OkYLW6U^?_7G zx2wg?CULj7))QU(n{$0JE%1t2dWrMi2g-Os{v|8^wK{@qlj%+1b^?NI z$}l2tjp0g>K3O+p%yK<9!XqmQ?E9>z&(|^Pi~aSRwI5x$jaA62GFz9%fmO3t3a>cq zK8Xbv=5Ps~4mKN5+Eqw12(!PEyedFXv~VLxMB~HwT1Vfo51pQ#D8e$e4pFZ{&RC2P z5gTIzl{3!&(tor^BwZfR8j4k{7Rq#`riKXP2O-Bh66#WWK2w=z;iD9GLl+3 zpHIaI4#lQ&S-xBK8PiQ%dwOh?%BO~DCo06pN7<^dnZCN@NzY{_Z1>rrB0U|nC&+!2 z2y!oBcTd2;@lzyk(B=TkyZ)zy0deK05*Q0zk+o$@nun`VI1Er7pjq>8V zNmlW{p7S^Btgb(TA}jL(uR>`0w8gHP^T~Sh5Tkip^spk4SBAhC{TZU}_Z)UJw-}zm zPq{KBm!k)?P{`-(9?LFt&YN4s%SIZ-9lJ!Ws~B%exHOeVFk3~}HewnnH(d)qkLQ_d z6h>O)pEE{vbOVw}E+jdYC^wM+AAhaI(YAibUc@B#_mDss0Ji&BK{WG`4 zOk>vSNq(Bq2IB@s>>Rxm6Wv?h;ZXkpb1l8u|+_qXWdC*jjcPCixq;!%BVPSp#hP zqo`%cNf&YoQXHC$D=D45RiT|5ngPlh?0T~?lUf*O)){K@*Kbh?3RW1j9-T?%lDk@y z4+~?wKI%Y!-=O|_IuKz|=)F;V7ps=5@g)RrE;;tvM$gUhG>jHcw2Hr@fS+k^Zr~>G z^JvPrZc}_&d_kEsqAEMTMJw!!CBw)u&ZVzmq+ZworuaE&TT>$pYsd9|g9O^0orAe8 z221?Va!l1|Y5X1Y?{G7rt1sX#qFA^?RLG^VjoxPf63;AS=_mVDfGJKg73L zsGdnTUD40y(>S##2l|W2Cy!H(@@5KBa(#gs`vlz}Y~$ot5VsqPQ{{YtjYFvIumZzt zA{CcxZLJR|4#{j7k~Tu*jkwz8QA|5G1$Cl895R`Zyp;irp1{KN){kB30O8P1W5;@bG znvX74roeMmQlUi=v9Y%(wl$ZC#9tKNFpvi3!C}f1m6Ct|l2g%psc{TJp)@yu)*e2> z((p0Fg*8gJ!|3WZke9;Z{8}&NRkv7iP=#_y-F}x^y?2m%-D_aj^)f04%mneyjo_;) z6qc_Zu$q37d~X``*eP~Q>I2gg%rrV8v=kDfpp$=%Vj}hF)^dsSWygoN(A$g*E=Do6FX?&(@F#7pbiJ`;c0c@Ul zDqW_90Wm#5f2L<(Lf3)3TeXtI7nhYwRm(F;*r_G6K@OPW4H(Y3O5SjUzBC}u3d|eQ8*8d@?;zUPE+i#QNMn=r(ap?2SH@vo*m z3HJ%XuG_S6;QbWy-l%qU;8x;>z>4pMW7>R}J%QLf%@1BY(4f_1iixd-6GlO7Vp*yU zp{VU^3?s?90i=!#>H`lxT!q8rk>W_$2~kbpz7eV{3wR|8E=8**5?qn8#n`*(bt1xRQrdGxyx2y%B$qmw#>ZV$c7%cO#%JM1lY$Y0q?Yuo> ze9KdJoiM)RH*SB%^;TAdX-zEjA7@%y=!0=Zg%iWK7jVI9b&Dk}0$Af&08KHo+ zOwDhFvA(E|ER%a^cdh@^wLUlmIv6?_3=BvX8jKk92L=Y}7Jf5OGMfh` zBdR1wFCi-i5@`9km{isRb0O%TX+f~)KNaEz{rXQa89`YIF;EN&gN)cigu6mNh>?Cm zAO&Im2flv6D{jwm+y<%WsPe4!89n~KN|7}Cb{Z;XweER73r}Qp2 zz}WP4j}U0&(uD&9yGy6`!+_v-S(yG*iytsTR#x_Rc>=6u^vnRDnf1gP{#2>`ffrAC% zTZ5WQ@hAK;P;>kX{D)mIXe4%a5p=LO1xXH@8T?mz7Q@d)$3pL{{B!2{-v70L*o1AO+|n5beiw~ zk@(>m?T3{2k2c;NWc^`4@P&Z?BjxXJ@;x1qhn)9Mn*IFdt_J-dIqx5#d`NfyfX~m( zIS~5)MfZ2Uy?_4W`47i}u0ZgPh<{D|w_d#;D}Q&U$Q-G}xM1A@1f{#%A$jh6Qp&0hQ<0bPOM z-{1Wm&p%%#eb_?x7i;bol EfAhh=DF6Tf diff --git a/hexagonaljava/.mvn/wrapper/maven-wrapper.properties b/hexagonaljava/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index 642d572ce9..0000000000 --- a/hexagonaljava/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,2 +0,0 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/hexagonaljava/mvnw b/hexagonaljava/mvnw deleted file mode 100755 index a16b5431b4..0000000000 --- a/hexagonaljava/mvnw +++ /dev/null @@ -1,310 +0,0 @@ -#!/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. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# M2_HOME - location of maven2's installed home dir -# 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 /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 - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" - - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi - done - - saveddir=`pwd` - - M2_HOME=`dirname "$PRG"`/.. - - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` - - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -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 "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; 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="`which 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 - -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher - -# 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/.."; pwd` - fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -########################################################################################## -# 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. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -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 "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -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 - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/hexagonaljava/mvnw.cmd b/hexagonaljava/mvnw.cmd deleted file mode 100644 index c8d43372c9..0000000000 --- a/hexagonaljava/mvnw.cmd +++ /dev/null @@ -1,182 +0,0 @@ -@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 Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@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 "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\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 DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_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 DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_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('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@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 "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\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% - -exit /B %ERROR_CODE% diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java index 603f8297d1..89bcfb6510 100644 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java @@ -9,5 +9,4 @@ public class HexagonaljavaApplication { public static void main(String[] args) { SpringApplication.run(HexagonaljavaApplication.class, args); } - } diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java index 7db6117f83..7a5ba70c51 100644 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java @@ -25,5 +25,4 @@ public class StudentResultController { public Double getTotalMarks(@PathVariable Integer id) { return studentResultService.getTotalMarks(id); } - } diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java index ef721e6eda..040faa03a7 100644 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java @@ -33,5 +33,4 @@ public class Student { public void setMarks(Map marks) { this.marks = marks; } - } diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java index 1d347346a2..541c70d757 100644 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java @@ -24,21 +24,15 @@ public class StudentResultJdbcRepoImpl implements StudentResultRepo { @Override public void save(Student student) { - jdbcTemplate.update("insert into student (id, name) " + "values(?, ?)", new Object[] { student.getId(), student.getName() }); insertResult(student); - } public void insertResult(Student student) { - String insertQuery = "insert into " + "studentresult " + "(subject,marks,id) " + "values " + "(?,?,?)"; - for (final Map.Entry entry : student.getMarks() - .entrySet()) { - + .entrySet()) { this.jdbcTemplate.batchUpdate(insertQuery, new BatchPreparedStatementSetter() { - @Override public void setValues(final PreparedStatement ps, final int i) throws SQLException { @@ -49,22 +43,19 @@ public class StudentResultJdbcRepoImpl implements StudentResultRepo { public int getBatchSize() { return student.getMarks() - .size(); + .size(); } }); } - } @Override public Student getStudent(Integer id) { - String selectQuery = "select * from ( select * from student where id = ? ) s left join studentresult on s.id = studentresult.id"; Student student = new Student(); jdbcTemplate.query(selectQuery, new Object[] { id }, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { while (rs.next()) { - if (student.getId() == null) { student.setId(rs.getInt("id")); student.setName(rs.getString("name")); @@ -73,12 +64,10 @@ public class StudentResultJdbcRepoImpl implements StudentResultRepo { String subject = rs.getString("subject"); Double marks = rs.getDouble("marks"); student.getMarks() - .put(subject, marks); - + .put(subject, marks); } } }); return student; } - } diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java index 1ee4e2b9e5..96cf105600 100644 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java @@ -7,5 +7,4 @@ public interface StudentResultRepo { void save(Student student); Student getStudent(Integer id); - } diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java index 6c94aa0083..46fd37a5f2 100644 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java @@ -15,12 +15,10 @@ public class StudentResultRepoImpl implements StudentResultRepo { @Override public void save(Student student) { studentsMap.put(student.getId(), student); - } @Override public Student getStudent(Integer id) { return studentsMap.get(id); } - } diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java index d77ac5dca8..91a25f3809 100644 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java @@ -4,8 +4,7 @@ import com.baeldung.hexagonaljava.entity.Student; public interface StudentResultService { - public void save(Student student); - - public Double getTotalMarks(Integer id); + void save(Student student); + Double getTotalMarks(Integer id); } diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java index d0b53e79f6..f8c163fdf4 100644 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java @@ -15,7 +15,6 @@ public class StudentResultServiceImpl implements StudentResultService { @Override public void save(Student student) { studentResultRepo.save(student); - } @Override @@ -23,10 +22,9 @@ public class StudentResultServiceImpl implements StudentResultService { Student student = studentResultRepo.getStudent(id); double totalMarks = 0; for (double marks : student.getMarks() - .values()) { + .values()) { totalMarks += marks; } return totalMarks; } - } diff --git a/hexagonaljava/src/main/resources/schema.sql b/hexagonaljava/src/main/resources/schema.sql index 4dab9fbb1f..40ba01ec02 100644 --- a/hexagonaljava/src/main/resources/schema.sql +++ b/hexagonaljava/src/main/resources/schema.sql @@ -8,4 +8,4 @@ subject VARCHAR(250) NOT NULL, marks NUMERIC(8,2), id VARCHAR(250), FOREIGN KEY (id) references STUDENT(id) -); \ No newline at end of file +); From 8e7655f0b8ebabfaf7e4ddba28ef9c5da611c9e9 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Fri, 27 Mar 2020 00:43:33 +0530 Subject: [PATCH 003/309] Removing unnecessary lines --- .../hexagonaljava/repository/StudentResultJdbcRepoImpl.java | 1 - .../baeldung/hexagonaljava/HexagonaljavaApplicationTests.java | 1 - 2 files changed, 2 deletions(-) diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java index 541c70d757..7b970462e3 100644 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java +++ b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java @@ -35,7 +35,6 @@ public class StudentResultJdbcRepoImpl implements StudentResultRepo { this.jdbcTemplate.batchUpdate(insertQuery, new BatchPreparedStatementSetter() { @Override public void setValues(final PreparedStatement ps, final int i) throws SQLException { - ps.setString(1, entry.getKey()); ps.setDouble(2, entry.getValue()); ps.setInt(3, student.getId()); diff --git a/hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java b/hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java index c61c51f7b2..eed2f7e6a3 100644 --- a/hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java +++ b/hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java @@ -9,5 +9,4 @@ class HexagonaljavaApplicationTests { @Test void contextLoads() { } - } From a9ab80c75ebcc997e93119a4e95626eb5e33a31a Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Fri, 10 Apr 2020 03:57:55 +0530 Subject: [PATCH 004/309] Example code for using Multiple Cache Manager in SpringBoot --- .../HexagonaljavaApplication.java | 12 ---- .../controller/StudentResultController.java | 28 -------- .../hexagonaljava/entity/Student.java | 36 ---------- .../repository/StudentResultJdbcRepoImpl.java | 72 ------------------- .../repository/StudentResultRepo.java | 10 --- .../repository/StudentResultRepoImpl.java | 24 ------- .../service/StudentResultService.java | 10 --- .../service/StudentResultServiceImpl.java | 30 -------- hexagonaljava/src/main/resources/schema.sql | 11 --- .../pom.xml | 41 ++++++----- .../MultiplecachemanagerApplication.java | 45 ++++++++++++ .../bo/CustomerDetailBO.java | 28 ++++++++ .../bo/OrderDetailBO.java | 25 +++++++ .../config/MultipleCacheResolver.java | 38 ++++++++++ .../MultipleCacheManagerController.java | 43 +++++++++++ .../multiplecachemanager/entity/Customer.java | 24 +++++++ .../multiplecachemanager/entity/Item.java | 34 +++++++++ .../multiplecachemanager/entity/Order.java | 44 ++++++++++++ .../repository/CustomerDetailRepository.java | 49 +++++++++++++ .../repository/OrderDetailRepository.java | 53 ++++++++++++++ .../src/main/resources/application.properties | 7 +- .../src/main/resources/data.sql | 7 ++ .../src/main/resources/schema.sql | 19 +++++ .../MultiplecachemanagerApplicationTests.java | 5 +- 24 files changed, 443 insertions(+), 252 deletions(-) delete mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java delete mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java delete mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java delete mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java delete mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java delete mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java delete mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java delete mode 100644 hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java delete mode 100644 hexagonaljava/src/main/resources/schema.sql rename {hexagonaljava => multiplecachemanager}/pom.xml (64%) create mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplication.java create mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java create mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java create mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java create mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java create mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java create mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java create mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java create mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java create mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java rename {hexagonaljava => multiplecachemanager}/src/main/resources/application.properties (56%) create mode 100644 multiplecachemanager/src/main/resources/data.sql create mode 100644 multiplecachemanager/src/main/resources/schema.sql rename hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java => multiplecachemanager/src/test/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplicationTests.java (62%) diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java deleted file mode 100644 index 89bcfb6510..0000000000 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/HexagonaljavaApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.hexagonaljava; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class HexagonaljavaApplication { - - public static void main(String[] args) { - SpringApplication.run(HexagonaljavaApplication.class, args); - } -} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java deleted file mode 100644 index 7a5ba70c51..0000000000 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/controller/StudentResultController.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.hexagonaljava.controller; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.hexagonaljava.entity.Student; -import com.baeldung.hexagonaljava.service.StudentResultService; - -@RestController -public class StudentResultController { - - @Autowired - private StudentResultService studentResultService; - - @PostMapping(value = "/save") - public void saveStudent(@RequestBody Student student) { - studentResultService.save(student); - } - - @GetMapping(value = "/getTotalMarks/{id}") - public Double getTotalMarks(@PathVariable Integer id) { - return studentResultService.getTotalMarks(id); - } -} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java deleted file mode 100644 index 040faa03a7..0000000000 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/entity/Student.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.hexagonaljava.entity; - -import java.util.Map; - -public class Student { - - private Integer id; - - private String name; - - private Map marks; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Map getMarks() { - return marks; - } - - public void setMarks(Map marks) { - this.marks = marks; - } -} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java deleted file mode 100644 index 7b970462e3..0000000000 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultJdbcRepoImpl.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.baeldung.hexagonaljava.repository; - -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Primary; -import org.springframework.jdbc.core.BatchPreparedStatementSetter; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.stereotype.Component; - -import com.baeldung.hexagonaljava.entity.Student; - -@Primary -@Component -public class StudentResultJdbcRepoImpl implements StudentResultRepo { - - @Autowired - JdbcTemplate jdbcTemplate; - - @Override - public void save(Student student) { - jdbcTemplate.update("insert into student (id, name) " + "values(?, ?)", new Object[] { student.getId(), student.getName() }); - insertResult(student); - } - - public void insertResult(Student student) { - String insertQuery = "insert into " + "studentresult " + "(subject,marks,id) " + "values " + "(?,?,?)"; - for (final Map.Entry entry : student.getMarks() - .entrySet()) { - this.jdbcTemplate.batchUpdate(insertQuery, new BatchPreparedStatementSetter() { - @Override - public void setValues(final PreparedStatement ps, final int i) throws SQLException { - ps.setString(1, entry.getKey()); - ps.setDouble(2, entry.getValue()); - ps.setInt(3, student.getId()); - } - - public int getBatchSize() { - return student.getMarks() - .size(); - } - }); - } - } - - @Override - public Student getStudent(Integer id) { - String selectQuery = "select * from ( select * from student where id = ? ) s left join studentresult on s.id = studentresult.id"; - Student student = new Student(); - jdbcTemplate.query(selectQuery, new Object[] { id }, new RowCallbackHandler() { - public void processRow(ResultSet rs) throws SQLException { - while (rs.next()) { - if (student.getId() == null) { - student.setId(rs.getInt("id")); - student.setName(rs.getString("name")); - student.setMarks(new HashMap()); - } - String subject = rs.getString("subject"); - Double marks = rs.getDouble("marks"); - student.getMarks() - .put(subject, marks); - } - } - }); - return student; - } -} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java deleted file mode 100644 index 96cf105600..0000000000 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepo.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.hexagonaljava.repository; - -import com.baeldung.hexagonaljava.entity.Student; - -public interface StudentResultRepo { - - void save(Student student); - - Student getStudent(Integer id); -} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java deleted file mode 100644 index 46fd37a5f2..0000000000 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/repository/StudentResultRepoImpl.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.hexagonaljava.repository; - -import java.util.HashMap; -import java.util.Map; - -import org.springframework.stereotype.Repository; - -import com.baeldung.hexagonaljava.entity.Student; - -@Repository -public class StudentResultRepoImpl implements StudentResultRepo { - - private Map studentsMap = new HashMap(); - - @Override - public void save(Student student) { - studentsMap.put(student.getId(), student); - } - - @Override - public Student getStudent(Integer id) { - return studentsMap.get(id); - } -} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java deleted file mode 100644 index 91a25f3809..0000000000 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultService.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.hexagonaljava.service; - -import com.baeldung.hexagonaljava.entity.Student; - -public interface StudentResultService { - - void save(Student student); - - Double getTotalMarks(Integer id); -} diff --git a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java b/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java deleted file mode 100644 index f8c163fdf4..0000000000 --- a/hexagonaljava/src/main/java/com/baeldung/hexagonaljava/service/StudentResultServiceImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.hexagonaljava.service; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import com.baeldung.hexagonaljava.entity.Student; -import com.baeldung.hexagonaljava.repository.StudentResultRepo; - -@Component -public class StudentResultServiceImpl implements StudentResultService { - - @Autowired - private StudentResultRepo studentResultRepo; - - @Override - public void save(Student student) { - studentResultRepo.save(student); - } - - @Override - public Double getTotalMarks(Integer id) { - Student student = studentResultRepo.getStudent(id); - double totalMarks = 0; - for (double marks : student.getMarks() - .values()) { - totalMarks += marks; - } - return totalMarks; - } -} diff --git a/hexagonaljava/src/main/resources/schema.sql b/hexagonaljava/src/main/resources/schema.sql deleted file mode 100644 index 40ba01ec02..0000000000 --- a/hexagonaljava/src/main/resources/schema.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE STUDENT ( - id INT PRIMARY KEY, - name VARCHAR(250) NOT NULL -); - -CREATE TABLE STUDENTRESULT( -subject VARCHAR(250) NOT NULL, -marks NUMERIC(8,2), -id VARCHAR(250), -FOREIGN KEY (id) references STUDENT(id) -); diff --git a/hexagonaljava/pom.xml b/multiplecachemanager/pom.xml similarity index 64% rename from hexagonaljava/pom.xml rename to multiplecachemanager/pom.xml index d9ca173888..22daf6e87d 100644 --- a/hexagonaljava/pom.xml +++ b/multiplecachemanager/pom.xml @@ -5,25 +5,45 @@ org.springframework.boot spring-boot-starter-parent - 2.2.5.RELEASE + 2.2.6.RELEASE - com.baeldung. - hexagonaljava + com.baeldung + multiplecachemanager 0.0.1-SNAPSHOT - hexagonaljava - Demo project for Spring Boot + multiplecachemanager + sample project for configuring multiple cache managers 1.8 + + org.springframework.boot + spring-boot-starter-jdbc + org.springframework.boot spring-boot-starter-web + + com.h2database + h2 + runtime + + + + org.springframework.boot + spring-boot-starter-cache + + + + com.github.ben-manes.caffeine + caffeine + + org.springframework.boot spring-boot-starter-test @@ -35,17 +55,6 @@ - - - org.springframework.boot - spring-boot-starter-jdbc - - - - com.h2database - h2 - runtime - diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplication.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplication.java new file mode 100644 index 0000000000..4c7efc98bd --- /dev/null +++ b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplication.java @@ -0,0 +1,45 @@ +package com.baeldung.multiplecachemanager; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.cache.caffeine.CaffeineCacheManager; +import org.springframework.cache.concurrent.ConcurrentMapCacheManager; +import org.springframework.cache.interceptor.CacheResolver; +import org.springframework.context.annotation.Bean; + +import com.baeldung.multiplecachemanager.config.MultipleCacheResolver; +import com.github.benmanes.caffeine.cache.Caffeine; + +@SpringBootApplication +@EnableCaching +public class MultiplecachemanagerApplication extends CachingConfigurerSupport { + + public static void main(String[] args) { + SpringApplication.run(MultiplecachemanagerApplication.class, args); + } + + @Bean + // @Primary + public CacheManager cacheManager() { + CaffeineCacheManager cacheManager = new CaffeineCacheManager("customers", "orders"); + cacheManager.setCaffeine(Caffeine.newBuilder() + .initialCapacity(200) + .maximumSize(500) + .weakKeys() + .recordStats()); + return cacheManager; + } + + @Bean + public CacheManager alternateCacheManager() { + return new ConcurrentMapCacheManager("customerOrders", "orderprice"); + } + + @Bean + public CacheResolver cacheResolver() { + return new MultipleCacheResolver(alternateCacheManager(), cacheManager()); + } +} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java new file mode 100644 index 0000000000..3da4c23e28 --- /dev/null +++ b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java @@ -0,0 +1,28 @@ +package com.baeldung.multiplecachemanager.bo; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +import com.baeldung.multiplecachemanager.entity.Customer; +import com.baeldung.multiplecachemanager.entity.Order; +import com.baeldung.multiplecachemanager.repository.CustomerDetailRepository; + +@Component +public class CustomerDetailBO { + + @Autowired + private CustomerDetailRepository customerDetailRepository; + + @Cacheable(cacheNames = "customers") + public Customer getCustomerDetail(Integer customerId) { + return customerDetailRepository.getCustomerDetail(customerId); + } + + @Cacheable(cacheNames = "customerOrders", cacheManager = "alternateCacheManager") + public List getCustomerOrders(Integer customerId) { + return customerDetailRepository.getCustomerOrders(customerId); + } +} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java new file mode 100644 index 0000000000..cb9e301fcb --- /dev/null +++ b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java @@ -0,0 +1,25 @@ +package com.baeldung.multiplecachemanager.bo; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +import com.baeldung.multiplecachemanager.entity.Order; +import com.baeldung.multiplecachemanager.repository.OrderDetailRepository; + +@Component +public class OrderDetailBO { + + @Autowired + private OrderDetailRepository orderDetailRepository; + + @Cacheable(cacheNames = "orders", cacheResolver = "cacheResolver") + public Order getOrderDetail(Integer orderId) { + return orderDetailRepository.getOrderDetail(orderId); + } + + @Cacheable(cacheNames = "orderprice", cacheResolver = "cacheResolver") + public double getOrderPrice(Integer orderId) { + return orderDetailRepository.getOrderPrice(orderId); + } +} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java new file mode 100644 index 0000000000..1bd869d98e --- /dev/null +++ b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java @@ -0,0 +1,38 @@ +package com.baeldung.multiplecachemanager.config; + +import java.util.ArrayList; +import java.util.Collection; + +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.interceptor.CacheOperationInvocationContext; +import org.springframework.cache.interceptor.CacheResolver; + +public class MultipleCacheResolver implements CacheResolver { + + private final CacheManager simpleCacheManager; + + private final CacheManager caffeineCacheManager; + + private static final String ORDER_CACHE = "orders"; + + private static final String ORDER_PRICE_CACHE = "orderprice"; + + public MultipleCacheResolver(CacheManager simpleCacheManager, CacheManager caffeineCacheManager) { + this.simpleCacheManager = simpleCacheManager; + this.caffeineCacheManager = caffeineCacheManager; + + } + + @Override + public Collection resolveCaches(CacheOperationInvocationContext context) { + Collection caches = new ArrayList(); + if ("getOrderDetail".equals(context.getMethod() + .getName())) { + caches.add(caffeineCacheManager.getCache(ORDER_CACHE)); + } else { + caches.add(simpleCacheManager.getCache(ORDER_PRICE_CACHE)); + } + return caches; + } +} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java new file mode 100644 index 0000000000..17a73bb27a --- /dev/null +++ b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java @@ -0,0 +1,43 @@ +package com.baeldung.multiplecachemanager.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.multiplecachemanager.bo.CustomerDetailBO; +import com.baeldung.multiplecachemanager.bo.OrderDetailBO; +import com.baeldung.multiplecachemanager.entity.Customer; +import com.baeldung.multiplecachemanager.entity.Order; + +@RestController +public class MultipleCacheManagerController { + + @Autowired + private CustomerDetailBO customerDetailBO; + + @Autowired + private OrderDetailBO orderDetailBO; + + @GetMapping(value = "/getCustomer/{customerid}") + public Customer getCustomer(@PathVariable Integer customerid) { + return customerDetailBO.getCustomerDetail(customerid); + } + + @GetMapping(value = "/getCustomerOrders/{customerid}") + public List getCustomerOrders(@PathVariable Integer customerid) { + return customerDetailBO.getCustomerOrders(customerid); + } + + @GetMapping(value = "/getOrder/{orderid}") + public Order getOrder(@PathVariable Integer orderid) { + return orderDetailBO.getOrderDetail(orderid); + } + + @GetMapping(value = "/getOrderPrice/{orderid}") + public double getOrderPrice(@PathVariable Integer orderid) { + return orderDetailBO.getOrderPrice(orderid); + } +} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java new file mode 100644 index 0000000000..cfae15f4e9 --- /dev/null +++ b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java @@ -0,0 +1,24 @@ +package com.baeldung.multiplecachemanager.entity; + +public class Customer { + + private int customerId; + + private String customerName; + + public int getCustomerId() { + return customerId; + } + + public void setCustomerId(int customerId) { + this.customerId = customerId; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } +} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java new file mode 100644 index 0000000000..4131464981 --- /dev/null +++ b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java @@ -0,0 +1,34 @@ +package com.baeldung.multiplecachemanager.entity; + +public class Item { + + private int itemId; + + private String itemDesc; + + private double itemPrice; + + public int getItemId() { + return itemId; + } + + public void setItemId(int itemId) { + this.itemId = itemId; + } + + public String getItemDesc() { + return itemDesc; + } + + public void setItemDesc(String itemDesc) { + this.itemDesc = itemDesc; + } + + public double getItemPrice() { + return itemPrice; + } + + public void setItemPrice(double itemPrice) { + this.itemPrice = itemPrice; + } +} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java new file mode 100644 index 0000000000..15da60d6ea --- /dev/null +++ b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java @@ -0,0 +1,44 @@ +package com.baeldung.multiplecachemanager.entity; + +public class Order { + + private int orderId; + + private int itemId; + + private int quantity; + + private int customerId; + + public int getOrderId() { + return orderId; + } + + public void setOrderId(int orderId) { + this.orderId = orderId; + } + + public int getItemId() { + return itemId; + } + + public void setItemId(int itemId) { + this.itemId = itemId; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public int getCustomerId() { + return customerId; + } + + public void setCustomerId(int customerId) { + this.customerId = customerId; + } +} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java new file mode 100644 index 0000000000..aab011427d --- /dev/null +++ b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java @@ -0,0 +1,49 @@ +package com.baeldung.multiplecachemanager.repository; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.stereotype.Repository; + +import com.baeldung.multiplecachemanager.entity.Customer; +import com.baeldung.multiplecachemanager.entity.Order; + +@Repository +public class CustomerDetailRepository { + + @Autowired + private JdbcTemplate jdbcTemplate; + + public Customer getCustomerDetail(Integer customerId) { + String customerQuery = "select * from customer where customerid = ? "; + Customer customer = new Customer(); + jdbcTemplate.query(customerQuery, new Object[] { customerId }, new RowCallbackHandler() { + public void processRow(ResultSet rs) throws SQLException { + customer.setCustomerId(rs.getInt("customerid")); + customer.setCustomerName(rs.getString("customername")); + } + }); + return customer; + } + + public List getCustomerOrders(Integer customerId) { + String customerOrderQuery = "select * from orderdetail where customerid = ? "; + List orders = new ArrayList(); + jdbcTemplate.query(customerOrderQuery, new Object[] { customerId }, new RowCallbackHandler() { + public void processRow(ResultSet rs) throws SQLException { + Order order = new Order(); + order.setCustomerId(rs.getInt("customerid")); + order.setItemId(rs.getInt("orderid")); + order.setOrderId(rs.getInt("orderid")); + order.setQuantity(rs.getInt("quantity")); + orders.add(order); + } + }); + return orders; + } +} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java new file mode 100644 index 0000000000..58c0968e48 --- /dev/null +++ b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java @@ -0,0 +1,53 @@ +package com.baeldung.multiplecachemanager.repository; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.stereotype.Repository; + +import com.baeldung.multiplecachemanager.entity.Item; +import com.baeldung.multiplecachemanager.entity.Order; + +@Repository +public class OrderDetailRepository { + + @Autowired + private JdbcTemplate jdbcTemplate; + + public Order getOrderDetail(Integer orderId) { + String orderDetailQuery = "select * from orderdetail where orderid = ? "; + Order order = new Order(); + jdbcTemplate.query(orderDetailQuery, new Object[] { orderId }, new RowCallbackHandler() { + public void processRow(ResultSet rs) throws SQLException { + order.setCustomerId(rs.getInt("customerid")); + order.setOrderId(rs.getInt("orderid")); + order.setItemId(rs.getInt("itemid")); + order.setQuantity(rs.getInt("quantity")); + } + }); + return order; + } + + public double getOrderPrice(Integer orderId) { + + String orderItemJoinQuery = "select * from ( select * from orderdetail where orderid = ? ) o left join item on o.itemid = ITEM.itemid"; + Order order = new Order(); + Item item = new Item(); + + jdbcTemplate.query(orderItemJoinQuery, new Object[] { orderId }, new RowCallbackHandler() { + public void processRow(ResultSet rs) throws SQLException { + order.setCustomerId(rs.getInt("customerid")); + order.setOrderId(rs.getInt("orderid")); + order.setItemId(rs.getInt("itemid")); + order.setQuantity(rs.getInt("quantity")); + item.setItemDesc("itemdesc"); + item.setItemId(rs.getInt("itemid")); + item.setItemPrice(rs.getDouble("price")); + } + }); + return order.getQuantity() * item.getItemPrice(); + } +} diff --git a/hexagonaljava/src/main/resources/application.properties b/multiplecachemanager/src/main/resources/application.properties similarity index 56% rename from hexagonaljava/src/main/resources/application.properties rename to multiplecachemanager/src/main/resources/application.properties index 5952b7eb01..53a3ac93b4 100644 --- a/hexagonaljava/src/main/resources/application.properties +++ b/multiplecachemanager/src/main/resources/application.properties @@ -2,4 +2,9 @@ spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= -spring.h2.console.enabled=false +#spring.h2.console.enabled=false + + +# Enabling H2 Console +spring.h2.console.enabled=true +spring.h2.console.path=/h2 diff --git a/multiplecachemanager/src/main/resources/data.sql b/multiplecachemanager/src/main/resources/data.sql new file mode 100644 index 0000000000..e4165ae71f --- /dev/null +++ b/multiplecachemanager/src/main/resources/data.sql @@ -0,0 +1,7 @@ +INSERT INTO CUSTOMER VALUES(1001,'BAELDUNG'); + +INSERT INTO ITEM VALUES(10001,'ITEM1',50.0); +INSERT INTO ITEM VALUES(10002,'ITEM2',100.0); + +INSERT INTO ORDERDETAIL VALUES(300001,1001,10001,2); +INSERT INTO ORDERDETAIL VALUES(300002,1001,10002,5); \ No newline at end of file diff --git a/multiplecachemanager/src/main/resources/schema.sql b/multiplecachemanager/src/main/resources/schema.sql new file mode 100644 index 0000000000..5862499bc0 --- /dev/null +++ b/multiplecachemanager/src/main/resources/schema.sql @@ -0,0 +1,19 @@ +CREATE TABLE CUSTOMER( + CUSTOMERID INT PRIMARY KEY, + CUSTOMERNAME VARCHAR(250) NOT NULL +); + +CREATE TABLE ITEM( +ITEMID INT PRIMARY KEY, +ITEMDESC VARCHAR(250), +PRICE DOUBLE +); + +CREATE TABLE ORDERDETAIL( +ORDERID INT PRIMARY KEY, +CUSTOMERID INT NOT NULL, +ITEMID INT NOT NULL, +QUANTITY INT, +FOREIGN KEY (customerid) references CUSTOMER(customerid), +FOREIGN KEY (itemid) references ITEM(itemid) +); \ No newline at end of file diff --git a/hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java b/multiplecachemanager/src/test/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplicationTests.java similarity index 62% rename from hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java rename to multiplecachemanager/src/test/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplicationTests.java index eed2f7e6a3..adf69309f2 100644 --- a/hexagonaljava/src/test/java/com/baeldung/hexagonaljava/HexagonaljavaApplicationTests.java +++ b/multiplecachemanager/src/test/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplicationTests.java @@ -1,12 +1,13 @@ -package com.baeldung.hexagonaljava; +package com.baeldung.multiplecachemanager; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -class HexagonaljavaApplicationTests { +class MultiplecachemanagerApplicationTests { @Test void contextLoads() { } + } From a00e511eb3b0eb13244894f1a622782d273fe049 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sat, 18 Apr 2020 03:47:11 +0530 Subject: [PATCH 005/309] BAEL-3963:Using multiple cache managers in Spring --- spring-caching/pom.xml | 17 +++++ .../caching/boot/CacheApplication.java | 4 ++ .../bo/CustomerDetailBO.java | 28 ++++++++ .../bo/OrderDetailBO.java | 25 ++++++++ .../config/MultipleCacheManagerConfig.java | 40 ++++++++++++ .../config/MultipleCacheResolver.java | 38 +++++++++++ .../MultipleCacheManagerController.java | 43 +++++++++++++ .../multiplecachemanager/entity/Customer.java | 24 +++++++ .../multiplecachemanager/entity/Item.java | 34 ++++++++++ .../multiplecachemanager/entity/Order.java | 44 +++++++++++++ .../repository/CustomerDetailRepository.java | 49 ++++++++++++++ .../repository/OrderDetailRepository.java | 53 +++++++++++++++ .../src/main/resources/application.properties | 10 +++ spring-caching/src/main/resources/data.sql | 7 ++ spring-caching/src/main/resources/schema.sql | 19 ++++++ ...ltipleCacheManagerIntegrationUnitTest.java | 64 +++++++++++++++++++ 16 files changed, 499 insertions(+) create mode 100644 spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java create mode 100644 spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java create mode 100644 spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheManagerConfig.java create mode 100644 spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java create mode 100644 spring-caching/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java create mode 100644 spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java create mode 100644 spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java create mode 100644 spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java create mode 100644 spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java create mode 100644 spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java create mode 100644 spring-caching/src/main/resources/application.properties create mode 100644 spring-caching/src/main/resources/data.sql create mode 100644 spring-caching/src/main/resources/schema.sql create mode 100644 spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java diff --git a/spring-caching/pom.xml b/spring-caching/pom.xml index d33f24de1f..11dd9a8873 100644 --- a/spring-caching/pom.xml +++ b/spring-caching/pom.xml @@ -15,6 +15,10 @@ + + org.springframework.boot + spring-boot-starter-web + org.springframework spring-context @@ -40,6 +44,19 @@ spring-test test + + com.github.ben-manes.caffeine + caffeine + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-jdbc + diff --git a/spring-caching/src/main/java/com/baeldung/caching/boot/CacheApplication.java b/spring-caching/src/main/java/com/baeldung/caching/boot/CacheApplication.java index 714dc443e0..afa1d0ec99 100644 --- a/spring-caching/src/main/java/com/baeldung/caching/boot/CacheApplication.java +++ b/spring-caching/src/main/java/com/baeldung/caching/boot/CacheApplication.java @@ -3,9 +3,13 @@ package com.baeldung.caching.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.annotation.EnableCaching; +//import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @EnableCaching +//to run any module like ehcache,caching or multiplecachemanager in local machine +//add it's package for ComponentScan like below +//@ComponentScan("com.baeldung.multiplecachemanager") public class CacheApplication { public static void main(String[] args) { diff --git a/spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java new file mode 100644 index 0000000000..3da4c23e28 --- /dev/null +++ b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java @@ -0,0 +1,28 @@ +package com.baeldung.multiplecachemanager.bo; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +import com.baeldung.multiplecachemanager.entity.Customer; +import com.baeldung.multiplecachemanager.entity.Order; +import com.baeldung.multiplecachemanager.repository.CustomerDetailRepository; + +@Component +public class CustomerDetailBO { + + @Autowired + private CustomerDetailRepository customerDetailRepository; + + @Cacheable(cacheNames = "customers") + public Customer getCustomerDetail(Integer customerId) { + return customerDetailRepository.getCustomerDetail(customerId); + } + + @Cacheable(cacheNames = "customerOrders", cacheManager = "alternateCacheManager") + public List getCustomerOrders(Integer customerId) { + return customerDetailRepository.getCustomerOrders(customerId); + } +} diff --git a/spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java new file mode 100644 index 0000000000..390881167f --- /dev/null +++ b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java @@ -0,0 +1,25 @@ +package com.baeldung.multiplecachemanager.bo; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +import com.baeldung.multiplecachemanager.entity.Order; +import com.baeldung.multiplecachemanager.repository.OrderDetailRepository; + +@Component +public class OrderDetailBO { + + @Autowired + private OrderDetailRepository orderDetailRepository; + + @Cacheable(cacheNames = "orders", cacheResolver = "cacheResolver") + public Order getOrderDetail(Integer orderId) { + return orderDetailRepository.getOrderDetail(orderId); + } + + @Cacheable(cacheNames = "orderprice", cacheResolver = "cacheResolver") + public double getOrderPrice(Integer orderId) { + return orderDetailRepository.getOrderPrice(orderId); + } +} diff --git a/spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheManagerConfig.java b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheManagerConfig.java new file mode 100644 index 0000000000..247a9b596b --- /dev/null +++ b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheManagerConfig.java @@ -0,0 +1,40 @@ +package com.baeldung.multiplecachemanager.config; + +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.cache.caffeine.CaffeineCacheManager; +import org.springframework.cache.concurrent.ConcurrentMapCacheManager; +import org.springframework.cache.interceptor.CacheResolver; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +//import org.springframework.context.annotation.Primary; + +import com.github.benmanes.caffeine.cache.Caffeine; + +@Configuration +@EnableCaching +public class MultipleCacheManagerConfig extends CachingConfigurerSupport { + + @Bean + //@Primary + public CacheManager cacheManager() { + CaffeineCacheManager cacheManager = new CaffeineCacheManager("customers", "orders"); + cacheManager.setCaffeine(Caffeine.newBuilder() + .initialCapacity(200) + .maximumSize(500) + .weakKeys() + .recordStats()); + return cacheManager; + } + + @Bean + public CacheManager alternateCacheManager() { + return new ConcurrentMapCacheManager("customerOrders", "orderprice"); + } + + @Bean + public CacheResolver cacheResolver() { + return new MultipleCacheResolver(alternateCacheManager(), cacheManager()); + } +} diff --git a/spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java new file mode 100644 index 0000000000..1bd869d98e --- /dev/null +++ b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java @@ -0,0 +1,38 @@ +package com.baeldung.multiplecachemanager.config; + +import java.util.ArrayList; +import java.util.Collection; + +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.interceptor.CacheOperationInvocationContext; +import org.springframework.cache.interceptor.CacheResolver; + +public class MultipleCacheResolver implements CacheResolver { + + private final CacheManager simpleCacheManager; + + private final CacheManager caffeineCacheManager; + + private static final String ORDER_CACHE = "orders"; + + private static final String ORDER_PRICE_CACHE = "orderprice"; + + public MultipleCacheResolver(CacheManager simpleCacheManager, CacheManager caffeineCacheManager) { + this.simpleCacheManager = simpleCacheManager; + this.caffeineCacheManager = caffeineCacheManager; + + } + + @Override + public Collection resolveCaches(CacheOperationInvocationContext context) { + Collection caches = new ArrayList(); + if ("getOrderDetail".equals(context.getMethod() + .getName())) { + caches.add(caffeineCacheManager.getCache(ORDER_CACHE)); + } else { + caches.add(simpleCacheManager.getCache(ORDER_PRICE_CACHE)); + } + return caches; + } +} diff --git a/spring-caching/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java new file mode 100644 index 0000000000..17a73bb27a --- /dev/null +++ b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java @@ -0,0 +1,43 @@ +package com.baeldung.multiplecachemanager.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.multiplecachemanager.bo.CustomerDetailBO; +import com.baeldung.multiplecachemanager.bo.OrderDetailBO; +import com.baeldung.multiplecachemanager.entity.Customer; +import com.baeldung.multiplecachemanager.entity.Order; + +@RestController +public class MultipleCacheManagerController { + + @Autowired + private CustomerDetailBO customerDetailBO; + + @Autowired + private OrderDetailBO orderDetailBO; + + @GetMapping(value = "/getCustomer/{customerid}") + public Customer getCustomer(@PathVariable Integer customerid) { + return customerDetailBO.getCustomerDetail(customerid); + } + + @GetMapping(value = "/getCustomerOrders/{customerid}") + public List getCustomerOrders(@PathVariable Integer customerid) { + return customerDetailBO.getCustomerOrders(customerid); + } + + @GetMapping(value = "/getOrder/{orderid}") + public Order getOrder(@PathVariable Integer orderid) { + return orderDetailBO.getOrderDetail(orderid); + } + + @GetMapping(value = "/getOrderPrice/{orderid}") + public double getOrderPrice(@PathVariable Integer orderid) { + return orderDetailBO.getOrderPrice(orderid); + } +} diff --git a/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java new file mode 100644 index 0000000000..cfae15f4e9 --- /dev/null +++ b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java @@ -0,0 +1,24 @@ +package com.baeldung.multiplecachemanager.entity; + +public class Customer { + + private int customerId; + + private String customerName; + + public int getCustomerId() { + return customerId; + } + + public void setCustomerId(int customerId) { + this.customerId = customerId; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } +} diff --git a/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java new file mode 100644 index 0000000000..4131464981 --- /dev/null +++ b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java @@ -0,0 +1,34 @@ +package com.baeldung.multiplecachemanager.entity; + +public class Item { + + private int itemId; + + private String itemDesc; + + private double itemPrice; + + public int getItemId() { + return itemId; + } + + public void setItemId(int itemId) { + this.itemId = itemId; + } + + public String getItemDesc() { + return itemDesc; + } + + public void setItemDesc(String itemDesc) { + this.itemDesc = itemDesc; + } + + public double getItemPrice() { + return itemPrice; + } + + public void setItemPrice(double itemPrice) { + this.itemPrice = itemPrice; + } +} diff --git a/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java new file mode 100644 index 0000000000..15da60d6ea --- /dev/null +++ b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java @@ -0,0 +1,44 @@ +package com.baeldung.multiplecachemanager.entity; + +public class Order { + + private int orderId; + + private int itemId; + + private int quantity; + + private int customerId; + + public int getOrderId() { + return orderId; + } + + public void setOrderId(int orderId) { + this.orderId = orderId; + } + + public int getItemId() { + return itemId; + } + + public void setItemId(int itemId) { + this.itemId = itemId; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public int getCustomerId() { + return customerId; + } + + public void setCustomerId(int customerId) { + this.customerId = customerId; + } +} diff --git a/spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java new file mode 100644 index 0000000000..aab011427d --- /dev/null +++ b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java @@ -0,0 +1,49 @@ +package com.baeldung.multiplecachemanager.repository; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.stereotype.Repository; + +import com.baeldung.multiplecachemanager.entity.Customer; +import com.baeldung.multiplecachemanager.entity.Order; + +@Repository +public class CustomerDetailRepository { + + @Autowired + private JdbcTemplate jdbcTemplate; + + public Customer getCustomerDetail(Integer customerId) { + String customerQuery = "select * from customer where customerid = ? "; + Customer customer = new Customer(); + jdbcTemplate.query(customerQuery, new Object[] { customerId }, new RowCallbackHandler() { + public void processRow(ResultSet rs) throws SQLException { + customer.setCustomerId(rs.getInt("customerid")); + customer.setCustomerName(rs.getString("customername")); + } + }); + return customer; + } + + public List getCustomerOrders(Integer customerId) { + String customerOrderQuery = "select * from orderdetail where customerid = ? "; + List orders = new ArrayList(); + jdbcTemplate.query(customerOrderQuery, new Object[] { customerId }, new RowCallbackHandler() { + public void processRow(ResultSet rs) throws SQLException { + Order order = new Order(); + order.setCustomerId(rs.getInt("customerid")); + order.setItemId(rs.getInt("orderid")); + order.setOrderId(rs.getInt("orderid")); + order.setQuantity(rs.getInt("quantity")); + orders.add(order); + } + }); + return orders; + } +} diff --git a/spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java new file mode 100644 index 0000000000..58c0968e48 --- /dev/null +++ b/spring-caching/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java @@ -0,0 +1,53 @@ +package com.baeldung.multiplecachemanager.repository; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowCallbackHandler; +import org.springframework.stereotype.Repository; + +import com.baeldung.multiplecachemanager.entity.Item; +import com.baeldung.multiplecachemanager.entity.Order; + +@Repository +public class OrderDetailRepository { + + @Autowired + private JdbcTemplate jdbcTemplate; + + public Order getOrderDetail(Integer orderId) { + String orderDetailQuery = "select * from orderdetail where orderid = ? "; + Order order = new Order(); + jdbcTemplate.query(orderDetailQuery, new Object[] { orderId }, new RowCallbackHandler() { + public void processRow(ResultSet rs) throws SQLException { + order.setCustomerId(rs.getInt("customerid")); + order.setOrderId(rs.getInt("orderid")); + order.setItemId(rs.getInt("itemid")); + order.setQuantity(rs.getInt("quantity")); + } + }); + return order; + } + + public double getOrderPrice(Integer orderId) { + + String orderItemJoinQuery = "select * from ( select * from orderdetail where orderid = ? ) o left join item on o.itemid = ITEM.itemid"; + Order order = new Order(); + Item item = new Item(); + + jdbcTemplate.query(orderItemJoinQuery, new Object[] { orderId }, new RowCallbackHandler() { + public void processRow(ResultSet rs) throws SQLException { + order.setCustomerId(rs.getInt("customerid")); + order.setOrderId(rs.getInt("orderid")); + order.setItemId(rs.getInt("itemid")); + order.setQuantity(rs.getInt("quantity")); + item.setItemDesc("itemdesc"); + item.setItemId(rs.getInt("itemid")); + item.setItemPrice(rs.getDouble("price")); + } + }); + return order.getQuantity() * item.getItemPrice(); + } +} diff --git a/spring-caching/src/main/resources/application.properties b/spring-caching/src/main/resources/application.properties new file mode 100644 index 0000000000..53a3ac93b4 --- /dev/null +++ b/spring-caching/src/main/resources/application.properties @@ -0,0 +1,10 @@ +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= +#spring.h2.console.enabled=false + + +# Enabling H2 Console +spring.h2.console.enabled=true +spring.h2.console.path=/h2 diff --git a/spring-caching/src/main/resources/data.sql b/spring-caching/src/main/resources/data.sql new file mode 100644 index 0000000000..e4165ae71f --- /dev/null +++ b/spring-caching/src/main/resources/data.sql @@ -0,0 +1,7 @@ +INSERT INTO CUSTOMER VALUES(1001,'BAELDUNG'); + +INSERT INTO ITEM VALUES(10001,'ITEM1',50.0); +INSERT INTO ITEM VALUES(10002,'ITEM2',100.0); + +INSERT INTO ORDERDETAIL VALUES(300001,1001,10001,2); +INSERT INTO ORDERDETAIL VALUES(300002,1001,10002,5); \ No newline at end of file diff --git a/spring-caching/src/main/resources/schema.sql b/spring-caching/src/main/resources/schema.sql new file mode 100644 index 0000000000..5862499bc0 --- /dev/null +++ b/spring-caching/src/main/resources/schema.sql @@ -0,0 +1,19 @@ +CREATE TABLE CUSTOMER( + CUSTOMERID INT PRIMARY KEY, + CUSTOMERNAME VARCHAR(250) NOT NULL +); + +CREATE TABLE ITEM( +ITEMID INT PRIMARY KEY, +ITEMDESC VARCHAR(250), +PRICE DOUBLE +); + +CREATE TABLE ORDERDETAIL( +ORDERID INT PRIMARY KEY, +CUSTOMERID INT NOT NULL, +ITEMID INT NOT NULL, +QUANTITY INT, +FOREIGN KEY (customerid) references CUSTOMER(customerid), +FOREIGN KEY (itemid) references ITEM(itemid) +); \ No newline at end of file diff --git a/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java b/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java new file mode 100644 index 0000000000..4bcbdb4d68 --- /dev/null +++ b/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java @@ -0,0 +1,64 @@ +package com.baeldung.multiplecachemanager; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.caffeine.CaffeineCache; +import org.springframework.util.Assert; + +import com.baeldung.multiplecachemanager.bo.OrderDetailBO; +import com.baeldung.multiplecachemanager.entity.Order; +import com.baeldung.multiplecachemanager.repository.OrderDetailRepository; + +@SpringBootApplication +@SpringBootTest +public class MultipleCacheManagerIntegrationUnitTest { + + @MockBean + private OrderDetailRepository orderDetailRepository; + + @Autowired + private OrderDetailBO orderDetailBO; + + @Autowired + private CacheManager cacheManager; + + @Autowired + private CacheManager alternateCacheManager; + + @Test + public void whenCallGetOrderDetail_thenDataShouldBeInCaffieneCacheManager() { + Integer key = 30001; + cacheManager.getCache("orders") + .evict(key); + Order order = new Order(); + order.setCustomerId(1001); + order.setItemId(10001); + order.setOrderId(30001); + order.setQuantity(2); + Mockito.when(orderDetailRepository.getOrderDetail(key)) + .thenReturn(order); + orderDetailBO.getOrderDetail(key); + org.springframework.cache.caffeine.CaffeineCache cache = (CaffeineCache) cacheManager.getCache("orders"); + Assert.notNull(cache.get(key) + .get(), "caffieneCache should have had the data"); + } + + @Test + public void whenCallGetOrderPrice_thenDataShouldBeInAlternateCacheManager() { + Integer key = 30001; + alternateCacheManager.getCache("orderprice") + .evict(key); + Mockito.when(orderDetailRepository.getOrderPrice(key)) + .thenReturn(500.0); + orderDetailBO.getOrderPrice(key); + Cache cache = alternateCacheManager.getCache("orderprice"); + Assert.notNull(cache.get(key) + .get(), "alternateCache should have had the data"); + } +} From a6dc19343777ab7b6b2ecb6496b1ee7b1f027b19 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sat, 18 Apr 2020 03:52:29 +0530 Subject: [PATCH 006/309] removing new module created in last pull request --- multiplecachemanager/pom.xml | 69 ------------------- .../MultiplecachemanagerApplication.java | 45 ------------ .../bo/CustomerDetailBO.java | 28 -------- .../bo/OrderDetailBO.java | 25 ------- .../config/MultipleCacheResolver.java | 38 ---------- .../MultipleCacheManagerController.java | 43 ------------ .../multiplecachemanager/entity/Customer.java | 24 ------- .../multiplecachemanager/entity/Item.java | 34 --------- .../multiplecachemanager/entity/Order.java | 44 ------------ .../repository/CustomerDetailRepository.java | 49 ------------- .../repository/OrderDetailRepository.java | 53 -------------- .../src/main/resources/application.properties | 10 --- .../src/main/resources/data.sql | 7 -- .../src/main/resources/schema.sql | 19 ----- .../MultiplecachemanagerApplicationTests.java | 13 ---- 15 files changed, 501 deletions(-) delete mode 100644 multiplecachemanager/pom.xml delete mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplication.java delete mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java delete mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java delete mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java delete mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java delete mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java delete mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java delete mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java delete mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java delete mode 100644 multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java delete mode 100644 multiplecachemanager/src/main/resources/application.properties delete mode 100644 multiplecachemanager/src/main/resources/data.sql delete mode 100644 multiplecachemanager/src/main/resources/schema.sql delete mode 100644 multiplecachemanager/src/test/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplicationTests.java diff --git a/multiplecachemanager/pom.xml b/multiplecachemanager/pom.xml deleted file mode 100644 index 22daf6e87d..0000000000 --- a/multiplecachemanager/pom.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.6.RELEASE - - - com.baeldung - multiplecachemanager - 0.0.1-SNAPSHOT - multiplecachemanager - sample project for configuring multiple cache managers - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-jdbc - - - org.springframework.boot - spring-boot-starter-web - - - - com.h2database - h2 - runtime - - - - org.springframework.boot - spring-boot-starter-cache - - - - com.github.ben-manes.caffeine - caffeine - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplication.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplication.java deleted file mode 100644 index 4c7efc98bd..0000000000 --- a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplication.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.multiplecachemanager; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cache.CacheManager; -import org.springframework.cache.annotation.CachingConfigurerSupport; -import org.springframework.cache.annotation.EnableCaching; -import org.springframework.cache.caffeine.CaffeineCacheManager; -import org.springframework.cache.concurrent.ConcurrentMapCacheManager; -import org.springframework.cache.interceptor.CacheResolver; -import org.springframework.context.annotation.Bean; - -import com.baeldung.multiplecachemanager.config.MultipleCacheResolver; -import com.github.benmanes.caffeine.cache.Caffeine; - -@SpringBootApplication -@EnableCaching -public class MultiplecachemanagerApplication extends CachingConfigurerSupport { - - public static void main(String[] args) { - SpringApplication.run(MultiplecachemanagerApplication.class, args); - } - - @Bean - // @Primary - public CacheManager cacheManager() { - CaffeineCacheManager cacheManager = new CaffeineCacheManager("customers", "orders"); - cacheManager.setCaffeine(Caffeine.newBuilder() - .initialCapacity(200) - .maximumSize(500) - .weakKeys() - .recordStats()); - return cacheManager; - } - - @Bean - public CacheManager alternateCacheManager() { - return new ConcurrentMapCacheManager("customerOrders", "orderprice"); - } - - @Bean - public CacheResolver cacheResolver() { - return new MultipleCacheResolver(alternateCacheManager(), cacheManager()); - } -} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java deleted file mode 100644 index 3da4c23e28..0000000000 --- a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/CustomerDetailBO.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.multiplecachemanager.bo; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Component; - -import com.baeldung.multiplecachemanager.entity.Customer; -import com.baeldung.multiplecachemanager.entity.Order; -import com.baeldung.multiplecachemanager.repository.CustomerDetailRepository; - -@Component -public class CustomerDetailBO { - - @Autowired - private CustomerDetailRepository customerDetailRepository; - - @Cacheable(cacheNames = "customers") - public Customer getCustomerDetail(Integer customerId) { - return customerDetailRepository.getCustomerDetail(customerId); - } - - @Cacheable(cacheNames = "customerOrders", cacheManager = "alternateCacheManager") - public List getCustomerOrders(Integer customerId) { - return customerDetailRepository.getCustomerOrders(customerId); - } -} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java deleted file mode 100644 index cb9e301fcb..0000000000 --- a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/bo/OrderDetailBO.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.multiplecachemanager.bo; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Component; - -import com.baeldung.multiplecachemanager.entity.Order; -import com.baeldung.multiplecachemanager.repository.OrderDetailRepository; - -@Component -public class OrderDetailBO { - - @Autowired - private OrderDetailRepository orderDetailRepository; - - @Cacheable(cacheNames = "orders", cacheResolver = "cacheResolver") - public Order getOrderDetail(Integer orderId) { - return orderDetailRepository.getOrderDetail(orderId); - } - - @Cacheable(cacheNames = "orderprice", cacheResolver = "cacheResolver") - public double getOrderPrice(Integer orderId) { - return orderDetailRepository.getOrderPrice(orderId); - } -} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java deleted file mode 100644 index 1bd869d98e..0000000000 --- a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/config/MultipleCacheResolver.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.multiplecachemanager.config; - -import java.util.ArrayList; -import java.util.Collection; - -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.cache.interceptor.CacheOperationInvocationContext; -import org.springframework.cache.interceptor.CacheResolver; - -public class MultipleCacheResolver implements CacheResolver { - - private final CacheManager simpleCacheManager; - - private final CacheManager caffeineCacheManager; - - private static final String ORDER_CACHE = "orders"; - - private static final String ORDER_PRICE_CACHE = "orderprice"; - - public MultipleCacheResolver(CacheManager simpleCacheManager, CacheManager caffeineCacheManager) { - this.simpleCacheManager = simpleCacheManager; - this.caffeineCacheManager = caffeineCacheManager; - - } - - @Override - public Collection resolveCaches(CacheOperationInvocationContext context) { - Collection caches = new ArrayList(); - if ("getOrderDetail".equals(context.getMethod() - .getName())) { - caches.add(caffeineCacheManager.getCache(ORDER_CACHE)); - } else { - caches.add(simpleCacheManager.getCache(ORDER_PRICE_CACHE)); - } - return caches; - } -} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java deleted file mode 100644 index 17a73bb27a..0000000000 --- a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/controller/MultipleCacheManagerController.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.multiplecachemanager.controller; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.multiplecachemanager.bo.CustomerDetailBO; -import com.baeldung.multiplecachemanager.bo.OrderDetailBO; -import com.baeldung.multiplecachemanager.entity.Customer; -import com.baeldung.multiplecachemanager.entity.Order; - -@RestController -public class MultipleCacheManagerController { - - @Autowired - private CustomerDetailBO customerDetailBO; - - @Autowired - private OrderDetailBO orderDetailBO; - - @GetMapping(value = "/getCustomer/{customerid}") - public Customer getCustomer(@PathVariable Integer customerid) { - return customerDetailBO.getCustomerDetail(customerid); - } - - @GetMapping(value = "/getCustomerOrders/{customerid}") - public List getCustomerOrders(@PathVariable Integer customerid) { - return customerDetailBO.getCustomerOrders(customerid); - } - - @GetMapping(value = "/getOrder/{orderid}") - public Order getOrder(@PathVariable Integer orderid) { - return orderDetailBO.getOrderDetail(orderid); - } - - @GetMapping(value = "/getOrderPrice/{orderid}") - public double getOrderPrice(@PathVariable Integer orderid) { - return orderDetailBO.getOrderPrice(orderid); - } -} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java deleted file mode 100644 index cfae15f4e9..0000000000 --- a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Customer.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.multiplecachemanager.entity; - -public class Customer { - - private int customerId; - - private String customerName; - - public int getCustomerId() { - return customerId; - } - - public void setCustomerId(int customerId) { - this.customerId = customerId; - } - - public String getCustomerName() { - return customerName; - } - - public void setCustomerName(String customerName) { - this.customerName = customerName; - } -} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java deleted file mode 100644 index 4131464981..0000000000 --- a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Item.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.multiplecachemanager.entity; - -public class Item { - - private int itemId; - - private String itemDesc; - - private double itemPrice; - - public int getItemId() { - return itemId; - } - - public void setItemId(int itemId) { - this.itemId = itemId; - } - - public String getItemDesc() { - return itemDesc; - } - - public void setItemDesc(String itemDesc) { - this.itemDesc = itemDesc; - } - - public double getItemPrice() { - return itemPrice; - } - - public void setItemPrice(double itemPrice) { - this.itemPrice = itemPrice; - } -} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java deleted file mode 100644 index 15da60d6ea..0000000000 --- a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/entity/Order.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.multiplecachemanager.entity; - -public class Order { - - private int orderId; - - private int itemId; - - private int quantity; - - private int customerId; - - public int getOrderId() { - return orderId; - } - - public void setOrderId(int orderId) { - this.orderId = orderId; - } - - public int getItemId() { - return itemId; - } - - public void setItemId(int itemId) { - this.itemId = itemId; - } - - public int getQuantity() { - return quantity; - } - - public void setQuantity(int quantity) { - this.quantity = quantity; - } - - public int getCustomerId() { - return customerId; - } - - public void setCustomerId(int customerId) { - this.customerId = customerId; - } -} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java deleted file mode 100644 index aab011427d..0000000000 --- a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/CustomerDetailRepository.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.multiplecachemanager.repository; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.stereotype.Repository; - -import com.baeldung.multiplecachemanager.entity.Customer; -import com.baeldung.multiplecachemanager.entity.Order; - -@Repository -public class CustomerDetailRepository { - - @Autowired - private JdbcTemplate jdbcTemplate; - - public Customer getCustomerDetail(Integer customerId) { - String customerQuery = "select * from customer where customerid = ? "; - Customer customer = new Customer(); - jdbcTemplate.query(customerQuery, new Object[] { customerId }, new RowCallbackHandler() { - public void processRow(ResultSet rs) throws SQLException { - customer.setCustomerId(rs.getInt("customerid")); - customer.setCustomerName(rs.getString("customername")); - } - }); - return customer; - } - - public List getCustomerOrders(Integer customerId) { - String customerOrderQuery = "select * from orderdetail where customerid = ? "; - List orders = new ArrayList(); - jdbcTemplate.query(customerOrderQuery, new Object[] { customerId }, new RowCallbackHandler() { - public void processRow(ResultSet rs) throws SQLException { - Order order = new Order(); - order.setCustomerId(rs.getInt("customerid")); - order.setItemId(rs.getInt("orderid")); - order.setOrderId(rs.getInt("orderid")); - order.setQuantity(rs.getInt("quantity")); - orders.add(order); - } - }); - return orders; - } -} diff --git a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java b/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java deleted file mode 100644 index 58c0968e48..0000000000 --- a/multiplecachemanager/src/main/java/com/baeldung/multiplecachemanager/repository/OrderDetailRepository.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.multiplecachemanager.repository; - -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.RowCallbackHandler; -import org.springframework.stereotype.Repository; - -import com.baeldung.multiplecachemanager.entity.Item; -import com.baeldung.multiplecachemanager.entity.Order; - -@Repository -public class OrderDetailRepository { - - @Autowired - private JdbcTemplate jdbcTemplate; - - public Order getOrderDetail(Integer orderId) { - String orderDetailQuery = "select * from orderdetail where orderid = ? "; - Order order = new Order(); - jdbcTemplate.query(orderDetailQuery, new Object[] { orderId }, new RowCallbackHandler() { - public void processRow(ResultSet rs) throws SQLException { - order.setCustomerId(rs.getInt("customerid")); - order.setOrderId(rs.getInt("orderid")); - order.setItemId(rs.getInt("itemid")); - order.setQuantity(rs.getInt("quantity")); - } - }); - return order; - } - - public double getOrderPrice(Integer orderId) { - - String orderItemJoinQuery = "select * from ( select * from orderdetail where orderid = ? ) o left join item on o.itemid = ITEM.itemid"; - Order order = new Order(); - Item item = new Item(); - - jdbcTemplate.query(orderItemJoinQuery, new Object[] { orderId }, new RowCallbackHandler() { - public void processRow(ResultSet rs) throws SQLException { - order.setCustomerId(rs.getInt("customerid")); - order.setOrderId(rs.getInt("orderid")); - order.setItemId(rs.getInt("itemid")); - order.setQuantity(rs.getInt("quantity")); - item.setItemDesc("itemdesc"); - item.setItemId(rs.getInt("itemid")); - item.setItemPrice(rs.getDouble("price")); - } - }); - return order.getQuantity() * item.getItemPrice(); - } -} diff --git a/multiplecachemanager/src/main/resources/application.properties b/multiplecachemanager/src/main/resources/application.properties deleted file mode 100644 index 53a3ac93b4..0000000000 --- a/multiplecachemanager/src/main/resources/application.properties +++ /dev/null @@ -1,10 +0,0 @@ -spring.datasource.url=jdbc:h2:mem:testdb -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.username=sa -spring.datasource.password= -#spring.h2.console.enabled=false - - -# Enabling H2 Console -spring.h2.console.enabled=true -spring.h2.console.path=/h2 diff --git a/multiplecachemanager/src/main/resources/data.sql b/multiplecachemanager/src/main/resources/data.sql deleted file mode 100644 index e4165ae71f..0000000000 --- a/multiplecachemanager/src/main/resources/data.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO CUSTOMER VALUES(1001,'BAELDUNG'); - -INSERT INTO ITEM VALUES(10001,'ITEM1',50.0); -INSERT INTO ITEM VALUES(10002,'ITEM2',100.0); - -INSERT INTO ORDERDETAIL VALUES(300001,1001,10001,2); -INSERT INTO ORDERDETAIL VALUES(300002,1001,10002,5); \ No newline at end of file diff --git a/multiplecachemanager/src/main/resources/schema.sql b/multiplecachemanager/src/main/resources/schema.sql deleted file mode 100644 index 5862499bc0..0000000000 --- a/multiplecachemanager/src/main/resources/schema.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE TABLE CUSTOMER( - CUSTOMERID INT PRIMARY KEY, - CUSTOMERNAME VARCHAR(250) NOT NULL -); - -CREATE TABLE ITEM( -ITEMID INT PRIMARY KEY, -ITEMDESC VARCHAR(250), -PRICE DOUBLE -); - -CREATE TABLE ORDERDETAIL( -ORDERID INT PRIMARY KEY, -CUSTOMERID INT NOT NULL, -ITEMID INT NOT NULL, -QUANTITY INT, -FOREIGN KEY (customerid) references CUSTOMER(customerid), -FOREIGN KEY (itemid) references ITEM(itemid) -); \ No newline at end of file diff --git a/multiplecachemanager/src/test/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplicationTests.java b/multiplecachemanager/src/test/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplicationTests.java deleted file mode 100644 index adf69309f2..0000000000 --- a/multiplecachemanager/src/test/java/com/baeldung/multiplecachemanager/MultiplecachemanagerApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.multiplecachemanager; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class MultiplecachemanagerApplicationTests { - - @Test - void contextLoads() { - } - -} From d7ee1a96991f4f2854ed388861797f1a8f4765be Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sat, 18 Apr 2020 15:52:19 +0530 Subject: [PATCH 007/309] Fixes as per editor Suggestions --- spring-caching/pom.xml | 101 +++++++++--------- .../src/main/resources/application.properties | 2 - ...ltipleCacheManagerIntegrationUnitTest.java | 4 +- 3 files changed, 53 insertions(+), 54 deletions(-) diff --git a/spring-caching/pom.xml b/spring-caching/pom.xml index 11dd9a8873..f56d3cf328 100644 --- a/spring-caching/pom.xml +++ b/spring-caching/pom.xml @@ -1,54 +1,55 @@ - - 4.0.0 - spring-caching - 0.1-SNAPSHOT - spring-caching - war + + 4.0.0 + spring-caching + 0.1-SNAPSHOT + spring-caching + war - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../parent-boot-2 - + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + - - + + org.springframework.boot spring-boot-starter-web - - org.springframework - spring-context - - - org.springframework.boot - spring-boot-starter-cache - - - org.springframework - spring-web - - - org.springframework - spring-webmvc - - - org.ehcache - ehcache - - - org.springframework - spring-test - test - - - com.github.ben-manes.caffeine - caffeine - - + + org.springframework + spring-context + + + org.springframework.boot + spring-boot-starter-cache + + + org.springframework + spring-web + + + org.springframework + spring-webmvc + + + org.ehcache + ehcache + + + org.springframework + spring-test + test + + + com.github.ben-manes.caffeine + caffeine + + com.h2database h2 runtime @@ -57,10 +58,10 @@ org.springframework.boot spring-boot-starter-jdbc - + + + + 3.5.2 + - - 3.5.2 - - \ No newline at end of file diff --git a/spring-caching/src/main/resources/application.properties b/spring-caching/src/main/resources/application.properties index 53a3ac93b4..ee7b5e62c0 100644 --- a/spring-caching/src/main/resources/application.properties +++ b/spring-caching/src/main/resources/application.properties @@ -2,8 +2,6 @@ spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= -#spring.h2.console.enabled=false - # Enabling H2 Console spring.h2.console.enabled=true diff --git a/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java b/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java index 4bcbdb4d68..e02e5da246 100644 --- a/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java +++ b/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java @@ -32,7 +32,7 @@ public class MultipleCacheManagerIntegrationUnitTest { private CacheManager alternateCacheManager; @Test - public void whenCallGetOrderDetail_thenDataShouldBeInCaffieneCacheManager() { + public void givenCacheResolverIsConfigured_whenCallGetOrderDetail_thenDataShouldBeInCaffieneCacheManager() { Integer key = 30001; cacheManager.getCache("orders") .evict(key); @@ -50,7 +50,7 @@ public class MultipleCacheManagerIntegrationUnitTest { } @Test - public void whenCallGetOrderPrice_thenDataShouldBeInAlternateCacheManager() { + public void givenCacheResolverIsConfigured_whenCallGetOrderPrice_thenDataShouldBeInAlternateCacheManager() { Integer key = 30001; alternateCacheManager.getCache("orderprice") .evict(key); From 5d04769c759824fb6d39eff874eda44339337830 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Mon, 27 Apr 2020 01:54:51 +0530 Subject: [PATCH 008/309] fixing spacing issue in pom.xml --- spring-caching/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-caching/pom.xml b/spring-caching/pom.xml index f56d3cf328..e62ebd501b 100644 --- a/spring-caching/pom.xml +++ b/spring-caching/pom.xml @@ -63,5 +63,4 @@ 3.5.2 - - \ No newline at end of file + From 4103e9a75c991125c2f919925a0c4c77dc036b32 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Mon, 27 Apr 2020 02:10:04 +0530 Subject: [PATCH 009/309] Fixing spacing issue in pom.xml --- spring-caching/pom.xml | 116 ++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/spring-caching/pom.xml b/spring-caching/pom.xml index e62ebd501b..3c594ee8ab 100644 --- a/spring-caching/pom.xml +++ b/spring-caching/pom.xml @@ -2,65 +2,65 @@ - 4.0.0 - spring-caching - 0.1-SNAPSHOT - spring-caching - war + 4.0.0 + spring-caching + 0.1-SNAPSHOT + spring-caching + war - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../parent-boot-2 - + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework - spring-context - - - org.springframework.boot - spring-boot-starter-cache - - - org.springframework - spring-web - - - org.springframework - spring-webmvc - - - org.ehcache - ehcache - - - org.springframework - spring-test - test - - - com.github.ben-manes.caffeine - caffeine - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-starter-jdbc - - + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework + spring-context + + + org.springframework.boot + spring-boot-starter-cache + + + org.springframework + spring-web + + + org.springframework + spring-webmvc + + + org.ehcache + ehcache + + + org.springframework + spring-test + test + + + com.github.ben-manes.caffeine + caffeine + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-jdbc + + - - 3.5.2 - + + 3.5.2 + From f9a771d6952cf968f597f4bc4beb7c3575ef2d21 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Mon, 27 Apr 2020 02:51:43 +0530 Subject: [PATCH 010/309] Fixing spacing issue 2 --- spring-caching/pom.xml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/spring-caching/pom.xml b/spring-caching/pom.xml index 3c594ee8ab..f443919b42 100644 --- a/spring-caching/pom.xml +++ b/spring-caching/pom.xml @@ -2,20 +2,20 @@ - 4.0.0 - spring-caching - 0.1-SNAPSHOT - spring-caching - war + 4.0.0 + spring-caching + 0.1-SNAPSHOT + spring-caching + war - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../parent-boot-2 - + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + - + org.springframework.boot spring-boot-starter-web @@ -58,9 +58,9 @@ org.springframework.boot spring-boot-starter-jdbc - + - - 3.5.2 - + + 3.5.2 + From cdc79108444d58fed34227222e9cf1a79e63a675 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Mon, 27 Apr 2020 03:30:41 +0530 Subject: [PATCH 011/309] Formatting space issues in pom.xml --- spring-caching/pom.xml | 93 +++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/spring-caching/pom.xml b/spring-caching/pom.xml index f443919b42..80644f8a5f 100644 --- a/spring-caching/pom.xml +++ b/spring-caching/pom.xml @@ -9,58 +9,57 @@ war - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../parent-boot-2 + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 - - org.springframework.boot - spring-boot-starter-web - - - org.springframework - spring-context - - - org.springframework.boot - spring-boot-starter-cache - - - org.springframework - spring-web + + org.springframework.boot + spring-boot-starter-web + + + org.springframework + spring-context + + + org.springframework.boot + spring-boot-starter-cache + + + org.springframework + spring-web + + + org.springframework + spring-webmvc + + + org.ehcache + ehcache + + + org.springframework + spring-test + test + + + com.github.ben-manes.caffeine + caffeine + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-jdbc - - org.springframework - spring-webmvc - - - org.ehcache - ehcache - - - org.springframework - spring-test - test - - - com.github.ben-manes.caffeine - caffeine - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-starter-jdbc - - - 3.5.2 + 3.5.2 From a11b2d812be30138e980285d2ebc76fdaa864e87 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Tue, 1 Oct 2019 12:56:55 -0400 Subject: [PATCH 012/309] Add architecture module with Hexagonal example --- architecture/README.md | 3 ++ architecture/pom.xml | 33 ++++++++++++ .../HexagonalArchitectureTaskApplication.java | 12 +++++ .../application/task/AddNewDailyTask.java | 29 ++++++++++ .../application/task/AddNewTask.java | 22 ++++++++ .../application/task/GetTasks.java | 22 ++++++++ .../commands/task/CreateTask.java | 7 +++ .../commands/task/GetAllTasks.java | 7 +++ .../architecture/domain/task/Task.java | 53 +++++++++++++++++++ .../domain/task/TaskRepository.java | 7 +++ .../architecture/domain/task/TaskService.java | 22 ++++++++ .../framework/cli/StartupRunner.java | 25 +++++++++ .../http/task/TaskApiController.java | 42 +++++++++++++++ .../framework/http/task/TaskRequest.java | 29 ++++++++++ 14 files changed, 313 insertions(+) create mode 100644 architecture/README.md create mode 100644 architecture/pom.xml create mode 100644 architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java create mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java diff --git a/architecture/README.md b/architecture/README.md new file mode 100644 index 0000000000..be093f25ed --- /dev/null +++ b/architecture/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [A Quick and Practical Example of Hexagonal Architecture in Java](https://www.baeldung.com/a-quick-and-practical-example-of-hexagonal-architecture-in-java-3/) diff --git a/architecture/pom.xml b/architecture/pom.xml new file mode 100644 index 0000000000..4ad104293e --- /dev/null +++ b/architecture/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + com.baeldung.architecture + architecture + 0.0.1-SNAPSHOT + architecture + jar + A Quick and Practical Example of Hexagonal Architecture in Java + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-web + + + diff --git a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java new file mode 100644 index 0000000000..83e4fc4c0b --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.architecture; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HexagonalArchitectureTaskApplication { + public static void main(String[] args) { + SpringApplication.run(HexagonalArchitectureTaskApplication.class, args); + } + +} diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java new file mode 100644 index 0000000000..208d1bfcc9 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java @@ -0,0 +1,29 @@ +package com.baeldung.architecture.application.task; + +import java.time.Instant; +import java.time.temporal.ChronoUnit; + +import com.baeldung.architecture.commands.task.CreateTask; +import com.baeldung.architecture.domain.task.Task; + +import org.springframework.stereotype.Component; + +@Component +public class AddNewDailyTask implements CreateTask { + + private AddNewTask addNewTask; + + public AddNewDailyTask(AddNewTask addNewTask) { + this.addNewTask = addNewTask; + } + + @Override + public void create(Task newTask) { + Instant initialDueDate = newTask.getDueDate(); + String description = newTask.getDescription(); + for (int i = 1; i <= 5; i++) { + Task task = new Task(initialDueDate.plus(i, ChronoUnit.DAYS), description); + addNewTask.create(task); + } + } +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java new file mode 100644 index 0000000000..2e5aff4a53 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java @@ -0,0 +1,22 @@ +package com.baeldung.architecture.application.task; + +import com.baeldung.architecture.domain.task.Task; +import com.baeldung.architecture.domain.task.TaskService; +import com.baeldung.architecture.commands.task.*; + +import org.springframework.stereotype.Component; + +@Component +public class AddNewTask implements CreateTask { + + private TaskService taskService; + + public AddNewTask(TaskService taskService) { + this.taskService = taskService; + } + + @Override + public void create(Task newTask) { + taskService.createTask(newTask); + } +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java new file mode 100644 index 0000000000..54539290ba --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java @@ -0,0 +1,22 @@ +package com.baeldung.architecture.application.task; + +import com.baeldung.architecture.domain.task.Task; +import com.baeldung.architecture.domain.task.TaskService; +import com.baeldung.architecture.commands.task.*; + +import org.springframework.stereotype.Component; + +@Component +public class GetTasks implements GetAllTasks { + + private TaskService taskService; + + public GetTasks(TaskService taskService) { + this.taskService = taskService; + } + + @Override + public Iterable getAll() { + return taskService.getAllTasks(); + } +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java new file mode 100644 index 0000000000..26e6da10e2 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java @@ -0,0 +1,7 @@ +package com.baeldung.architecture.commands.task; + +import com.baeldung.architecture.domain.task.Task; + +public interface CreateTask { + public void create(Task newTask); +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java new file mode 100644 index 0000000000..d3c40db92f --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java @@ -0,0 +1,7 @@ +package com.baeldung.architecture.commands.task; + +import com.baeldung.architecture.domain.task.Task; + +public interface GetAllTasks { + public Iterable getAll(); +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java new file mode 100644 index 0000000000..240dc33571 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java @@ -0,0 +1,53 @@ +package com.baeldung.architecture.domain.task; + +import java.time.Instant; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Task { + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private Long id; + private Instant dueDate = Instant.now(); + private String description; + + public Task() {} + + public Task(Instant dueDate, String description) { + this.dueDate = dueDate; + this.description = description; + } + + public Task(Long id, Instant dueDate, String description) { + this(dueDate, description); + this.id = id; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Instant getDueDate() { + return dueDate; + } + + public void setDueDate(Instant dueDate) { + this.dueDate = dueDate; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java new file mode 100644 index 0000000000..d896212714 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java @@ -0,0 +1,7 @@ +package com.baeldung.architecture.domain.task; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface TaskRepository extends CrudRepository {}; diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java new file mode 100644 index 0000000000..cace0614ad --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java @@ -0,0 +1,22 @@ +package com.baeldung.architecture.domain.task; + +import org.springframework.stereotype.Service; + +@Service +public class TaskService { + + private TaskRepository taskRepository; + + public TaskService(TaskRepository taskRepository) { + this.taskRepository = taskRepository; + } + + public void createTask(Task task) { + taskRepository.save(task); + } + + public Iterable getAllTasks() { + return taskRepository.findAll(); + } + +}; diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java new file mode 100644 index 0000000000..260c033b71 --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java @@ -0,0 +1,25 @@ +package com.baeldung.architecture.framework.cli; + +import com.baeldung.architecture.application.task.AddNewDailyTask; +import com.baeldung.architecture.domain.task.Task; + +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.stereotype.Component; + +@Component +public class StartupRunner implements ApplicationRunner { + + AddNewDailyTask addNewDailyTask; + + public StartupRunner(AddNewDailyTask addNewDailyTask) { + this.addNewDailyTask = addNewDailyTask; + } + @Override + public void run(ApplicationArguments args) throws Exception { + System.out.println("Adding daily tasks"); + Task task = new Task(); + task.setDescription("Startup Task"); + addNewDailyTask.create(task); + } +} \ No newline at end of file diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java new file mode 100644 index 0000000000..c6f7bff2dd --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java @@ -0,0 +1,42 @@ +package com.baeldung.architecture.framework.http.task; + +import java.time.Instant; + +import com.baeldung.architecture.application.task.AddNewTask; +import com.baeldung.architecture.application.task.GetTasks; +import com.baeldung.architecture.domain.task.Task; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("task") +public class TaskApiController { + + private AddNewTask addNewTask; + private GetTasks getTasks; + + public TaskApiController( + AddNewTask addNewTask, + GetTasks getTasks + ) { + this.addNewTask = addNewTask; + this.getTasks = getTasks; + } + + @GetMapping + Iterable listTasks() { + return getTasks.getAll(); + } + + @PostMapping(consumes = "application/json", produces = "application/json") + void createTask(@RequestBody TaskRequest taskRequest) { + Task task = new Task(); + task.setDescription(taskRequest.getDescription()); + task.setDueDate(Instant.parse(taskRequest.getDueDate())); + addNewTask.create(task); + } +} \ No newline at end of file diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java new file mode 100644 index 0000000000..2e353b079a --- /dev/null +++ b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java @@ -0,0 +1,29 @@ +package com.baeldung.architecture.framework.http.task; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +public class TaskRequest { + @JsonInclude(Include.NON_NULL) + private String description; + + @JsonInclude(Include.NON_NULL) + private String dueDate; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getDueDate() { + return dueDate; + } + + public void setDueDate(String dueDate) { + this.dueDate = dueDate; + } + +} \ No newline at end of file From 8ed374c4b073fe83d326401bee41dca828d7d1e7 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Tue, 1 Oct 2019 20:15:39 -0400 Subject: [PATCH 013/309] Fixup styling --- .../architecture/HexagonalArchitectureTaskApplication.java | 6 +++--- .../baeldung/architecture/application/task/AddNewTask.java | 2 +- .../baeldung/architecture/application/task/GetTasks.java | 2 +- .../baeldung/architecture/framework/cli/StartupRunner.java | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java index 83e4fc4c0b..69c6f4b276 100644 --- a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java +++ b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java @@ -5,8 +5,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class HexagonalArchitectureTaskApplication { - public static void main(String[] args) { - SpringApplication.run(HexagonalArchitectureTaskApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(HexagonalArchitectureTaskApplication.class, args); + } } diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java index 2e5aff4a53..70638378f9 100644 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java @@ -19,4 +19,4 @@ public class AddNewTask implements CreateTask { public void create(Task newTask) { taskService.createTask(newTask); } -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java index 54539290ba..c876f7de85 100644 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java @@ -19,4 +19,4 @@ public class GetTasks implements GetAllTasks { public Iterable getAll() { return taskService.getAllTasks(); } -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java index 260c033b71..cf38e5ee5e 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java @@ -17,7 +17,6 @@ public class StartupRunner implements ApplicationRunner { } @Override public void run(ApplicationArguments args) throws Exception { - System.out.println("Adding daily tasks"); Task task = new Task(); task.setDescription("Startup Task"); addNewDailyTask.create(task); From f830524b20cf2dde5a8667779c39ac07ad84e095 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Tue, 1 Oct 2019 20:15:39 -0400 Subject: [PATCH 014/309] Fixup styling --- .../architecture/application/task/AddNewDailyTask.java | 2 +- .../com/baeldung/architecture/commands/task/CreateTask.java | 2 +- .../com/baeldung/architecture/commands/task/GetAllTasks.java | 2 +- .../com/baeldung/architecture/domain/task/TaskService.java | 2 +- .../com/baeldung/architecture/framework/cli/StartupRunner.java | 2 +- .../architecture/framework/http/task/TaskApiController.java | 2 +- .../baeldung/architecture/framework/http/task/TaskRequest.java | 3 +-- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java index 208d1bfcc9..f9ee97542c 100644 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java +++ b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java @@ -26,4 +26,4 @@ public class AddNewDailyTask implements CreateTask { addNewTask.create(task); } } -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java index 26e6da10e2..ec60868a22 100644 --- a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java +++ b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java @@ -4,4 +4,4 @@ import com.baeldung.architecture.domain.task.Task; public interface CreateTask { public void create(Task newTask); -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java index d3c40db92f..c9aa1be5f8 100644 --- a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java +++ b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java @@ -4,4 +4,4 @@ import com.baeldung.architecture.domain.task.Task; public interface GetAllTasks { public Iterable getAll(); -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java index cace0614ad..11ef0f3e19 100644 --- a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java +++ b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java @@ -19,4 +19,4 @@ public class TaskService { return taskRepository.findAll(); } -}; +} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java index cf38e5ee5e..449bc9386e 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java @@ -21,4 +21,4 @@ public class StartupRunner implements ApplicationRunner { task.setDescription("Startup Task"); addNewDailyTask.create(task); } -} \ No newline at end of file +} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java index c6f7bff2dd..87a8f5fe4b 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java @@ -39,4 +39,4 @@ public class TaskApiController { task.setDueDate(Instant.parse(taskRequest.getDueDate())); addNewTask.create(task); } -} \ No newline at end of file +} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java index 2e353b079a..70b98a32f9 100644 --- a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java +++ b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java @@ -25,5 +25,4 @@ public class TaskRequest { public void setDueDate(String dueDate) { this.dueDate = dueDate; } - -} \ No newline at end of file +} From b4be5f28a1da02c3501d43c56b8c508daf900b59 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sun, 31 May 2020 03:00:18 +0530 Subject: [PATCH 015/309] Changing the Test class name from IntegrationUnitTest to IntegrationTest --- ...onUnitTest.java => MultipleCacheManagerIntegrationTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-caching/src/test/java/com/baeldung/multiplecachemanager/{MultipleCacheManagerIntegrationUnitTest.java => MultipleCacheManagerIntegrationTest.java} (97%) diff --git a/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java b/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java similarity index 97% rename from spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java rename to spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java index e02e5da246..c83d4f9e96 100644 --- a/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java +++ b/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java @@ -17,7 +17,7 @@ import com.baeldung.multiplecachemanager.repository.OrderDetailRepository; @SpringBootApplication @SpringBootTest -public class MultipleCacheManagerIntegrationUnitTest { +public class MultipleCacheManagerIntegrationTest { @MockBean private OrderDetailRepository orderDetailRepository; From 333dad149fcaec6fe36f64d0375d4b00f9029828 Mon Sep 17 00:00:00 2001 From: marcodenisi Date: Thu, 18 Jun 2020 17:49:10 +0200 Subject: [PATCH 016/309] BAEL-4083 - sample spring boot app with xml config and properties --- spring-boot-modules/pom.xml | 1 + spring-boot-modules/spring-boot-xml/pom.xml | 32 +++++++++++++++++++ .../java/com/baeldung/springbootxml/Pojo.java | 17 ++++++++++ .../SpringBootXmlApplication.java | 25 +++++++++++++++ .../SpringBootXmlWithConfigApplication.java | 23 +++++++++++++ .../src/main/resources/application.properties | 1 + .../src/main/resources/beans.xml | 13 ++++++++ .../src/main/resources/beansconf.xml | 15 +++++++++ 8 files changed, 127 insertions(+) create mode 100644 spring-boot-modules/spring-boot-xml/pom.xml create mode 100644 spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/Pojo.java create mode 100644 spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java create mode 100644 spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java create mode 100644 spring-boot-modules/spring-boot-xml/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml create mode 100644 spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 7992c0ce12..8ef3d34056 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -57,6 +57,7 @@ spring-boot-springdoc spring-boot-testing spring-boot-vue + spring-boot-xml diff --git a/spring-boot-modules/spring-boot-xml/pom.xml b/spring-boot-modules/spring-boot-xml/pom.xml new file mode 100644 index 0000000000..dd575ff414 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/pom.xml @@ -0,0 +1,32 @@ + + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + 4.0.0 + + spring-boot-xml + + + + org.springframework.boot + spring-boot-starter + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/Pojo.java b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/Pojo.java new file mode 100644 index 0000000000..8c8b47ed40 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/Pojo.java @@ -0,0 +1,17 @@ +package com.baeldung.springbootxml; + +public class Pojo { + + private String field; + + public Pojo() { + } + + public String getField() { + return field; + } + + public void setField(String field) { + this.field = field; + } +} diff --git a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java new file mode 100644 index 0000000000..1a0350fd26 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java @@ -0,0 +1,25 @@ +package com.baeldung.springbootxml; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + +@Configuration +@EnableAutoConfiguration +@ImportResource("classpath:beans.xml") +public class SpringBootXmlApplication implements CommandLineRunner { + + @Autowired private Pojo pojo; + + public static void main(String[] args) { + SpringApplication.run(SpringBootXmlApplication.class, args); + } + + public void run(String... args) { + System.out.println(pojo.getField()); + } + +} diff --git a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java new file mode 100644 index 0000000000..7c36ac7905 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java @@ -0,0 +1,23 @@ +package com.baeldung.springbootxml; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; + +@Configuration +@ImportResource("classpath:beansconf.xml") +public class SpringBootXmlWithConfigApplication implements CommandLineRunner { + + @Autowired private Pojo pojo; + + public static void main(String[] args) { + SpringApplication.run(SpringBootXmlWithConfigApplication.class, args); + } + + @Override + public void run(String... args) throws Exception { + System.out.println(pojo.getField()); + } +} diff --git a/spring-boot-modules/spring-boot-xml/src/main/resources/application.properties b/spring-boot-modules/spring-boot-xml/src/main/resources/application.properties new file mode 100644 index 0000000000..ab9de92c82 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/resources/application.properties @@ -0,0 +1 @@ +sample=string loaded from properties! \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml b/spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml new file mode 100644 index 0000000000..9dac0d9e65 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml b/spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml new file mode 100644 index 0000000000..7f328370a8 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file From 3cb402ced71073a70875cc770e2abc47b0e9ef5e Mon Sep 17 00:00:00 2001 From: marcodenisi Date: Thu, 18 Jun 2020 17:58:25 +0200 Subject: [PATCH 017/309] BAEL-4083 - removed sample with xml context-config --- .../SpringBootXmlApplication.java | 6 ++--- .../SpringBootXmlWithConfigApplication.java | 23 ------------------- .../src/main/resources/beansconf.xml | 15 ------------ 3 files changed, 2 insertions(+), 42 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java delete mode 100644 spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml diff --git a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java index 1a0350fd26..bd75a95d7d 100644 --- a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java +++ b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java @@ -3,12 +3,10 @@ package com.baeldung.springbootxml; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ImportResource; -@Configuration -@EnableAutoConfiguration +@SpringBootApplication @ImportResource("classpath:beans.xml") public class SpringBootXmlApplication implements CommandLineRunner { diff --git a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java deleted file mode 100644 index 7c36ac7905..0000000000 --- a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlWithConfigApplication.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.springbootxml; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; - -@Configuration -@ImportResource("classpath:beansconf.xml") -public class SpringBootXmlWithConfigApplication implements CommandLineRunner { - - @Autowired private Pojo pojo; - - public static void main(String[] args) { - SpringApplication.run(SpringBootXmlWithConfigApplication.class, args); - } - - @Override - public void run(String... args) throws Exception { - System.out.println(pojo.getField()); - } -} diff --git a/spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml b/spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml deleted file mode 100644 index 7f328370a8..0000000000 --- a/spring-boot-modules/spring-boot-xml/src/main/resources/beansconf.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - \ No newline at end of file From eaf59355892d58c92d04354d4a77c28d91b45a9f Mon Sep 17 00:00:00 2001 From: marcodenisi Date: Thu, 18 Jun 2020 22:41:36 +0200 Subject: [PATCH 018/309] add slfj logger --- .../springbootxml/SpringBootXmlApplication.java | 12 +++++++++--- .../spring-boot-xml/src/main/resources/beans.xml | 12 +++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java index bd75a95d7d..addf24c427 100644 --- a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java +++ b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplication.java @@ -1,15 +1,21 @@ package com.baeldung.springbootxml; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; -@SpringBootApplication +@Configuration +@EnableAutoConfiguration @ImportResource("classpath:beans.xml") public class SpringBootXmlApplication implements CommandLineRunner { + private static final Logger logger = LoggerFactory.getLogger(SpringBootXmlApplication.class); + @Autowired private Pojo pojo; public static void main(String[] args) { @@ -17,7 +23,7 @@ public class SpringBootXmlApplication implements CommandLineRunner { } public void run(String... args) { - System.out.println(pojo.getField()); + logger.info(pojo.getField()); } } diff --git a/spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml b/spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml index 9dac0d9e65..200afecbc9 100644 --- a/spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml +++ b/spring-boot-modules/spring-boot-xml/src/main/resources/beans.xml @@ -1,11 +1,9 @@ - + From 1c61ba62abf38bd6c3962dc2a4a293baf4523a18 Mon Sep 17 00:00:00 2001 From: joe zhang Date: Fri, 19 Jun 2020 11:06:53 +0800 Subject: [PATCH 019/309] Leasy Zhang/shiwangzhihe@gmail.com --- .../convertlisttomap/ListToMapUnitTest.java | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java diff --git a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java new file mode 100644 index 0000000000..e2340a5a9a --- /dev/null +++ b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java @@ -0,0 +1,102 @@ +package com.baeldung.convertlisttomap; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +import org.junit.Test; + +public class ListToMapUnitTest { + + @Test + public void givenAList_whenConvertWithJava8GroupBy_thenReturnMap() { + List strings = Arrays.asList("List", "Map", "Set", "Tree"); + + Map> convertedMap = new HashMap<>(); + + Supplier> listSupplier = () -> { + return new ArrayList<>(); + }; + + Supplier>> mapFactory = () -> { + return new HashMap<>(); + }; + convertedMap = strings.stream() + .collect(Collectors.groupingBy(String::length, mapFactory, Collectors.toCollection(listSupplier))); + + assertEquals(2, convertedMap.size()); + assertTrue(convertedMap.get(3) + .contains("Map")); + } + + @Test + public void givenAList_whenConvertWithJava8Collect_thenReturnMap() { + List strings = Arrays.asList("List", "Map", "Set", "Tree"); + + Map> convertedMap = new HashMap<>(); + + Supplier>> mapFactory = () -> { + return new HashMap<>(); + }; + + Supplier> listSupplier = () -> { + return new ArrayList<>(); + }; + + BiConsumer>, String> accumulator = (response, element) -> { + Integer key = element.length(); + List values = response.getOrDefault(key, listSupplier.get()); + values.add(element); + response.put(key, values); + }; + + BiConsumer>, Map>> combiner = (res1, res2) -> { + res1.putAll(res2); + }; + + convertedMap = strings.stream() + .collect(mapFactory, accumulator, combiner); + + assertEquals(2, convertedMap.size()); + assertTrue(convertedMap.get(3) + .contains("Map")); + } + + @Test + public void givenAList_whenConvertWithCollectorToMap_thenReturnMap() { + List strings = Arrays.asList("List", "Map", "Set", "Tree"); + + Map> convertedMap = new HashMap<>(); + + Supplier>> mapFactory = () -> { + return new HashMap<>(); + }; + + Supplier> listSupplier = () -> { + return new ArrayList<>(); + }; + + convertedMap = strings.stream() + .collect(Collectors.toMap(String::length, (p) -> { + List strs = listSupplier.get(); + strs.add(p); + return strs; + }, (existing, replacement) -> { + existing.addAll(replacement); + return existing; + }, mapFactory)); + + assertEquals(2, convertedMap.size()); + assertTrue(convertedMap.get(3) + .contains("Map")); + } + +} From e8d8dd085f0b215f5680b20ab9b3a77547c23960 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sun, 21 Jun 2020 02:13:35 +0530 Subject: [PATCH 020/309] Fixing UT failure in build --- spring-caching/src/main/resources/schema.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-caching/src/main/resources/schema.sql b/spring-caching/src/main/resources/schema.sql index 5862499bc0..7d5cb36d66 100644 --- a/spring-caching/src/main/resources/schema.sql +++ b/spring-caching/src/main/resources/schema.sql @@ -1,3 +1,6 @@ +DROP TABLE ORDERDETAIL IF EXISTS; +DROP TABLE ITEM IF EXISTS; +DROP TABLE CUSTOMER IF EXISTS; CREATE TABLE CUSTOMER( CUSTOMERID INT PRIMARY KEY, CUSTOMERNAME VARCHAR(250) NOT NULL From 57dcc48b92144a6810453d754fa0f19f81090566 Mon Sep 17 00:00:00 2001 From: mdhtr Date: Mon, 22 Jun 2020 16:26:42 +0200 Subject: [PATCH 021/309] Examples for the first version of the article --- json-2/pom.xml | 60 +++++++++++++++++++ .../JacksonDeserializationExample.java | 40 +++++++++++++ .../jackson/JacksonExamplePerson.java | 19 ++++++ .../hydrajsonld/HydraJsonldExamplePerson.java | 15 +++++ .../HydraJsonldSerializationExample.java | 52 ++++++++++++++++ .../JacksonJsonLdSerializationExample.java | 25 ++++++++ .../JacksonJsonldExamplePerson.java | 17 ++++++ 7 files changed, 228 insertions(+) create mode 100644 json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationExample.java create mode 100644 json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonExamplePerson.java create mode 100644 json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldExamplePerson.java create mode 100644 json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationExample.java create mode 100644 json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationExample.java create mode 100644 json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonldExamplePerson.java diff --git a/json-2/pom.xml b/json-2/pom.xml index e0295af59b..73c26e8259 100644 --- a/json-2/pom.xml +++ b/json-2/pom.xml @@ -49,6 +49,66 @@ commons-lang3 3.9 + + + com.fasterxml.jackson.core + jackson-annotations + 2.11.0 + + + com.fasterxml.jackson.core + jackson-databind + 2.11.0 + + + com.io-informatics.oss + jackson-jsonld + 0.1.1 + + + jackson-databind + com.fasterxml.jackson.core + + + jackson-annotations + com.fasterxml.jackson.core + + + jackson-core + com.fasterxml.jackson.core + + + jsonld-java + com.github.jsonld-java + + + + + de.escalon.hypermedia + hydra-jsonld + 0.4.2 + + + jackson-databind + com.fasterxml.jackson.core + + + + + com.github.jsonld-java + jsonld-java + 0.13.0 + + + jackson-core + com.fasterxml.jackson.core + + + jackson-databind + com.fasterxml.jackson.core + + + 0.9.23 diff --git a/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationExample.java b/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationExample.java new file mode 100644 index 0000000000..b80769b408 --- /dev/null +++ b/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationExample.java @@ -0,0 +1,40 @@ +package com.baeldung.jsonld.deserialization.jsonldjava.jackson; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.jsonldjava.core.JsonLdOptions; +import com.github.jsonldjava.core.JsonLdProcessor; +import com.github.jsonldjava.utils.JsonUtils; + +public class JacksonDeserializationExample { + public static void main(String[] args) throws IOException { + String exampleJsonld ="{" + + " \"@context\": {" + + " \"@vocab\": \"http://schema.org/\"," + + " \"knows\": {" + + " \"@type\": \"@id\"" + + " }" + + " }," + + " \"@type\": \"Person\"," + + " \"@id\": \"http://example.com/person/1234\"," + + " \"name\": \"Example Name\"," + + " \"knows\": \"http://example.com/person/2345\"" + + "}"; + + Object jsonObject = JsonUtils.fromString(exampleJsonld); + Object compact = JsonLdProcessor.compact(jsonObject, new HashMap(), new JsonLdOptions()); + String compactContent = JsonUtils.toString(compact); + + System.out.println(JsonUtils.toPrettyString(compact)); + + ObjectMapper objectMapper = new ObjectMapper(); + JacksonExamplePerson person = objectMapper.readValue(compactContent, JacksonExamplePerson.class); + + System.out.println(person.id); + System.out.println(person.name); + System.out.println(person.knows.id); + } +} diff --git a/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonExamplePerson.java b/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonExamplePerson.java new file mode 100644 index 0000000000..2e9f38e665 --- /dev/null +++ b/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonExamplePerson.java @@ -0,0 +1,19 @@ +package com.baeldung.jsonld.deserialization.jsonldjava.jackson; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class JacksonExamplePerson { + @JsonProperty("@id") + public String id; + @JsonProperty("http://schema.org/name") + public String name; + @JsonProperty("http://schema.org/knows") + public Link knows; + + public class Link { + @JsonProperty("@id") + public String id; + } +} diff --git a/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldExamplePerson.java b/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldExamplePerson.java new file mode 100644 index 0000000000..16b2199a73 --- /dev/null +++ b/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldExamplePerson.java @@ -0,0 +1,15 @@ +package com.baeldung.jsonld.serialization.hydrajsonld; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import de.escalon.hypermedia.hydra.mapping.Expose; +import de.escalon.hypermedia.hydra.mapping.Vocab; + +@Vocab("http://example.com/vocab/") +@Expose("person") +public class HydraJsonldExamplePerson { + @JsonProperty("@id") + public String id; + @Expose("fullName") + public String name; +} diff --git a/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationExample.java b/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationExample.java new file mode 100644 index 0000000000..3d3531b0b5 --- /dev/null +++ b/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationExample.java @@ -0,0 +1,52 @@ +package com.baeldung.jsonld.serialization.hydrajsonld; + +import java.io.IOException; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.BeanDescription; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationConfig; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.BeanSerializerModifier; +import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; + +import de.escalon.hypermedia.hydra.serialize.JacksonHydraSerializer; + +public class HydraJsonldSerializationExample { + public static void main(String[] args) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + mapper.registerModule(getJacksonHydraSerializerModule()); + + HydraJsonldExamplePerson person = new HydraJsonldExamplePerson(); + person.id = "http://example.com/person/1234"; + person.name = "Example Name"; + + System.out.println(mapper.writerWithDefaultPrettyPrinter() + .writeValueAsString(person)); + } + + public static SimpleModule getJacksonHydraSerializerModule() { + return new SimpleModule() { + + @Override + public void setupModule(SetupContext context) { + super.setupModule(context); + + context.addBeanSerializerModifier(new BeanSerializerModifier() { + + @Override + public JsonSerializer modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer serializer) { + + if (serializer instanceof BeanSerializerBase) { + return new JacksonHydraSerializer((BeanSerializerBase) serializer); + } else { + return serializer; + } + } + }); + } + }; + } +} diff --git a/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationExample.java b/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationExample.java new file mode 100644 index 0000000000..6a1acee1b8 --- /dev/null +++ b/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationExample.java @@ -0,0 +1,25 @@ +package com.baeldung.jsonld.serialization.jacksonjsonld; + +import java.io.IOException; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import ioinformarics.oss.jackson.module.jsonld.HydraCollection; +import ioinformarics.oss.jackson.module.jsonld.JsonldGraph; +import ioinformarics.oss.jackson.module.jsonld.JsonldModule; +import ioinformarics.oss.jackson.module.jsonld.JsonldResource; + +public class JacksonJsonLdSerializationExample { + public static void main(String[] args) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JsonldModule()); + + JacksonJsonldExamplePerson person = new JacksonJsonldExamplePerson(); + + JsonldResource jsonldResource = JsonldResource.Builder.create() + .build(person); + + System.out.println(objectMapper.writerWithDefaultPrettyPrinter() + .writeValueAsString(jsonldResource)); + } +} diff --git a/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonldExamplePerson.java b/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonldExamplePerson.java new file mode 100644 index 0000000000..a3161ba1d3 --- /dev/null +++ b/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonldExamplePerson.java @@ -0,0 +1,17 @@ +package com.baeldung.jsonld.serialization.jacksonjsonld; + +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldId; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldLink; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldNamespace; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldProperty; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldType; + +@JsonldNamespace(name = "s", uri = "http://schema.org/") +@JsonldLink(rel = "s:knows", name = "knows", href = "http://example.com/person/2345") +@JsonldType("s:Person") +class JacksonJsonldExamplePerson { + @JsonldId + public String id = "http://example.com/person/1234"; + @JsonldProperty("s:name") + public String name = "Example Name"; +} From c5f8489f1d347ea83939cba014dc3f857810a5b1 Mon Sep 17 00:00:00 2001 From: Marco Denisi Date: Sun, 28 Jun 2020 10:15:48 +0200 Subject: [PATCH 022/309] BAEL-4083 - add app integration test --- spring-boot-modules/spring-boot-xml/pom.xml | 8 ++++++ ...ringBootXmlApplicationIntegrationTest.java | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplicationIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-xml/pom.xml b/spring-boot-modules/spring-boot-xml/pom.xml index dd575ff414..e1ddd8f437 100644 --- a/spring-boot-modules/spring-boot-xml/pom.xml +++ b/spring-boot-modules/spring-boot-xml/pom.xml @@ -18,6 +18,14 @@ org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-starter-test + + + junit + junit + diff --git a/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplicationIntegrationTest.java b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplicationIntegrationTest.java new file mode 100644 index 0000000000..2c3993d0d8 --- /dev/null +++ b/spring-boot-modules/spring-boot-xml/src/main/java/com/baeldung/springbootxml/SpringBootXmlApplicationIntegrationTest.java @@ -0,0 +1,26 @@ +package com.baeldung.springbootxml; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SpringBootXmlApplication.class) +public class SpringBootXmlApplicationIntegrationTest { + + @Autowired private Pojo pojo; + @Value("${sample}") private String sample; + + @Test + public void whenCallingGetter_thenPrintingProperty() { + assertThat(pojo.getField()) + .isNotBlank() + .isEqualTo(sample); + } + +} \ No newline at end of file From 67e9dc8187222f9746889f090cef492425ab1fce Mon Sep 17 00:00:00 2001 From: STS Date: Sun, 28 Jun 2020 20:33:10 +0200 Subject: [PATCH 023/309] add excel formula --- excelformula/.gitignore | 34 +++++++++++ excelformula/pom.xml | 57 +++++++++++++++++++ .../poi/excelformula/ExcelFormula.java | 36 ++++++++++++ .../excelformula/ExcelformulaApplication.java | 13 +++++ .../src/main/resources/application.properties | 1 + .../ExcelformulaApplicationTests.java | 38 +++++++++++++ 6 files changed, 179 insertions(+) create mode 100644 excelformula/.gitignore create mode 100644 excelformula/pom.xml create mode 100644 excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java create mode 100644 excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java create mode 100644 excelformula/src/main/resources/application.properties create mode 100644 excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java diff --git a/excelformula/.gitignore b/excelformula/.gitignore new file mode 100644 index 0000000000..719e322c1d --- /dev/null +++ b/excelformula/.gitignore @@ -0,0 +1,34 @@ +HELP.md +mvnw +mvnw.cmd +.mvn +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ diff --git a/excelformula/pom.xml b/excelformula/pom.xml new file mode 100644 index 0000000000..4ea65b5e57 --- /dev/null +++ b/excelformula/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.1.RELEASE + + + com.bealdung.poi + excelformula + 0.0.1-SNAPSHOT + excelformula + Demo project for Spring Boot + + 11 + 4.1.2 + 4.13 + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.apache.poi + poi-ooxml + ${poi-ooxml.version} + + + junit + junit + ${junit.version} + test + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java b/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java new file mode 100644 index 0000000000..1e2fa5acfe --- /dev/null +++ b/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java @@ -0,0 +1,36 @@ +package com.bealdung.poi.excelformula; + +import org.apache.poi.ss.usermodel.CellValue; +import org.apache.poi.xssf.usermodel.XSSFCell; +import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.util.List; + +@Component +public class ExcelFormula { + XSSFWorkbook excel; + public XSSFSheet inserData(List dataList) { + excel = new XSSFWorkbook(); + XSSFSheet sheet = excel.createSheet(); + int rowNum =0 ; + for (Integer data : dataList){ + sheet.createRow(rowNum++).createCell(0).setCellValue(data); + } + return sheet; + } + public double setFormula(String formula) throws IOException { + XSSFSheet sheet = excel.getSheetAt(0); + int lastCellNum = sheet.getRow(0).getLastCellNum(); + XSSFCell formulaCell = sheet.getRow(0).createCell(lastCellNum + 1); + formulaCell.setCellFormula(formula); + XSSFFormulaEvaluator formulaEvaluator = excel.getCreationHelper().createFormulaEvaluator(); + CellValue evaluate = formulaEvaluator.evaluate(formulaCell); + if(excel != null) + excel.close(); + return evaluate.getNumberValue(); + } +} diff --git a/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java b/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java new file mode 100644 index 0000000000..b857bd4266 --- /dev/null +++ b/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java @@ -0,0 +1,13 @@ +package com.bealdung.poi.excelformula; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ExcelformulaApplication { + + public static void main(String[] args) { + SpringApplication.run(ExcelformulaApplication.class, args); + } + +} diff --git a/excelformula/src/main/resources/application.properties b/excelformula/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/excelformula/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java b/excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java new file mode 100644 index 0000000000..c2385911d0 --- /dev/null +++ b/excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java @@ -0,0 +1,38 @@ +package com.bealdung.poi.excelformula; + +import org.apache.poi.ss.util.CellReference; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.junit.Assert; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest +class ExcelformulaApplicationTests { + @Autowired + private ExcelFormula excelFormula; + + @Test + void givenExcelData_whenSetAndEvaluateFormula() throws IOException { + List data = Arrays.asList(2, 5, 10, 15, 7, 9); + XSSFSheet sheet = excelFormula.inserData(data); + int result = 0; + for (int row = 0; row <= sheet.getLastRowNum(); row++) { + result += sheet.getRow(row).getCell(0).getNumericCellValue(); + } + String colName = CellReference.convertNumToColString(0); + String startCell = colName + 1; + String stopCell = colName + (sheet.getLastRowNum() + 1); + String sumFormula = String.format("SUM(%s:%s)", startCell, stopCell); + int resultValue = (int) excelFormula.setFormula(sumFormula); + Assert.assertEquals("The results are the same!", resultValue , result); + } + +} From ecde6b58a83eb964a66e3cf5e9ebef7428018e05 Mon Sep 17 00:00:00 2001 From: STS Date: Sun, 28 Jun 2020 21:12:09 +0200 Subject: [PATCH 024/309] create README.md file --- excelformula/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 excelformula/README.md diff --git a/excelformula/README.md b/excelformula/README.md new file mode 100644 index 0000000000..86ddaba413 --- /dev/null +++ b/excelformula/README.md @@ -0,0 +1,8 @@ +## Apache POI + +This module contains articles about Apache POI + +### Relevant Articles: +- [Working with Microsoft Excel in Java](https://www.baeldung.com/java-microsoft-excel) +- [Read Excel Cell Value Rather Than Formula With Apache POI](https://www.baeldung.com/apache-poi-read-cell-value-formula) +- [Upload and Display Excel Files with Spring MVC](https://www.baeldung.com/spring-mvc-excel-files) From 2d37d4ce87d6c279d6a5ec0f662efa04df82161f Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Mon, 29 Jun 2020 12:05:57 +0200 Subject: [PATCH 025/309] BAEL-4198 - Fix Selenium Live Tests --- testing-modules/selenium-junit-testng/pom.xml | 37 +++++-------- .../baeldung/selenium/SeleniumExample.java | 53 +++++++++++-------- .../selenium/config/SeleniumConfig.java | 22 ++++---- .../selenium/models/BaeldungAbout.java | 6 +-- .../selenium/pages/BaeldungAboutPage.java | 2 +- .../selenium/pages/BaeldungHomePage.java | 6 +-- .../selenium/pages/StartHerePage.java | 4 +- ...a => SeleniumJavaScriptClickLiveTest.java} | 22 ++++---- .../SeleniumCookiesJUnitLiveTest.java | 32 ++++++++--- .../junit/SeleniumWithJUnitLiveTest.java | 25 +++++---- .../SeleniumPageObjectLiveTest.java | 10 ++-- .../testng/SeleniumWithTestNGLiveTest.java | 13 +++-- 12 files changed, 129 insertions(+), 103 deletions(-) rename testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/{SeleniumJavaScriptClickTest.java => SeleniumJavaScriptClickLiveTest.java} (74%) rename testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/{junit => cookies}/SeleniumCookiesJUnitLiveTest.java (80%) rename testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/{junit => pages}/SeleniumPageObjectLiveTest.java (79%) diff --git a/testing-modules/selenium-junit-testng/pom.xml b/testing-modules/selenium-junit-testng/pom.xml index 3734bf72c9..44af047bdd 100644 --- a/testing-modules/selenium-junit-testng/pom.xml +++ b/testing-modules/selenium-junit-testng/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 selenium-junit-testng 0.0.1-SNAPSHOT @@ -43,32 +44,22 @@ - src + + + src/main/resources + true + + + src/test/resources + true + + - - - live - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - **/*LiveTest.java - - - - - - - - 6.10 3.4.0 + 1.5.4 diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java index c5ad5182ff..b32e51d250 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/SeleniumExample.java @@ -1,14 +1,12 @@ -package main.java.com.baeldung.selenium; - -import main.java.com.baeldung.selenium.config.SeleniumConfig; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.interactions.Actions; +package com.baeldung.selenium; import java.util.List; -import java.util.concurrent.TimeUnit; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.baeldung.selenium.config.SeleniumConfig; public class SeleniumExample { @@ -17,15 +15,18 @@ public class SeleniumExample { public SeleniumExample() { config = new SeleniumConfig(); - config.getDriver().get(url); + config.getDriver() + .get(url); } public void closeWindow() { - this.config.getDriver().close(); + this.config.getDriver() + .close(); } public String getTitle() { - return this.config.getDriver().getTitle(); + return this.config.getDriver() + .getTitle(); } public void getAboutBaeldungPage() { @@ -35,29 +36,35 @@ public class SeleniumExample { } private void closeOverlay() { - List webElementList = this.config.getDriver().findElements(By.tagName("a")); + List webElementList = this.config.getDriver() + .findElements(By.tagName("a")); if (webElementList != null) { webElementList.stream() - .filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))) - .filter(WebElement::isDisplayed) - .findAny() - .ifPresent(WebElement::click); + .filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))) + .filter(WebElement::isDisplayed) + .findAny() + .ifPresent(WebElement::click); } } private void clickAboutLink() { - this.config.getDriver().findElement(By.partialLinkText("About")).click(); + Actions actions = new Actions(config.getDriver()); + WebElement aboutElement = this.config.getDriver() + .findElement(By.id("menu-item-6138")); + + actions.moveToElement(aboutElement).perform(); } private void clickAboutUsLink() { - Actions builder = new Actions(config.getDriver()); - WebElement element = this.config.getDriver().findElement(By.partialLinkText("About Baeldung.")); - builder.moveToElement(element).build().perform(); + WebElement element = this.config.getDriver() + .findElement(By.partialLinkText("About Baeldung.")); + element.click(); } public boolean isAuthorInformationAvailable() { return this.config.getDriver() - .findElement(By.cssSelector("article > .row > div")) - .isDisplayed(); + .getPageSource() + .contains("Hey ! I'm Eugen"); } + } diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/config/SeleniumConfig.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/config/SeleniumConfig.java index c84283b76b..b1b7754648 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/config/SeleniumConfig.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/config/SeleniumConfig.java @@ -1,17 +1,14 @@ -package main.java.com.baeldung.selenium.config; +package com.baeldung.selenium.config; + +import java.io.File; +import java.util.concurrent.TimeUnit; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.DesiredCapabilities; -import java.io.File; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public class SeleniumConfig { private WebDriver driver; @@ -19,15 +16,17 @@ public class SeleniumConfig { public SeleniumConfig() { Capabilities capabilities = DesiredCapabilities.firefox(); driver = new FirefoxDriver(capabilities); - driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); + driver.manage() + .timeouts() + .implicitlyWait(5, TimeUnit.SECONDS); } static { System.setProperty("webdriver.gecko.driver", findFile("geckodriver.mac")); } - static private String findFile(String filename) { - String paths[] = {"", "bin/", "target/classes"}; // if you have chromedriver somewhere else on the path, then put it here. + private static String findFile(String filename) { + String[] paths = { "", "bin/", "target/classes" }; // if you have chromedriver somewhere else on the path, then put it here. for (String path : paths) { if (new File(path + filename).exists()) return path + filename; @@ -40,7 +39,8 @@ public class SeleniumConfig { } public void navigateTo(String url) { - driver.navigate().to(url); + driver.navigate() + .to(url); } public void clickElement(WebElement element) { diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/models/BaeldungAbout.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/models/BaeldungAbout.java index 838beb5326..580cbd1f2b 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/models/BaeldungAbout.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/models/BaeldungAbout.java @@ -1,7 +1,7 @@ -package main.java.com.baeldung.selenium.models; +package com.baeldung.selenium.models; -import main.java.com.baeldung.selenium.config.SeleniumConfig; -import main.java.com.baeldung.selenium.pages.BaeldungAboutPage; +import com.baeldung.selenium.config.SeleniumConfig; +import com.baeldung.selenium.pages.BaeldungAboutPage; import org.openqa.selenium.support.PageFactory; public class BaeldungAbout { diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungAboutPage.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungAboutPage.java index d33cb76398..064462fc10 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungAboutPage.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungAboutPage.java @@ -1,4 +1,4 @@ -package main.java.com.baeldung.selenium.pages; +package com.baeldung.selenium.pages; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungHomePage.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungHomePage.java index 55a8044375..d901bf3c34 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungHomePage.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/BaeldungHomePage.java @@ -1,6 +1,6 @@ -package main.java.com.baeldung.selenium.pages; +package com.baeldung.selenium.pages; -import main.java.com.baeldung.selenium.config.SeleniumConfig; +import com.baeldung.selenium.config.SeleniumConfig; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; @@ -8,7 +8,7 @@ import org.openqa.selenium.support.PageFactory; public class BaeldungHomePage { private SeleniumConfig config; - @FindBy(css=".header--menu > a") + @FindBy(css = ".nav--logo_mobile") private WebElement title; @FindBy(css = ".menu-start-here > a") private WebElement startHere; diff --git a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/StartHerePage.java b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/StartHerePage.java index 4f0ee9edcd..ccc166c351 100644 --- a/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/StartHerePage.java +++ b/testing-modules/selenium-junit-testng/src/main/java/com/baeldung/selenium/pages/StartHerePage.java @@ -1,6 +1,6 @@ -package main.java.com.baeldung.selenium.pages; +package com.baeldung.selenium.pages; -import main.java.com.baeldung.selenium.config.SeleniumConfig; +import com.baeldung.selenium.config.SeleniumConfig; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickLiveTest.java similarity index 74% rename from testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickTest.java rename to testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickLiveTest.java index 6d2ab8ef1f..de519a44fc 100644 --- a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickTest.java +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/clickusingjavascript/SeleniumJavaScriptClickLiveTest.java @@ -1,4 +1,4 @@ -package java.com.baeldung.selenium.clickusingjavascript; +package com.baeldung.selenium.clickusingjavascript; import org.junit.After; import org.junit.Before; @@ -14,16 +14,18 @@ import org.openqa.selenium.support.ui.WebDriverWait; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class SeleniumJavaScriptClickTest { +import java.io.File; + +public class SeleniumJavaScriptClickLiveTest { private WebDriver driver; private WebDriverWait wait; @Before public void setUp() { - System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); + System.setProperty("webdriver.chrome.driver", new File("src/main/resources/chromedriver.mac").getAbsolutePath()); driver = new ChromeDriver(); - wait = new WebDriverWait(driver, 5000); + wait = new WebDriverWait(driver, 20); } @After @@ -37,19 +39,21 @@ public class SeleniumJavaScriptClickTest { String title = driver.getTitle(); assertEquals("Baeldung | Java, Spring and Web Development tutorials", title); - wait.until(ExpectedConditions.elementToBeClickable(By.className("menu-search"))); - WebElement searchButton = driver.findElement(By.className("menu-search")); + wait.until(ExpectedConditions.elementToBeClickable(By.className("nav--menu_item_anchor"))); + WebElement searchButton = driver.findElement(By.className("nav--menu_item_anchor")); clickElement(searchButton); wait.until(ExpectedConditions.elementToBeClickable(By.id("search"))); WebElement searchInput = driver.findElement(By.id("search")); searchInput.sendKeys("Selenium"); - wait.until(ExpectedConditions.elementToBeClickable(By.className("btn-search"))); - WebElement seeSearchResultsButton = driver.findElement(By.className("btn-search")); + wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".btn-search"))); + WebElement seeSearchResultsButton = driver.findElement(By.cssSelector(".btn-search")); clickElement(seeSearchResultsButton); - int seleniumPostsCount = driver.findElements(By.className("post")).size(); + wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("post"))); + int seleniumPostsCount = driver.findElements(By.className("post")) + .size(); assertTrue(seleniumPostsCount > 0); } diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumCookiesJUnitLiveTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/cookies/SeleniumCookiesJUnitLiveTest.java similarity index 80% rename from testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumCookiesJUnitLiveTest.java rename to testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/cookies/SeleniumCookiesJUnitLiveTest.java index 0cbbf52454..337e3b85fb 100644 --- a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumCookiesJUnitLiveTest.java +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/cookies/SeleniumCookiesJUnitLiveTest.java @@ -1,4 +1,16 @@ -package test.java.com.baeldung.selenium.junit; +package com.baeldung.selenium.cookies; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; + +import java.io.File; +import java.util.Set; +import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; @@ -9,12 +21,6 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.DesiredCapabilities; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; - public class SeleniumCookiesJUnitLiveTest { private WebDriver driver; @@ -22,11 +28,21 @@ public class SeleniumCookiesJUnitLiveTest { @Before public void setUp() { + System.setProperty("webdriver.gecko.driver", findFile("geckodriver.mac")); + Capabilities capabilities = DesiredCapabilities.firefox(); driver = new FirefoxDriver(capabilities); navUrl = "https://baeldung.com"; driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); - System.setProperty("webdriver.gecko.driver", "geckodriver.exe"); + } + + private static String findFile(String filename) { + String[] paths = { "", "bin/", "target/classes" }; // if you have chromedriver somewhere else on the path, then put it here. + for (String path : paths) { + if (new File(path + filename).exists()) + return path + filename; + } + return ""; } @After diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java index b1a4149358..1b1035cc6c 100644 --- a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumWithJUnitLiveTest.java @@ -1,16 +1,21 @@ -package test.java.com.baeldung.selenium.junit; +package com.baeldung.selenium.junit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; -import main.java.com.baeldung.selenium.SeleniumExample; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import static org.testng.Assert.*; +import com.baeldung.selenium.SeleniumExample; public class SeleniumWithJUnitLiveTest { private static SeleniumExample seleniumExample; - private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials"; + private String expectedTitle = "About Baeldung | Baeldung"; @BeforeClass public static void setUp() { @@ -18,17 +23,17 @@ public class SeleniumWithJUnitLiveTest { } @AfterClass - public static void tearDown() { + public static void tearDown() throws IOException { seleniumExample.closeWindow(); } @Test public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() { - seleniumExample.getAboutBaeldungPage(); - String actualTitle = seleniumExample.getTitle(); - assertNotNull(actualTitle); - assertEquals(expectedTitle, actualTitle); - assertTrue(seleniumExample.isAuthorInformationAvailable()); + seleniumExample.getAboutBaeldungPage(); + String actualTitle = seleniumExample.getTitle(); + assertNotNull(actualTitle); + assertEquals(expectedTitle, actualTitle); + assertTrue(seleniumExample.isAuthorInformationAvailable()); } } diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumPageObjectLiveTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/pages/SeleniumPageObjectLiveTest.java similarity index 79% rename from testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumPageObjectLiveTest.java rename to testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/pages/SeleniumPageObjectLiveTest.java index 8493122414..96772821a9 100644 --- a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/junit/SeleniumPageObjectLiveTest.java +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/pages/SeleniumPageObjectLiveTest.java @@ -1,9 +1,9 @@ -package test.java.com.baeldung.selenium.junit; +package com.baeldung.selenium.pages; -import main.java.com.baeldung.selenium.config.SeleniumConfig; -import main.java.com.baeldung.selenium.models.BaeldungAbout; -import main.java.com.baeldung.selenium.pages.BaeldungHomePage; -import main.java.com.baeldung.selenium.pages.StartHerePage; +import com.baeldung.selenium.config.SeleniumConfig; +import com.baeldung.selenium.models.BaeldungAbout; +import com.baeldung.selenium.pages.BaeldungHomePage; +import com.baeldung.selenium.pages.StartHerePage; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java index 94426edc6d..85fa00c0ab 100644 --- a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/testng/SeleniumWithTestNGLiveTest.java @@ -1,16 +1,19 @@ -package test.java.com.baeldung.selenium.testng; +package com.baeldung.selenium.testng; + +import com.baeldung.selenium.SeleniumExample; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; -import main.java.com.baeldung.selenium.SeleniumExample; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; -import static org.testng.Assert.*; - public class SeleniumWithTestNGLiveTest { private SeleniumExample seleniumExample; - private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials"; + private String expectedTitle = "About Baeldung | Baeldung"; @BeforeSuite public void setUp() { From 12eb8523493e790d2cb232f902035e290fc0a097 Mon Sep 17 00:00:00 2001 From: STS Date: Mon, 29 Jun 2020 14:07:18 +0200 Subject: [PATCH 026/309] remove and add file --- {excelformula => apache-poi/excelformula}/.gitignore | 0 {excelformula => apache-poi/excelformula}/pom.xml | 0 .../src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java | 0 .../com/bealdung/poi/excelformula/ExcelformulaApplication.java | 0 .../excelformula}/src/main/resources/application.properties | 0 .../bealdung/poi/excelformula/ExcelformulaApplicationTests.java | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename {excelformula => apache-poi/excelformula}/.gitignore (100%) rename {excelformula => apache-poi/excelformula}/pom.xml (100%) rename {excelformula => apache-poi/excelformula}/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java (100%) rename {excelformula => apache-poi/excelformula}/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java (100%) rename {excelformula => apache-poi/excelformula}/src/main/resources/application.properties (100%) rename {excelformula => apache-poi/excelformula}/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java (100%) diff --git a/excelformula/.gitignore b/apache-poi/excelformula/.gitignore similarity index 100% rename from excelformula/.gitignore rename to apache-poi/excelformula/.gitignore diff --git a/excelformula/pom.xml b/apache-poi/excelformula/pom.xml similarity index 100% rename from excelformula/pom.xml rename to apache-poi/excelformula/pom.xml diff --git a/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java b/apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java similarity index 100% rename from excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java rename to apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java diff --git a/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java b/apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java similarity index 100% rename from excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java rename to apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java diff --git a/excelformula/src/main/resources/application.properties b/apache-poi/excelformula/src/main/resources/application.properties similarity index 100% rename from excelformula/src/main/resources/application.properties rename to apache-poi/excelformula/src/main/resources/application.properties diff --git a/excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java b/apache-poi/excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java similarity index 100% rename from excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java rename to apache-poi/excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java From 35e88cd1c57be5eb25da73f48e9c7e1b6f1cef36 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Mon, 29 Jun 2020 15:56:23 +0200 Subject: [PATCH 027/309] BAEL-4198 --- testing-modules/selenium-junit-testng/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/testing-modules/selenium-junit-testng/pom.xml b/testing-modules/selenium-junit-testng/pom.xml index 44af047bdd..210c2051da 100644 --- a/testing-modules/selenium-junit-testng/pom.xml +++ b/testing-modules/selenium-junit-testng/pom.xml @@ -59,7 +59,6 @@ 6.10 3.4.0 - 1.5.4 From 672ffdbe9f9fe6de186e38a4a7d28aa6e95378ee Mon Sep 17 00:00:00 2001 From: joe zhang Date: Mon, 29 Jun 2020 22:34:19 +0800 Subject: [PATCH 028/309] update unit test for collectors.toMap method --- .../convertlisttomap/ListToMapUnitTest.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java index e2340a5a9a..5a875a904e 100644 --- a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java +++ b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java @@ -9,6 +9,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -84,15 +86,23 @@ public class ListToMapUnitTest { return new ArrayList<>(); }; + Function keyMapper = (element) -> { + return element.length(); + }; + + Function> valueMapper = (element) -> { + List collection = listSupplier.get(); + collection.add(element); + return collection; + }; + + BinaryOperator> mergeFunction = (existing, replacement) -> { + existing.addAll(replacement); + return existing; + }; + convertedMap = strings.stream() - .collect(Collectors.toMap(String::length, (p) -> { - List strs = listSupplier.get(); - strs.add(p); - return strs; - }, (existing, replacement) -> { - existing.addAll(replacement); - return existing; - }, mapFactory)); + .collect(Collectors.toMap(keyMapper, valueMapper, mergeFunction, mapFactory)); assertEquals(2, convertedMap.size()); assertTrue(convertedMap.get(3) From a97a87735a6a95f98bb4b88dc750a577447a2e73 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Tue, 30 Jun 2020 15:24:38 +0200 Subject: [PATCH 029/309] BAEL-4024 - Taking Screenshots with Selenium WebDriver --- testing-modules/selenium-junit-testng/pom.xml | 6 ++ .../TakeScreenShotSeleniumLiveTest.java | 85 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/screenshot/TakeScreenShotSeleniumLiveTest.java diff --git a/testing-modules/selenium-junit-testng/pom.xml b/testing-modules/selenium-junit-testng/pom.xml index 210c2051da..8d661997f8 100644 --- a/testing-modules/selenium-junit-testng/pom.xml +++ b/testing-modules/selenium-junit-testng/pom.xml @@ -41,6 +41,11 @@ hamcrest-all ${hamcrest-all.version} + + ru.yandex.qatools.ashot + ashot + ${ashot.version} + @@ -59,6 +64,7 @@ 6.10 3.4.0 + 1.5.4 diff --git a/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/screenshot/TakeScreenShotSeleniumLiveTest.java b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/screenshot/TakeScreenShotSeleniumLiveTest.java new file mode 100644 index 0000000000..cf705bb81f --- /dev/null +++ b/testing-modules/selenium-junit-testng/src/test/java/com/baeldung/selenium/screenshot/TakeScreenShotSeleniumLiveTest.java @@ -0,0 +1,85 @@ +package com.baeldung.selenium.screenshot; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import javax.imageio.ImageIO; + +import org.apache.commons.io.FileUtils; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.remote.DesiredCapabilities; + +import ru.yandex.qatools.ashot.AShot; +import ru.yandex.qatools.ashot.Screenshot; +import ru.yandex.qatools.ashot.coordinates.WebDriverCoordsProvider; +import ru.yandex.qatools.ashot.shooting.ShootingStrategies; + +public class TakeScreenShotSeleniumLiveTest { + + private static ChromeDriver driver; + + @BeforeClass + public static void setUp() { + System.setProperty("webdriver.chrome.driver", resolveResourcePath("chromedriver.mac")); + + Capabilities capabilities = DesiredCapabilities.chrome(); + driver = new ChromeDriver(capabilities); + driver.manage() + .timeouts() + .implicitlyWait(5, TimeUnit.SECONDS); + + driver.get("http://www.google.com/"); + } + + @AfterClass + public static void tearDown() throws IOException { + driver.close(); + + System.clearProperty("webdriver.chrome.driver"); + } + + @Test + public void whenGoogleIsLoaded_thenCaptureScreenshot() throws IOException { + takeScreenshot(resolveTestResourcePath("google-home.png")); + + assertTrue(new File(resolveTestResourcePath("google-home.png")).exists()); + } + + @Test + public void whenGoogleIsLoaded_thenCaptureLogo() throws IOException { + WebElement logo = driver.findElement(By.id("hplogo")); + + Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)) + .coordsProvider(new WebDriverCoordsProvider()) + .takeScreenshot(driver, logo); + + ImageIO.write(screenshot.getImage(), "jpg", new File(resolveTestResourcePath("google-logo.png"))); + assertTrue(new File(resolveTestResourcePath("google-logo.png")).exists()); + } + + public void takeScreenshot(String pathname) throws IOException { + File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); + FileUtils.copyFile(src, new File(pathname)); + } + + private static String resolveResourcePath(String filename) { + File file = new File("src/main/resources/" + filename); + return file.getAbsolutePath(); + } + + private static String resolveTestResourcePath(String filename) { + File file = new File("src/test/resources/" + filename); + return file.getAbsolutePath(); + } +} From d1a9ff7480f8f21543c02d61992d0dd20fa4e56d Mon Sep 17 00:00:00 2001 From: Joao Esperancinha Date: Tue, 30 Jun 2020 15:52:17 +0200 Subject: [PATCH 030/309] [BAEL-4281] Examples of array comparisons --- java-collections/README.md | 8 +++ java-collections/pom.xml | 49 +++++++++++++++++++ .../com/baeldung/comparingarrays/Plane.java | 39 +++++++++++++++ .../src/main/resources/logback.xml | 13 +++++ .../baeldung/DeepEqualsCompareUnitTest.java | 34 +++++++++++++ .../com/baeldung/EqualsCompareUnitTest.java | 29 +++++++++++ .../com/baeldung/LengthsCompareUnitTest.java | 22 +++++++++ .../com/baeldung/OrderCompareUnitTest.java | 34 +++++++++++++ .../baeldung/ReferenceCompareUnitTest.java | 34 +++++++++++++ 9 files changed, 262 insertions(+) create mode 100644 java-collections/README.md create mode 100644 java-collections/pom.xml create mode 100644 java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java create mode 100644 java-collections/src/main/resources/logback.xml create mode 100644 java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java create mode 100644 java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java create mode 100644 java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java create mode 100644 java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java create mode 100644 java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java diff --git a/java-collections/README.md b/java-collections/README.md new file mode 100644 index 0000000000..480b7f257a --- /dev/null +++ b/java-collections/README.md @@ -0,0 +1,8 @@ +## Java Collections Examples + +This module support code for articles about handling java collections and arrays. + +### Relevant Articles: +- [Comparing two integer arrays in Java](https://stackoverflow.com/questions/14897366/comparing-two-integer-arrays-in-java) +- [Compare two arrays with not the same order](https://stackoverflow.com/questions/54711228/compare-two-arrays-with-not-the-same-order) +- More articles: [[next -->]](../java-collections-conversions-2) \ No newline at end of file diff --git a/java-collections/pom.xml b/java-collections/pom.xml new file mode 100644 index 0000000000..5e0ee42244 --- /dev/null +++ b/java-collections/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + java-collections + 0.1.0-SNAPSHOT + java-collections + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.hamcrest + hamcrest-all + ${hamcrest-all.version} + test + + + + + java-collections + + + src/main/resources + true + + + + + + 4.1 + + diff --git a/java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java b/java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java new file mode 100644 index 0000000000..db61807878 --- /dev/null +++ b/java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java @@ -0,0 +1,39 @@ +package com.baeldung.comparingarrays; + +import java.util.Objects; + +public class Plane { + + private final String name; + + private final String model; + + public Plane(String name, String model) { + + this.name = name; + this.model = model; + } + + public String getName() { + return name; + } + + public String getModel() { + return model; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Plane plane = (Plane) o; + return Objects.equals(name, plane.name) && Objects.equals(model, plane.model); + } + + @Override + public int hashCode() { + return Objects.hash(name, model); + } +} diff --git a/java-collections/src/main/resources/logback.xml b/java-collections/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/java-collections/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java new file mode 100644 index 0000000000..f311d0e5c9 --- /dev/null +++ b/java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java @@ -0,0 +1,34 @@ +package com.baeldung; + +import com.baeldung.comparingarrays.Plane; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class DeepEqualsCompareUnitTest { + + @Test + public void givenArray1andArray2_whenSameContent_thenDeepEquals() { + final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, + new Plane[] { new Plane("Plane 2", "B738") } }; + final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, + new Plane[] { new Plane("Plane 2", "B738") } }; + + boolean result = Arrays.deepEquals(planes1, planes2); + assertTrue("Result is not true", result); + } + + @Test + public void givenArray1andArray2_whenNotSameContent_thenNotDeepEquals() { + final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, + new Plane[] { new Plane("Plane 2", "B738") } }; + final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 2", "B738") }, + new Plane[] { new Plane("Plane 1", "A320") } }; + + boolean result = Arrays.deepEquals(planes1, planes2); + assertFalse("Result is true", result); + } +} diff --git a/java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java new file mode 100644 index 0000000000..b56395a848 --- /dev/null +++ b/java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class EqualsCompareUnitTest { + + @Test + public void givenArray1andArray2_whenSameContent_thenEquals() { + final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + + boolean result = Arrays.equals(planes1, planes2); + assertTrue("Result is not true", result); + } + + @Test + public void givenArray1andArray2_whenSameContentOtherSort_thenNotEquals() { + final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + final String[] planes2 = new String[] { "B738", "A320", "A321", "A319", "B77W", "B737", "A333", "A332" }; + + boolean result = Arrays.equals(planes1, planes2); + assertFalse("Result is true", result); + } +} diff --git a/java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java new file mode 100644 index 0000000000..8b3c90c427 --- /dev/null +++ b/java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize; +import static org.junit.Assert.assertThat; + +public class LengthsCompareUnitTest { + + @Test + public void givenArray1andArray2_whenSameSizes_thenSizeEqualsOk() { + final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + final Integer[] quantities = new Integer[] { 10, 12, 34, 45, 12, 43, 5, 2 }; + + assertThat(planes1, arrayWithSize(8)); + assertThat(quantities, arrayWithSize(8)); + assertThat(planes1.length, is(8)); + assertThat(quantities.length, is(8)); + } +} + diff --git a/java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java new file mode 100644 index 0000000000..8be7251c05 --- /dev/null +++ b/java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java @@ -0,0 +1,34 @@ +package com.baeldung; + +import com.baeldung.comparingarrays.Plane; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Comparator; + +import static org.junit.Assert.assertTrue; + +public class OrderCompareUnitTest { + @Test + public void givenArray1andArray2_whenNotSameContent_thenNotDeepEquals() { + final Plane[][] planes1 = new Plane[][] { + new Plane[] { new Plane("Plane 1", "A320"), new Plane("Plane 2", "B738") } }; + final Plane[][] planes2 = new Plane[][] { + new Plane[] { new Plane("Plane 2", "B738"), new Plane("Plane 1", "A320") } }; + + Comparator planeComparator = (o1, o2) -> { + if (o1.getName() + .equals(o2.getName())) { + return o2.getModel() + .compareTo(o1.getModel()); + } + return o2.getName() + .compareTo(o1.getName()); + }; + Arrays.sort(planes1[0], planeComparator); + Arrays.sort(planes2[0], planeComparator); + + boolean result = Arrays.deepEquals(planes1, planes2); + assertTrue("Result is false", result); + } +} diff --git a/java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java new file mode 100644 index 0000000000..9716a34607 --- /dev/null +++ b/java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java @@ -0,0 +1,34 @@ +package com.baeldung; + +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; + +public class ReferenceCompareUnitTest { + + @Test + public void givenArray1andArray2_whenEquals_thenEqual() { + final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + final String[] planes2 = planes1; + + assertSame("Objects are not equal!", planes1, planes2); + + planes2[0] = "747"; + + assertSame("Objects are not same!", planes1, planes2); + assertEquals("Objects are not equal!", "747", planes2[0]); + assertEquals("Objects are not equal!", "747", planes1[0]); + } + + @Test + public void givenArray1andArray2_whenDifferentValues_thenNotEqual() { + final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + + assertNotSame("Objects are the same!", planes1, planes2); + assertNotEquals("Objects are equal!", planes1, planes2); + } +} From 48cdcb20fb46d3a8d48ad94e598851ff7ce9f556 Mon Sep 17 00:00:00 2001 From: luvarqpp Date: Wed, 1 Jul 2020 15:39:19 +0200 Subject: [PATCH 031/309] Fix exception when receiving POISON_PILL POISON_PILL is causing writing to closed client due to logic in code. --- .../src/main/java/com/baeldung/selector/EchoServer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java index 8cf2e941fe..9e9edcd0ba 100644 --- a/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java +++ b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java @@ -49,11 +49,11 @@ public class EchoServer { if (new String(buffer.array()).trim().equals(POISON_PILL)) { client.close(); System.out.println("Not accepting client messages anymore"); + } else { + buffer.flip(); + client.write(buffer); + buffer.clear(); } - - buffer.flip(); - client.write(buffer); - buffer.clear(); } private static void register(Selector selector, ServerSocketChannel serverSocket) throws IOException { From 6182cdf09f56fc11a852a784371427a2b9705eea Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 3 Jul 2020 17:18:39 +0530 Subject: [PATCH 032/309] gupta.aashishrules@gmail.com - Hexagonal gupta.aashishrules@gmail.com - Hexagonal --- bookstore/pom.xml | 23 +++++++++++ .../src/main/java/com/hexagonal/MainApp.java | 13 +++++++ .../hexagonal/controller/BookController.java | 37 ++++++++++++++++++ .../main/java/com/hexagonal/domain/Book.java | 38 +++++++++++++++++++ .../hexagonal/repository/BookRepository.java | 15 ++++++++ .../repository/BookRepositoryImpl.java | 35 +++++++++++++++++ .../com/hexagonal/service/BookService.java | 15 ++++++++ .../hexagonal/service/BookServiceImpl.java | 35 +++++++++++++++++ 8 files changed, 211 insertions(+) create mode 100644 bookstore/pom.xml create mode 100644 bookstore/src/main/java/com/hexagonal/MainApp.java create mode 100644 bookstore/src/main/java/com/hexagonal/controller/BookController.java create mode 100644 bookstore/src/main/java/com/hexagonal/domain/Book.java create mode 100644 bookstore/src/main/java/com/hexagonal/repository/BookRepository.java create mode 100644 bookstore/src/main/java/com/hexagonal/repository/BookRepositoryImpl.java create mode 100644 bookstore/src/main/java/com/hexagonal/service/BookService.java create mode 100644 bookstore/src/main/java/com/hexagonal/service/BookServiceImpl.java diff --git a/bookstore/pom.xml b/bookstore/pom.xml new file mode 100644 index 0000000000..68286076e5 --- /dev/null +++ b/bookstore/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + com.hexagonal + bookstore + 0.0.1-SNAPSHOT + + + 1.8 + + + + org.springframework.boot + spring-boot-starter-parent + 2.3.1.RELEASE + + + + + org.springframework.boot + spring-boot-starter-web + + + \ No newline at end of file diff --git a/bookstore/src/main/java/com/hexagonal/MainApp.java b/bookstore/src/main/java/com/hexagonal/MainApp.java new file mode 100644 index 0000000000..0d6ef861b3 --- /dev/null +++ b/bookstore/src/main/java/com/hexagonal/MainApp.java @@ -0,0 +1,13 @@ +package com.hexagonal; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; + +@SpringBootApplication +public class MainApp { + public static void main(String[] args) { + SpringApplication.run(MainApp.class, args); + } + +} \ No newline at end of file diff --git a/bookstore/src/main/java/com/hexagonal/controller/BookController.java b/bookstore/src/main/java/com/hexagonal/controller/BookController.java new file mode 100644 index 0000000000..7e525deaa1 --- /dev/null +++ b/bookstore/src/main/java/com/hexagonal/controller/BookController.java @@ -0,0 +1,37 @@ +package com.hexagonal.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import com.hexagonal.domain.Book; +import com.hexagonal.service.BookService; + +@RestController +public class BookController { + + @Autowired + private BookService bookService; + + @RequestMapping("/book/add") + @PostMapping(produces = { MediaType.TEXT_PLAIN_VALUE }) + public void addBook(@RequestBody Book book) { + bookService.addBook(book); + } + + public Book buyBook(@PathVariable String isbn) { + return bookService.buyBook(isbn); + } + + public List listBooks() { + return bookService.listBooks(); + } + +} diff --git a/bookstore/src/main/java/com/hexagonal/domain/Book.java b/bookstore/src/main/java/com/hexagonal/domain/Book.java new file mode 100644 index 0000000000..84125391cc --- /dev/null +++ b/bookstore/src/main/java/com/hexagonal/domain/Book.java @@ -0,0 +1,38 @@ +package com.hexagonal.domain; + +public class Book { + + private String name; + private String isbn; + private String author; + + @Override + public String toString() { + return "Book [name=" + name + ", ISBN=" + isbn + ", author=" + author + "]"; + } + + public String getIsbn() { + return isbn; + } + + public void setIsbn(String isbn) { + this.isbn = isbn; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + +} diff --git a/bookstore/src/main/java/com/hexagonal/repository/BookRepository.java b/bookstore/src/main/java/com/hexagonal/repository/BookRepository.java new file mode 100644 index 0000000000..1e64a2d21b --- /dev/null +++ b/bookstore/src/main/java/com/hexagonal/repository/BookRepository.java @@ -0,0 +1,15 @@ +package com.hexagonal.repository; + +import java.util.List; + +import com.hexagonal.domain.Book; + +public interface BookRepository { + + public void add(Book book); + + public Book buy(String isbn); + + public List list(); + +} diff --git a/bookstore/src/main/java/com/hexagonal/repository/BookRepositoryImpl.java b/bookstore/src/main/java/com/hexagonal/repository/BookRepositoryImpl.java new file mode 100644 index 0000000000..f4f99583dd --- /dev/null +++ b/bookstore/src/main/java/com/hexagonal/repository/BookRepositoryImpl.java @@ -0,0 +1,35 @@ +package com.hexagonal.repository; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.springframework.stereotype.Repository; + +import com.hexagonal.domain.Book; + +@Repository +public class BookRepositoryImpl implements BookRepository { + + private Map bookMap = new HashMap<>(); + + @Override + public void add(Book book) { + bookMap.put(book.getIsbn(), book); + System.out.println("Book Added " + book); + } + + @Override + public Book buy(String isbn) { + return bookMap.get(isbn); + } + + @Override + public List list() { + return bookMap.values() + .stream() + .collect(Collectors.toList()); + } + +} diff --git a/bookstore/src/main/java/com/hexagonal/service/BookService.java b/bookstore/src/main/java/com/hexagonal/service/BookService.java new file mode 100644 index 0000000000..cb5e1a930e --- /dev/null +++ b/bookstore/src/main/java/com/hexagonal/service/BookService.java @@ -0,0 +1,15 @@ +package com.hexagonal.service; + +import java.util.List; + +import com.hexagonal.domain.Book; + +public interface BookService { + + public void addBook(Book book); + + public Book buyBook(String isbn); + + public List listBooks(); + +} diff --git a/bookstore/src/main/java/com/hexagonal/service/BookServiceImpl.java b/bookstore/src/main/java/com/hexagonal/service/BookServiceImpl.java new file mode 100644 index 0000000000..c7e660ea36 --- /dev/null +++ b/bookstore/src/main/java/com/hexagonal/service/BookServiceImpl.java @@ -0,0 +1,35 @@ +package com.hexagonal.service; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.hexagonal.domain.Book; +import com.hexagonal.repository.BookRepository; + +@Service +public class BookServiceImpl implements BookService { + + @Autowired + private BookRepository bookRepository; + + @Override + public void addBook(Book book) { + bookRepository.add(book); + + } + + @Override + public Book buyBook(String isbn) { + + return bookRepository.buy(isbn); + } + + @Override + public List listBooks() { + + return bookRepository.list(); + } + +} From 8f22ea5d36d35cd990d3fdf7b561b77add9278c5 Mon Sep 17 00:00:00 2001 From: STS Date: Fri, 3 Jul 2020 23:56:52 +0200 Subject: [PATCH 033/309] change files location --- apache-poi/excelformula/.gitignore | 34 ----------- apache-poi/excelformula/pom.xml | 57 ------------------- .../excelformula/ExcelformulaApplication.java | 13 ----- .../src/main/resources/application.properties | 1 - .../poi/excel/setFormula}/ExcelFormula.java | 4 +- .../setFormula/ExcelFormulaUnitTest.java} | 15 +---- 6 files changed, 4 insertions(+), 120 deletions(-) delete mode 100644 apache-poi/excelformula/.gitignore delete mode 100644 apache-poi/excelformula/pom.xml delete mode 100644 apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java delete mode 100644 apache-poi/excelformula/src/main/resources/application.properties rename apache-poi/{excelformula/src/main/java/com/bealdung/poi/excelformula => src/main/java/com/baeldung/poi/excel/setFormula}/ExcelFormula.java (90%) rename apache-poi/{excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java => src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java} (71%) diff --git a/apache-poi/excelformula/.gitignore b/apache-poi/excelformula/.gitignore deleted file mode 100644 index 719e322c1d..0000000000 --- a/apache-poi/excelformula/.gitignore +++ /dev/null @@ -1,34 +0,0 @@ -HELP.md -mvnw -mvnw.cmd -.mvn -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/** -!**/src/test/** - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ - -### VS Code ### -.vscode/ diff --git a/apache-poi/excelformula/pom.xml b/apache-poi/excelformula/pom.xml deleted file mode 100644 index 4ea65b5e57..0000000000 --- a/apache-poi/excelformula/pom.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.1.RELEASE - - - com.bealdung.poi - excelformula - 0.0.1-SNAPSHOT - excelformula - Demo project for Spring Boot - - 11 - 4.1.2 - 4.13 - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - org.apache.poi - poi-ooxml - ${poi-ooxml.version} - - - junit - junit - ${junit.version} - test - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java b/apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java deleted file mode 100644 index b857bd4266..0000000000 --- a/apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelformulaApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.bealdung.poi.excelformula; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class ExcelformulaApplication { - - public static void main(String[] args) { - SpringApplication.run(ExcelformulaApplication.class, args); - } - -} diff --git a/apache-poi/excelformula/src/main/resources/application.properties b/apache-poi/excelformula/src/main/resources/application.properties deleted file mode 100644 index 8b13789179..0000000000 --- a/apache-poi/excelformula/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java b/apache-poi/src/main/java/com/baeldung/poi/excel/setFormula/ExcelFormula.java similarity index 90% rename from apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java rename to apache-poi/src/main/java/com/baeldung/poi/excel/setFormula/ExcelFormula.java index 1e2fa5acfe..7bd8d8a035 100644 --- a/apache-poi/excelformula/src/main/java/com/bealdung/poi/excelformula/ExcelFormula.java +++ b/apache-poi/src/main/java/com/baeldung/poi/excel/setFormula/ExcelFormula.java @@ -1,16 +1,14 @@ -package com.bealdung.poi.excelformula; +package com.baeldung.poi.excel.setFormula; import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.springframework.stereotype.Component; import java.io.IOException; import java.util.List; -@Component public class ExcelFormula { XSSFWorkbook excel; public XSSFSheet inserData(List dataList) { diff --git a/apache-poi/excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java b/apache-poi/src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java similarity index 71% rename from apache-poi/excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java rename to apache-poi/src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java index c2385911d0..8daf311149 100644 --- a/apache-poi/excelformula/src/test/java/com/bealdung/poi/excelformula/ExcelformulaApplicationTests.java +++ b/apache-poi/src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java @@ -1,26 +1,18 @@ -package com.bealdung.poi.excelformula; +package com.baeldung.poi.excel.setFormula; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.junit.Assert; import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; import java.util.Arrays; import java.util.List; -@RunWith(SpringRunner.class) -@SpringBootTest -class ExcelformulaApplicationTests { - @Autowired - private ExcelFormula excelFormula; - +class ExcelFormulaUnitTest { @Test void givenExcelData_whenSetAndEvaluateFormula() throws IOException { + ExcelFormula excelFormula = new ExcelFormula(); List data = Arrays.asList(2, 5, 10, 15, 7, 9); XSSFSheet sheet = excelFormula.inserData(data); int result = 0; @@ -34,5 +26,4 @@ class ExcelformulaApplicationTests { int resultValue = (int) excelFormula.setFormula(sumFormula); Assert.assertEquals("The results are the same!", resultValue , result); } - } From b2a0fcd76bcf6eaa70c99d530b383c6711239ec6 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 6 Jul 2020 16:10:46 +0000 Subject: [PATCH 034/309] BAEL-4302 : How can I list all classes loaded in a specific class loader --- .../loadedclasslisting/ClassLoaderType.java | 6 +++ .../baeldung/loadedclasslisting/Launcher.java | 51 +++++++++++++++++++ .../ListLoadedClassesAgent.java | 46 +++++++++++++++++ .../baeldung/loadedclasslisting/MANIFEST.MF | 1 + .../customLoader/ClassLoaderInfo.java | 12 +++++ .../customLoader/CustomClassLoader.java | 32 ++++++++++++ 6 files changed, 148 insertions(+) create mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ClassLoaderType.java create mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java create mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java create mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/MANIFEST.MF create mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java create mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/CustomClassLoader.java diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ClassLoaderType.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ClassLoaderType.java new file mode 100644 index 0000000000..1111fc21fe --- /dev/null +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ClassLoaderType.java @@ -0,0 +1,6 @@ +package com.baeldung.loadedclasslisting; + +public enum ClassLoaderType { + + SYSTEM, EXTENSION, BOOTSTRAP, CUSTOM +} diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java new file mode 100644 index 0000000000..19c42dfd8d --- /dev/null +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java @@ -0,0 +1,51 @@ +package com.baeldung.loadedclasslisting; + +import java.lang.reflect.Method; +import java.util.Arrays; + +import com.baeldung.loadedclasslisting.customLoader.ClassLoaderInfo; +import com.baeldung.loadedclasslisting.customLoader.CustomClassLoader; + +public class Launcher { + + private static ClassLoader customClassLoader; + + public static void main(String[] args) { + + printClassesLoadedBy(ClassLoaderType.BOOTSTRAP); + + printClassesLoadedBy(ClassLoaderType.SYSTEM); + + printClassesLoadedBy(ClassLoaderType.EXTENSION); + + printClassesLoadedBy(ClassLoaderType.CUSTOM); + } + + private static void printClassesLoadedBy(ClassLoaderType classLoaderType) { + Class[] classes; + if (classLoaderType.equals(ClassLoaderType.CUSTOM)) { + customClassLoader = customClassLoading(); + classes = ListLoadedClassesAgent.listLoadedClasses(customClassLoader); + } else { + classes = ListLoadedClassesAgent.listLoadedClasses(classLoaderType); + } + Arrays.asList(classes) + .forEach(clazz -> System.out.println( + classLoaderType + " ClassLoader : " + clazz.getCanonicalName())); + } + + private static CustomClassLoader customClassLoading() { + CustomClassLoader customClassLoader = new CustomClassLoader(); + Class c; + try { + c = customClassLoader.findClass(ClassLoaderInfo.class.getName()); + Object ob = c.getDeclaredConstructor() + .newInstance(); + Method md = c.getMethod("printClassLoaders"); + md.invoke(ob); + } catch (Exception e) { + e.printStackTrace(); + } + return customClassLoader; + } +} diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java new file mode 100644 index 0000000000..03907f8b04 --- /dev/null +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java @@ -0,0 +1,46 @@ +package com.baeldung.loadedclasslisting; + +import java.lang.instrument.Instrumentation; + +public class ListLoadedClassesAgent { + + private static Instrumentation instrumentation; + + public static void premain(String agentArgs, Instrumentation instrumentation) { + ListLoadedClassesAgent.instrumentation = instrumentation; + } + + public static Class[] listLoadedClasses(ClassLoaderType classLoaderType) { + if (instrumentation == null) { + throw new IllegalStateException( + "ListLoadedClassesAgent is not initialized."); + } + return instrumentation.getInitiatedClasses( + getClassLoader(classLoaderType)); + } + + public static Class[] listLoadedClasses(ClassLoader classLoader) { + if (instrumentation == null) { + throw new IllegalStateException( + "ListLoadedClassesAgent is not initialized."); + } + return instrumentation.getInitiatedClasses(classLoader); + } + + private static ClassLoader getClassLoader(ClassLoaderType classLoaderType) { + ClassLoader classLoader = null; + switch (classLoaderType) { + case SYSTEM: + classLoader = ClassLoader.getSystemClassLoader(); + break; + case EXTENSION: + classLoader = ClassLoader.getSystemClassLoader().getParent(); + break; + case BOOTSTRAP: + break; + default: + break; + } + return classLoader; + } +} diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/MANIFEST.MF b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/MANIFEST.MF new file mode 100644 index 0000000000..4a60bda0b7 --- /dev/null +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/MANIFEST.MF @@ -0,0 +1 @@ +Premain-Class: com.baeldung.loadedclasslisting.ListLoadedClassesAgent \ No newline at end of file diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java new file mode 100644 index 0000000000..a787b062d5 --- /dev/null +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java @@ -0,0 +1,12 @@ +package com.baeldung.loadedclasslisting.customLoader; + +import java.util.ArrayList; + +public class ClassLoaderInfo { + + public void printClassLoaders() throws ClassNotFoundException { + + System.out.println("Classloader of this class:" + ClassLoaderInfo.class.getClassLoader()); + System.out.println("Classloader of ArrayList:" + ArrayList.class.getClassLoader()); + } +} diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/CustomClassLoader.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/CustomClassLoader.java new file mode 100644 index 0000000000..a5f293f605 --- /dev/null +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/CustomClassLoader.java @@ -0,0 +1,32 @@ +package com.baeldung.loadedclasslisting.customLoader; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +public class CustomClassLoader extends ClassLoader { + + @Override + public Class findClass(String name) throws ClassNotFoundException { + byte[] b = loadClassFromFile(name); + return defineClass(name, b, 0, b.length); + } + + private byte[] loadClassFromFile(String fileName) { + InputStream inputStream = getClass().getClassLoader() + .getResourceAsStream(fileName.replace('.', File.separatorChar) + ".class"); + byte[] buffer; + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + int nextValue = 0; + try { + while ((nextValue = inputStream.read()) != -1) { + byteStream.write(nextValue); + } + } catch (IOException e) { + e.printStackTrace(); + } + buffer = byteStream.toByteArray(); + return buffer; + } +} From 4f987c9198d52a4068454f7f9d3e61266e1ac08e Mon Sep 17 00:00:00 2001 From: joe zhang Date: Tue, 7 Jul 2020 13:20:06 +0800 Subject: [PATCH 035/309] update labmda function --- .../convertlisttomap/ListToMapUnitTest.java | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java index 5a875a904e..4ca5671e29 100644 --- a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java +++ b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java @@ -24,13 +24,9 @@ public class ListToMapUnitTest { Map> convertedMap = new HashMap<>(); - Supplier> listSupplier = () -> { - return new ArrayList<>(); - }; + Supplier> listSupplier = ArrayList::new; - Supplier>> mapFactory = () -> { - return new HashMap<>(); - }; + Supplier>> mapFactory = HashMap::new; convertedMap = strings.stream() .collect(Collectors.groupingBy(String::length, mapFactory, Collectors.toCollection(listSupplier))); @@ -45,13 +41,9 @@ public class ListToMapUnitTest { Map> convertedMap = new HashMap<>(); - Supplier>> mapFactory = () -> { - return new HashMap<>(); - }; + Supplier>> mapFactory = HashMap::new; - Supplier> listSupplier = () -> { - return new ArrayList<>(); - }; + Supplier> listSupplier = ArrayList::new; BiConsumer>, String> accumulator = (response, element) -> { Integer key = element.length(); @@ -78,17 +70,11 @@ public class ListToMapUnitTest { Map> convertedMap = new HashMap<>(); - Supplier>> mapFactory = () -> { - return new HashMap<>(); - }; + Supplier>> mapFactory = HashMap::new; - Supplier> listSupplier = () -> { - return new ArrayList<>(); - }; + Supplier> listSupplier = ArrayList::new; - Function keyMapper = (element) -> { - return element.length(); - }; + Function keyMapper = String::length; Function> valueMapper = (element) -> { List collection = listSupplier.get(); From 3e31cb49b16682206ba189db0233d1e5bc0b43fd Mon Sep 17 00:00:00 2001 From: STS Date: Sat, 11 Jul 2020 10:31:02 +0200 Subject: [PATCH 036/309] changes after adding excel file --- .../poi/excel/setFormula/ExcelFormula.java | 32 +++++------- .../src/main/resources/SetFormulaTest.xlsx | Bin 0 -> 8014 bytes .../setFormula/ExcelFormulaUnitTest.java | 46 +++++++++++++----- 3 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 apache-poi/src/main/resources/SetFormulaTest.xlsx diff --git a/apache-poi/src/main/java/com/baeldung/poi/excel/setFormula/ExcelFormula.java b/apache-poi/src/main/java/com/baeldung/poi/excel/setFormula/ExcelFormula.java index 7bd8d8a035..8b1ca5a89a 100644 --- a/apache-poi/src/main/java/com/baeldung/poi/excel/setFormula/ExcelFormula.java +++ b/apache-poi/src/main/java/com/baeldung/poi/excel/setFormula/ExcelFormula.java @@ -1,34 +1,26 @@ package com.baeldung.poi.excel.setFormula; -import org.apache.poi.ss.usermodel.CellValue; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; -import java.util.List; public class ExcelFormula { - XSSFWorkbook excel; - public XSSFSheet inserData(List dataList) { - excel = new XSSFWorkbook(); - XSSFSheet sheet = excel.createSheet(); - int rowNum =0 ; - for (Integer data : dataList){ - sheet.createRow(rowNum++).createCell(0).setCellValue(data); - } - return sheet; - } - public double setFormula(String formula) throws IOException { - XSSFSheet sheet = excel.getSheetAt(0); + public double setFormula(String fileLocation, XSSFWorkbook wb, String formula) throws IOException { + XSSFSheet sheet = wb.getSheetAt(0); int lastCellNum = sheet.getRow(0).getLastCellNum(); - XSSFCell formulaCell = sheet.getRow(0).createCell(lastCellNum + 1); + XSSFCell formulaCell = sheet.getRow(0).createCell(lastCellNum); formulaCell.setCellFormula(formula); - XSSFFormulaEvaluator formulaEvaluator = excel.getCreationHelper().createFormulaEvaluator(); - CellValue evaluate = formulaEvaluator.evaluate(formulaCell); - if(excel != null) - excel.close(); - return evaluate.getNumberValue(); + XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator(); + formulaEvaluator.evaluateFormulaCell(formulaCell); + FileOutputStream fileOut = new FileOutputStream(new File(fileLocation)); + wb.write(fileOut); + wb.close(); + fileOut.close(); + return formulaCell.getNumericCellValue(); } } diff --git a/apache-poi/src/main/resources/SetFormulaTest.xlsx b/apache-poi/src/main/resources/SetFormulaTest.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..a0fe73f0ebe74ad3ca9020e685c4a6f0564687e5 GIT binary patch literal 8014 zcmeHM1zS|x8XiEpX6O`YknWc5PHB)35u{;gq`Nz%YmhEMN?J;gM!F>=grT|Px%XVp z@tpe$?pgbJ_L|wV-|yM8_WOPBTJKU*M0kJ)Kmwou002rrp=R%x3LF4{@&Ew91)#ti zNZQ-ESlYRmXn8nTIvcUNzp{Ol{{WsL7XS~t|DX1MJOUMoLn__uKxwGljpPPP#A2-& z3eQ16KTZn+h3T5S*%X_{mx((OTxgA09{x+d8ndx4&LUhn!@SdYHesc0klD0YUAW3~ zh1N#1H<3*z@%U+lniKBG_zUp0bKlRO*Uln!2Go-4R46hEqx!od>rg@A$g;Vg=%?@S zHBt?DG8zD(1>=FGZHg-z>7JOp+3&@upVHx1kTK#fT~@(^!L2R!F{HUPPjPUWTITbyR1I*9 z^(hG|ZV_1sfk?W)exI`5lG#Ni+?0go!P}7PCcfOSiDQ|5GbzQpn4)0tMM(p5NfM2{w*bmmik_69=Lyq(CaVF9 zVsgB5D3wTy&NQ#UqU*UTc<-PplJT3l19~RV%Bdr5AK|tDGmc8$KycwRst}{gi|X6L zE;+#-BMRLjf_@Ug_@j`4#)5H&ErfU6*4|{%g+vAzeGiosn+Hz`qwa-rh4-|s^(DW| zjOCUy(wrRFEpxXOf$d|d1>U_DOR<(CR7(zL2@mPWqLu9&x)>2TPRI$?xgv8kjVL@$;H<7$(4n_lKY#1 zmK{6?LznthBPct2T>lQInP9l`n|I|x%p+b2G$?-nXVvE1nT|CAsk|jczKaYUl-Px- zd0c1aFf2EKanR~a<{400bFjCT0OuS1yvR-q^b=N-+?IT`oe^rN_NdB>GU&xZ$ZqS9 zv7BIZ0u7d)+D+10pF95aCq=L<)$kEs+QWWFVJQuD!ihZfl_LcvS+YCRdy`9&nko|I zukKA3?+B5~7?I{9Xnp*xs%!XGNUHcatsoWqQFlRKk}JXUC~=KJSfyS!Dv=W;##kfj zI8ld~vIb99DRLsO3DE!)r6^&MjLU=fiK%7+F3`5lw%gvL>hDF<2M z_yUt{oCrb(iL+I`?A2{aQ|o%El>1xXh{c|YJ&l^yG^g+;dQOwyMY@0Xi04#^Zh&J( zo11F5!!a()g<_Z}tHMP(6>2TmEwE$wP*nQ?zaL&r@GHVENPnIb^S2|4!!w;J4WLwxfKKx=E%Wu}pqa61Nz&ewB@y%ll-VqE zXCzECO9ou41BZRY(|SZcDB$@aP=)#0l2)nZQ>GjcS)I>5dqxv6WyF$9CxoSiy&8o_ zzd!1Z$flc@te)Hk;5X66XWFqzQS{qI&`8lz&<{kLQb5;-s~@WNO!}HRyvVk_Ur^g4 zTtNS!3)f6k5v?~_h9C*fEL#>w{5p*E!<-5ip$@3)q6REGIvy_2gNjrnQ1ZNH+^1LZZfq8Pbi!*G{a_ucBOm?vuV{vTlYPvZK}@y;{wdpe}(uM<+|v zl4QjEj47`s{i#lHNd;nZU7BDb7fm>3H=U{6j*-8z)xTlavHBd$1{@aWHz3A>nqc>0(b|o*%&fpuH=eBIeNM5#93;T4GdxaaN4VJOB8S%t}tsInU3Fdif z87anSZD(rpNH{yRw>FK+)|vwypXf(sso!qeW!ODp(d*_cxcvTow~cQ(k(-chF}ln- zNK-|3!VN;g+z{Ru_n`8yG7?8Xny*Ni&8*h3X$Sq`| zu(geQsl*`@g_Tr>doi`RW?b@Ff2el&3i`u|NdbxagAe@XZo)m_;61e-MBx{$_-ETG zO>8OSI!oaZm_7}@2xqC#A)zR2o0r2bp4B9ir`~Kk75hv8{Jm!10*dc}$s&ki1)yQ> z_56kJt#9qd#%f3yTI**Ic|6a`{b%-PX86J0mt03^NpsNYqd;*KV{X{zRi8*zl7>$| zF0Tgico$6UdSD_{iGgSbS4mpdkk1?h7Vs@T?8M+NowSJ;q>!?y#bHAB6C{;%sdzW_ zqYkTG007iNxwsxsBymnI$igvD1ICwl_ZaCv&*ln|1y4*f}}E7rPs)-HFJe&l{s+gc#Dl zlACy6&%H76+rK&9$RvzyuU>x_bAJ}9>U(+VECi%8a9_PljrH@oy10D$=I(Bh8vT7@ zJ_7j@8jh_|ZSVarrX0h{9$gkO*b{!!=0ucc-^D<)jcJFG0{~;AM=!fwYj)ooFrq|Z zx_kKcue4AUIg2w>n}nMoH1`u7)J}eV&E&*9(%tRB*?^rh>iPvUD8|-2lz~HH;mw$s zUigRw(X+rU*9aW{V*aiV@nf@;eJOK`bUjCV4~dJS>cSoDa7!Y?rf4OdOldU6twVc& zslm~Yg65A#mRL%LN?%Qjcw11d28&Hf_=c6O_6@yYRkP(1km8skZ;zC+pnlgOCo5Pv zhA8D3!RUNtKK$)=n1-8Zla4cvDXYHYGAGlyE7yA!e$2S=@}4~wI?KOMqXTgQXM`im z=D(=AfVj=R3d11hjxd`2_qGTaECA$ zs1_3p`BYR#Srr?ehSiHpDDou+rG$V;)`f-63KCDFTp=iB;;JoXm%Mn~BqMwv8%C;< zdVjhWjZZxScCF%zp`U9&84Zi5`!}ncIpT*7?+&G1(E6>Y@f^6Z{~-(CkYsa zs}v(~fcRY*!WSyD?jDoA$mf=FgiMP8m-L-j;*y)9$sR0XaONl-$?ZIw(Jw5iGf=xw zVyaNphRz@l<=A4aF2(lskHTe_@Bs_cmP-|oV^Bj8a$jzZaQNenB*)=jg3H-AYatYj zY3iVPKmT?DUMm^>rE<2YFkXz zNA6}aosdBC!$>MPcXbw!j9(bpl)1*0PCs^(neqt^$W>=T;wqKz+v8;B5whng%U%x< zJC&;LvWJj7JL}og@!bIn+F1JQRx)X?K~yQOW>DQ6kb4S{w>zC5H>1&dd&z;AuWA!F zlz3P0-!Yx=P#FrGCe<%`;diVD^N2EQXZUt(OtmSL?Sj7+#eAEA_;l#+y4pbVs>2v6 zujZ^$;j(1MrSFcV8>)O>ho{Qg5y~*La-I1XRfIvX*{9~Wu-UQT#@`W6BE9v5kS6J$ zjplBgwTx&mVYCz(19?3Ijd%DA0)1@C|tHpCNX|HeN2-5 ze0lH7SSknmsnQcClhVz_H9_4hAb3P27^mkH;nN&J~gB)NmR%MXWMgA5c*<{7%8su-e5D$%$^EF- zBB+voj<;SrFg%w>C$6JHmtM9h2dqPA&R|VwQgNTnWTM0MF_JA9}A(oQFn{z zdtl;ttDiufJrT(8L}Si$8zVfYO282ZIqRg}v>M*XP4N?_WbD$(;Avc9iI4vsdrN9x zUD44M{aZ%$`qw@ZDV6sbr(hQE;10v;q&6`Fv;5hZC!bqJKXH|AESu9| zxZ|-@KI#^bW66no=B=a4<*NlP(EcjY;lb80t7~a-O`mCvwsy^4TV=a#hNT@z{}L!u z(!jGGK4&V69=-jj!CfL?)B1CUTnqkjKT6u+;mUcm8-RZi{Mebbf+7441MA4O)nt2zHDy$2ySw^S`kT!gSK9cSp~hH!#nyDnOTA&2TsJM=-iPJI8cnTh zugfJIK9X0P8aAZpr}fdZJv8)}m1ynBxU7!4UXlZXLrs>PMVwkmM98FY0>|6?VhaTgr^M$L$(u>TJIsDIZ|*skkq+1$09drCvi-!@t;f)-w59>Me;A z%tgSc2SNYnMg0CuY~%Q(wby*~hL`)5l)Mpzpvm{R@m{s?&3rt>2c$NH=gG~>x6K!i z(P(gAuA9GBAcN~|xVsR4<)joh2uDB$s>Wea*Ow1(3?5wx*z8omb+!syc%NEhofVw< z;*B5*4cpL3WDtUQX0(hlv&GLVd?Y?zfrn#f;en3_L#+8zoWH$ydvoT*?ciuf22Teh7zKf2 zgjcGbn{&2FzR$vq#lZa*R7ZYM%(d;ko_tyObZ&2!7B_}DtNabC@S4wjFRA3w`_a?9 z`9?a)5jF>XsCBNLN8%hd<=%9V$mCc~(}$xA?9bRULlEi9vJG(dNRs#E(ACe<2?x&t z_+NXUzrU~F`@h)aSJb}sW71@t({{n|4 B-9P{U literal 0 HcmV?d00001 diff --git a/apache-poi/src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java b/apache-poi/src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java index 8daf311149..990b93fcbb 100644 --- a/apache-poi/src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java +++ b/apache-poi/src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java @@ -2,28 +2,48 @@ package com.baeldung.poi.excel.setFormula; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; -import java.util.Arrays; -import java.util.List; +import java.net.URISyntaxException; +import java.nio.file.Paths; class ExcelFormulaUnitTest { + private static String FILE_NAME = "SetFormulaTest.xlsx"; + private String fileLocation; + private ExcelFormula excelFormula; + + @BeforeEach + public void setup() throws URISyntaxException { + fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString(); + excelFormula = new ExcelFormula(); + } + @Test void givenExcelData_whenSetAndEvaluateFormula() throws IOException { - ExcelFormula excelFormula = new ExcelFormula(); - List data = Arrays.asList(2, 5, 10, 15, 7, 9); - XSSFSheet sheet = excelFormula.inserData(data); - int result = 0; + FileInputStream inputStream = new FileInputStream(new File(fileLocation)); + XSSFWorkbook wb = new XSSFWorkbook(inputStream); + XSSFSheet sheet = wb.getSheetAt(0); + double resultColumnA = 0; + double resultColumnB = 0; for (int row = 0; row <= sheet.getLastRowNum(); row++) { - result += sheet.getRow(row).getCell(0).getNumericCellValue(); + resultColumnA += sheet.getRow(row).getCell(0).getNumericCellValue(); + resultColumnB += sheet.getRow(row).getCell(1).getNumericCellValue(); } - String colName = CellReference.convertNumToColString(0); - String startCell = colName + 1; - String stopCell = colName + (sheet.getLastRowNum() + 1); - String sumFormula = String.format("SUM(%s:%s)", startCell, stopCell); - int resultValue = (int) excelFormula.setFormula(sumFormula); - Assert.assertEquals("The results are the same!", resultValue , result); + String colNameA = CellReference.convertNumToColString(0); + String colNameB = CellReference.convertNumToColString(1); + String startCellA = colNameA + 1; + String stopCellA = colNameA + (sheet.getLastRowNum() + 1); + String sumFormulaForColumnA = String.format("SUM(%s:%s)", startCellA, stopCellA); + String startCellB = colNameB + 1; + String stopCellB = colNameB + (sheet.getLastRowNum() + 1); + String sumFormulaForColumnB = String.format("SUM(%s:%s)", startCellB, stopCellB); + double resultValue = excelFormula.setFormula(fileLocation, wb, sumFormulaForColumnA + "-" + sumFormulaForColumnB); + Assert.assertEquals(resultValue, resultColumnA - resultColumnB, 0d); } } From a909a79f718c0129ee56b66910ba0b058aa3464b Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Sat, 11 Jul 2020 20:34:36 -0600 Subject: [PATCH 037/309] BAEL-4148: Demo app for spring boot and Docker --- docker/docker-spring-boot/mvnw | 310 ++++++++++++++++++ docker/docker-spring-boot/mvnw.cmd | 182 ++++++++++ docker/docker-spring-boot/pom.xml | 54 +++ .../src/main/docker/Dockerfile | 15 + .../com/baeldung/docker/DemoApplication.java | 13 + .../com/baeldung/docker/HelloController.java | 16 + .../src/main/resources/application.properties | 1 + 7 files changed, 591 insertions(+) create mode 100755 docker/docker-spring-boot/mvnw create mode 100644 docker/docker-spring-boot/mvnw.cmd create mode 100644 docker/docker-spring-boot/pom.xml create mode 100644 docker/docker-spring-boot/src/main/docker/Dockerfile create mode 100644 docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java create mode 100644 docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java create mode 100644 docker/docker-spring-boot/src/main/resources/application.properties diff --git a/docker/docker-spring-boot/mvnw b/docker/docker-spring-boot/mvnw new file mode 100755 index 0000000000..a16b5431b4 --- /dev/null +++ b/docker/docker-spring-boot/mvnw @@ -0,0 +1,310 @@ +#!/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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# 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 /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 + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -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 "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; 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="`which 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 + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# 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/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# 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. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +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 "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -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 + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/docker/docker-spring-boot/mvnw.cmd b/docker/docker-spring-boot/mvnw.cmd new file mode 100644 index 0000000000..c8d43372c9 --- /dev/null +++ b/docker/docker-spring-boot/mvnw.cmd @@ -0,0 +1,182 @@ +@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 Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@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 "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\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 DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_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 DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_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('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@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 "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\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% + +exit /B %ERROR_CODE% diff --git a/docker/docker-spring-boot/pom.xml b/docker/docker-spring-boot/pom.xml new file mode 100644 index 0000000000..b9c80bc43a --- /dev/null +++ b/docker/docker-spring-boot/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.1.RELEASE + + + com.baeldung.docker + spring-boot-docker + 0.0.1-SNAPSHOT + spring-boot-docker + Demo project showing Spring Boot and Docker + + + 8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + true + + + + + + + diff --git a/docker/docker-spring-boot/src/main/docker/Dockerfile b/docker/docker-spring-boot/src/main/docker/Dockerfile new file mode 100644 index 0000000000..fa147dd69b --- /dev/null +++ b/docker/docker-spring-boot/src/main/docker/Dockerfile @@ -0,0 +1,15 @@ +# To build, run the following command from the top level project directory: +# +# docker build -f src/main/docker/Dockerfile . + +FROM adoptopenjdk:11-jre-hotspot as builder +ARG JAR_FILE=target/*.jar +COPY ${JAR_FILE} application.jar +RUN java -Djarmode=layertools -jar application.jar extract + +FROM adoptopenjdk:11-jre-hotspot +COPY --from=builder dependencies/ ./ +COPY --from=builder snapshot-dependencies/ ./ +COPY --from=builder spring-boot-loader/ ./ +COPY --from=builder application/ ./ +ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"] \ No newline at end of file diff --git a/docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java new file mode 100644 index 0000000000..e0c1d57e89 --- /dev/null +++ b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/DemoApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.docker; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java new file mode 100644 index 0000000000..b463bb557f --- /dev/null +++ b/docker/docker-spring-boot/src/main/java/com/baeldung/docker/HelloController.java @@ -0,0 +1,16 @@ +package com.baeldung.docker; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + + @GetMapping("/hello") + public ResponseEntity hello() + { + return ResponseEntity.ok("hello2 "); + } + +} diff --git a/docker/docker-spring-boot/src/main/resources/application.properties b/docker/docker-spring-boot/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/docker/docker-spring-boot/src/main/resources/application.properties @@ -0,0 +1 @@ + From 7cbb0833d40610344c1d11da0cf7597ca24e52ad Mon Sep 17 00:00:00 2001 From: joe zhang Date: Sun, 12 Jul 2020 16:19:08 +0800 Subject: [PATCH 038/309] refactor unit test into utility class --- .../convertlisttomap/ListToMapConverter.java | 70 +++++++++++++++++ .../convertlisttomap/ListToMapUnitTest.java | 78 ++++--------------- 2 files changed, 83 insertions(+), 65 deletions(-) create mode 100644 java-collections-conversions-2/src/main/java/com/baeldung/convertlisttomap/ListToMapConverter.java diff --git a/java-collections-conversions-2/src/main/java/com/baeldung/convertlisttomap/ListToMapConverter.java b/java-collections-conversions-2/src/main/java/com/baeldung/convertlisttomap/ListToMapConverter.java new file mode 100644 index 0000000000..8450f54f9d --- /dev/null +++ b/java-collections-conversions-2/src/main/java/com/baeldung/convertlisttomap/ListToMapConverter.java @@ -0,0 +1,70 @@ +package com.baeldung.convertlisttomap; + +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.BinaryOperator; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +/** + * Convert a string list to a map whose key is the string's length and value is the collection with same length. + * Give a list {"Baeldung", "is", "very", "cool"}. + * After conversion we'll get a map like: + * {8 : ["Baeldung"], 2 : ["is"], 4 : ["very", "cool"]}. + * + * @author leasy.zhang + * + */ +public class ListToMapConverter { + + public Map> groupingByStringLength(List source, + Supplier>> mapSupplier, + Supplier> listSupplier) { + + return source.stream() + .collect(Collectors.groupingBy(String::length, mapSupplier, Collectors.toCollection(listSupplier))); + } + + public Map> streamCollectByStringLength(List source, + Supplier>> mapSupplier, + Supplier> listSupplier) { + + BiConsumer>, String> accumulator = (response, element) -> { + Integer key = element.length(); + List values = response.getOrDefault(key, listSupplier.get()); + values.add(element); + response.put(key, values); + }; + + BiConsumer>, Map>> combiner = (res1, res2) -> { + res1.putAll(res2); + }; + + return source.stream() + .collect(mapSupplier, accumulator, combiner); + } + + public Map> collectorToMapByStringLength(List source, + Supplier>> mapSupplier, + Supplier> listSupplier) { + + Function keyMapper = String::length; + + Function> valueMapper = (element) -> { + List collection = listSupplier.get(); + collection.add(element); + return collection; + }; + + BinaryOperator> mergeFunction = (existing, replacement) -> { + existing.addAll(replacement); + return existing; + }; + + return source.stream() + .collect(Collectors.toMap(keyMapper, valueMapper, mergeFunction, mapSupplier)); + } + +} diff --git a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java index 4ca5671e29..2b43813822 100644 --- a/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java +++ b/java-collections-conversions-2/src/test/java/com/baeldung/convertlisttomap/ListToMapUnitTest.java @@ -1,6 +1,5 @@ package com.baeldung.convertlisttomap; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.ArrayList; @@ -8,89 +7,38 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.function.BiConsumer; -import java.util.function.BinaryOperator; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collectors; +import org.junit.Before; import org.junit.Test; public class ListToMapUnitTest { + private ListToMapConverter converter; + private List source; + + @Before + public void setUp() { + converter = new ListToMapConverter(); + source = Arrays.asList("List", "Map", "Set", "Tree"); + } + @Test public void givenAList_whenConvertWithJava8GroupBy_thenReturnMap() { - List strings = Arrays.asList("List", "Map", "Set", "Tree"); - - Map> convertedMap = new HashMap<>(); - - Supplier> listSupplier = ArrayList::new; - - Supplier>> mapFactory = HashMap::new; - convertedMap = strings.stream() - .collect(Collectors.groupingBy(String::length, mapFactory, Collectors.toCollection(listSupplier))); - - assertEquals(2, convertedMap.size()); + Map> convertedMap = converter.groupingByStringLength(source, HashMap::new, ArrayList::new); assertTrue(convertedMap.get(3) .contains("Map")); } @Test public void givenAList_whenConvertWithJava8Collect_thenReturnMap() { - List strings = Arrays.asList("List", "Map", "Set", "Tree"); - - Map> convertedMap = new HashMap<>(); - - Supplier>> mapFactory = HashMap::new; - - Supplier> listSupplier = ArrayList::new; - - BiConsumer>, String> accumulator = (response, element) -> { - Integer key = element.length(); - List values = response.getOrDefault(key, listSupplier.get()); - values.add(element); - response.put(key, values); - }; - - BiConsumer>, Map>> combiner = (res1, res2) -> { - res1.putAll(res2); - }; - - convertedMap = strings.stream() - .collect(mapFactory, accumulator, combiner); - - assertEquals(2, convertedMap.size()); + Map> convertedMap = converter.streamCollectByStringLength(source, HashMap::new, ArrayList::new); assertTrue(convertedMap.get(3) .contains("Map")); } @Test public void givenAList_whenConvertWithCollectorToMap_thenReturnMap() { - List strings = Arrays.asList("List", "Map", "Set", "Tree"); - - Map> convertedMap = new HashMap<>(); - - Supplier>> mapFactory = HashMap::new; - - Supplier> listSupplier = ArrayList::new; - - Function keyMapper = String::length; - - Function> valueMapper = (element) -> { - List collection = listSupplier.get(); - collection.add(element); - return collection; - }; - - BinaryOperator> mergeFunction = (existing, replacement) -> { - existing.addAll(replacement); - return existing; - }; - - convertedMap = strings.stream() - .collect(Collectors.toMap(keyMapper, valueMapper, mergeFunction, mapFactory)); - - assertEquals(2, convertedMap.size()); + Map> convertedMap = converter.collectorToMapByStringLength(source, HashMap::new, ArrayList::new); assertTrue(convertedMap.get(3) .contains("Map")); } From 64dc02f18fdbde9e728083aef09cf7318f9145cf Mon Sep 17 00:00:00 2001 From: mdhtr Date: Sun, 12 Jul 2020 23:29:55 +0200 Subject: [PATCH 039/309] Examples for the second version of the article --- .../JacksonDeserializationExample.java | 40 ------------------ .../hydrajsonld/HydraJsonldExamplePerson.java | 15 ------- .../JacksonJsonLdSerializationExample.java | 25 ----------- .../JacksonJsonldExamplePerson.java | 17 -------- .../JacksonDeserializationUnitTest.java | 41 ++++++++++++++++++ .../jsonldjava/jackson/Person.java} | 4 +- .../HydraJsonldSerializationUnitTest.java} | 37 +++++++++++----- .../JacksonJsonLdSerializationUnitTest.java | 42 +++++++++++++++++++ 8 files changed, 112 insertions(+), 109 deletions(-) delete mode 100644 json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationExample.java delete mode 100644 json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldExamplePerson.java delete mode 100644 json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationExample.java delete mode 100644 json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonldExamplePerson.java create mode 100644 json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java rename json-2/src/{main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonExamplePerson.java => test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/Person.java} (88%) rename json-2/src/{main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationExample.java => test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java} (52%) create mode 100644 json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java diff --git a/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationExample.java b/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationExample.java deleted file mode 100644 index b80769b408..0000000000 --- a/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationExample.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.jsonld.deserialization.jsonldjava.jackson; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.jsonldjava.core.JsonLdOptions; -import com.github.jsonldjava.core.JsonLdProcessor; -import com.github.jsonldjava.utils.JsonUtils; - -public class JacksonDeserializationExample { - public static void main(String[] args) throws IOException { - String exampleJsonld ="{" + - " \"@context\": {" + - " \"@vocab\": \"http://schema.org/\"," + - " \"knows\": {" + - " \"@type\": \"@id\"" + - " }" + - " }," + - " \"@type\": \"Person\"," + - " \"@id\": \"http://example.com/person/1234\"," + - " \"name\": \"Example Name\"," + - " \"knows\": \"http://example.com/person/2345\"" + - "}"; - - Object jsonObject = JsonUtils.fromString(exampleJsonld); - Object compact = JsonLdProcessor.compact(jsonObject, new HashMap(), new JsonLdOptions()); - String compactContent = JsonUtils.toString(compact); - - System.out.println(JsonUtils.toPrettyString(compact)); - - ObjectMapper objectMapper = new ObjectMapper(); - JacksonExamplePerson person = objectMapper.readValue(compactContent, JacksonExamplePerson.class); - - System.out.println(person.id); - System.out.println(person.name); - System.out.println(person.knows.id); - } -} diff --git a/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldExamplePerson.java b/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldExamplePerson.java deleted file mode 100644 index 16b2199a73..0000000000 --- a/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldExamplePerson.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.jsonld.serialization.hydrajsonld; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import de.escalon.hypermedia.hydra.mapping.Expose; -import de.escalon.hypermedia.hydra.mapping.Vocab; - -@Vocab("http://example.com/vocab/") -@Expose("person") -public class HydraJsonldExamplePerson { - @JsonProperty("@id") - public String id; - @Expose("fullName") - public String name; -} diff --git a/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationExample.java b/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationExample.java deleted file mode 100644 index 6a1acee1b8..0000000000 --- a/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationExample.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.jsonld.serialization.jacksonjsonld; - -import java.io.IOException; - -import com.fasterxml.jackson.databind.ObjectMapper; - -import ioinformarics.oss.jackson.module.jsonld.HydraCollection; -import ioinformarics.oss.jackson.module.jsonld.JsonldGraph; -import ioinformarics.oss.jackson.module.jsonld.JsonldModule; -import ioinformarics.oss.jackson.module.jsonld.JsonldResource; - -public class JacksonJsonLdSerializationExample { - public static void main(String[] args) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JsonldModule()); - - JacksonJsonldExamplePerson person = new JacksonJsonldExamplePerson(); - - JsonldResource jsonldResource = JsonldResource.Builder.create() - .build(person); - - System.out.println(objectMapper.writerWithDefaultPrettyPrinter() - .writeValueAsString(jsonldResource)); - } -} diff --git a/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonldExamplePerson.java b/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonldExamplePerson.java deleted file mode 100644 index a3161ba1d3..0000000000 --- a/json-2/src/main/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonldExamplePerson.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.jsonld.serialization.jacksonjsonld; - -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldId; -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldLink; -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldNamespace; -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldProperty; -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldType; - -@JsonldNamespace(name = "s", uri = "http://schema.org/") -@JsonldLink(rel = "s:knows", name = "knows", href = "http://example.com/person/2345") -@JsonldType("s:Person") -class JacksonJsonldExamplePerson { - @JsonldId - public String id = "http://example.com/person/1234"; - @JsonldProperty("s:name") - public String name = "Example Name"; -} diff --git a/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java new file mode 100644 index 0000000000..35a2613957 --- /dev/null +++ b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java @@ -0,0 +1,41 @@ +package com.baeldung.jsonld.deserialization.jsonldjava.jackson; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.util.HashMap; + +import org.junit.jupiter.api.Test; + +import com.baeldung.jsonld.deserialization.jsonldjava.jackson.Person.Link; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.jsonldjava.core.JsonLdOptions; +import com.github.jsonldjava.core.JsonLdProcessor; +import com.github.jsonldjava.utils.JsonUtils; + +public class JacksonDeserializationUnitTest { + + @Test + void givenAJsonLdObject_whenCompactIsUsedWithEmptyContext_thenItCanBeDeserializedIntoAJacksonAnnotatedJavaObject() throws IOException { + String inputJsonLd = "{\"@context\":{\"@vocab\":\"http://schema.org/\",\"knows\":{\"@type\":\"@id\"}},\"@type\":\"Person\",\"@id\":\"http://example.com/person/1234\",\"name\":\"Example Name\",\"knows\":\"http://example.com/person/2345\"}"; + + Object jsonObject = JsonUtils.fromString(inputJsonLd); + Object compact = JsonLdProcessor.compact(jsonObject, new HashMap(), new JsonLdOptions()); + String compactContent = JsonUtils.toString(compact); + + assertEquals("{\"@id\":\"http://example.com/person/1234\",\"@type\":\"http://schema.org/Person\",\"http://schema.org/knows\":{\"@id\":\"http://example.com/person/2345\"},\"http://schema.org/name\":\"Example Name\"}", compactContent); + + ObjectMapper objectMapper = new ObjectMapper(); + Person person = objectMapper.readValue(compactContent, Person.class); + + Person expectedPerson = new Person(); + expectedPerson.id = "http://example.com/person/1234"; + expectedPerson.name = "Example Name"; + expectedPerson.knows = new Link(); + expectedPerson.knows.id = "http://example.com/person/2345"; + + assertEquals(expectedPerson.id, person.id); + assertEquals(expectedPerson.name, person.name); + assertEquals(expectedPerson.knows.id, person.knows.id); + } +} diff --git a/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonExamplePerson.java b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/Person.java similarity index 88% rename from json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonExamplePerson.java rename to json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/Person.java index 2e9f38e665..0cb6d43336 100644 --- a/json-2/src/main/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonExamplePerson.java +++ b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/Person.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) -public class JacksonExamplePerson { +public class Person { @JsonProperty("@id") public String id; @JsonProperty("http://schema.org/name") @@ -12,7 +12,7 @@ public class JacksonExamplePerson { @JsonProperty("http://schema.org/knows") public Link knows; - public class Link { + public static class Link { @JsonProperty("@id") public String id; } diff --git a/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationExample.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java similarity index 52% rename from json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationExample.java rename to json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java index 3d3531b0b5..e5d1e35236 100644 --- a/json-2/src/main/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationExample.java +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java @@ -1,8 +1,12 @@ package com.baeldung.jsonld.serialization.hydrajsonld; -import java.io.IOException; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.BeanDescription; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.ObjectMapper; @@ -11,23 +15,36 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.BeanSerializerModifier; import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; +import de.escalon.hypermedia.hydra.mapping.Expose; +import de.escalon.hypermedia.hydra.mapping.Vocab; import de.escalon.hypermedia.hydra.serialize.JacksonHydraSerializer; -public class HydraJsonldSerializationExample { - public static void main(String[] args) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - mapper.registerModule(getJacksonHydraSerializerModule()); +public class HydraJsonldSerializationUnitTest { + @Vocab("http://example.com/vocab/") + @Expose("person") + static class Person { + @JsonProperty("@id") + public String id; + @Expose("fullName") + public String name; + } - HydraJsonldExamplePerson person = new HydraJsonldExamplePerson(); + @Test + void givenAHydraJsonldAnnotatedObject_whenJacksonHydraSerializerIsUsed_thenAJsonLdDocumentIsGenerated() throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(getJacksonHydraSerializerModule()); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + Person person = new Person(); person.id = "http://example.com/person/1234"; person.name = "Example Name"; - System.out.println(mapper.writerWithDefaultPrettyPrinter() - .writeValueAsString(person)); + String personJsonLd = objectMapper.writeValueAsString(person); + + assertEquals("{\"@context\":{\"@vocab\":\"http://example.com/vocab/\",\"name\":\"fullName\"},\"@type\":\"person\",\"name\":\"Example Name\",\"@id\":\"http://example.com/person/1234\"}", personJsonLd); } - public static SimpleModule getJacksonHydraSerializerModule() { + static SimpleModule getJacksonHydraSerializerModule() { return new SimpleModule() { @Override diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java new file mode 100644 index 0000000000..b539c73608 --- /dev/null +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java @@ -0,0 +1,42 @@ +package com.baeldung.jsonld.serialization.jacksonjsonld; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import ioinformarics.oss.jackson.module.jsonld.JsonldModule; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldId; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldLink; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldNamespace; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldProperty; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldResource; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldType; + +public class JacksonJsonLdSerializationUnitTest { + @JsonldResource + @JsonldNamespace(name = "s", uri = "http://schema.org/") + @JsonldType("s:Person") + @JsonldLink(rel = "s:knows", name = "knows", href = "http://example.com/person/2345") + static class Person { + @JsonldId + public String id = "http://example.com/person/1234"; + @JsonldProperty("s:name") + public String name = "Example Name"; + } + + @Test + void givenAJacksonJsonldAnnotatedObject_whenJsonldModuleIsUsed_thenAJsonLdDocumentIsGenerated() throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JsonldModule()); + + Person person = new Person(); + String personJsonLd = objectMapper.writeValueAsString(person); + + assertEquals( + "{\"@type\":\"s:Person\",\"@context\":{\"s\":\"http://schema.org/\",\"name\":\"s:name\",\"knows\":{\"@id\":\"s:knows\",\"@type\":\"@id\"}},\"name\":\"Example Name\",\"@id\":\"http://example.com/person/1234\",\"knows\":\"http://example.com/person/2345\"}", + personJsonLd); + } +} From 793db9f42b2e8cb3fde61072ee8f9a99d633745e Mon Sep 17 00:00:00 2001 From: Anirban Chatterjee Date: Mon, 13 Jul 2020 02:19:13 +0200 Subject: [PATCH 040/309] Added exception handling examples --- .../exceptionhandling/ExceptionHandling.kt | 83 +++++++++++++++++++ .../ExceptionHandlingUnitTest.kt | 46 ++++++++++ 2 files changed, 129 insertions(+) create mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt create mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt new file mode 100644 index 0000000000..137a303edb --- /dev/null +++ b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt @@ -0,0 +1,83 @@ +package com.baeldung.exceptionhandling + +import java.io.IOException + +class ExceptionHandling { + + fun tryCatchBlock(): Int? { + try { + val message = "Welcome to Kotlin Tutorials" + return message.toInt() + } catch (exception: NumberFormatException) { + println("NumberFormatException in the code") + return null + } + } + + fun tryCatchExpression(): Int? { + val number = try { + val message = "Welcome to Kotlin Tutorials" + message.toInt() + } catch (exception: NumberFormatException) { + println("NumberFormatException in the code") + null + } + return number + } + + fun multipleCatchBlock(): Int? { + return try { + val result = 25 / 0 + return result + } catch (exception: NumberFormatException) { + println("NumberFormatException in the code") + null + } catch (exception: ArithmeticException) { + println("ArithmeticException in the code") + null + } catch (exception: Exception) { + println("Exception in the code") + null + } + } + + fun nestedTryCatchBlock(): Int? { + return try { + val firstNumber = 50 / 2 * 0 + try { + val secondNumber = 100 / firstNumber + secondNumber + } catch (exception: ArithmeticException) { + println("ArithmeticException in the code") + null + } + } catch (exception: NumberFormatException) { + println("NumberFormatException in the code") + null + } + } + + fun finallyBlock(): Int? { + return try { + val message = "Welcome to Kotlin Tutorials" + message.toInt() + } catch (exception: NumberFormatException) { + println("NumberFormatException in the code") + null + } finally { + println("In the Finally block") + } + } + + fun throwKeyword() { + val message = "Welcome to Kotlin Tutorials" + if (message.length > 10) throw IllegalArgumentException("String is invalid") + else println("String is valid") + } + + @Throws(IOException::class) + fun throwsAnnotation(): String?{ + val filePath = null + return filePath ?: throw IOException("File path is invalid") + } +} diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt new file mode 100644 index 0000000000..49ad3c38e0 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt @@ -0,0 +1,46 @@ +package com.baeldung.exceptionhandling + +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import java.io.IOException +import kotlin.test.assertNull + +class ExceptionHandlingUnitTest { + + private val classUnderTest: ExceptionHandling = ExceptionHandling() + + @Test + fun givenInvalidConversion_whenTryCatchUsed_thenReturnsCatchBlockValue(){ + assertNull(classUnderTest.tryCatchBlock()) + } + + @Test + fun givenInvalidConversion_whenTryCatchExpressionUsed_thenReturnsCatchBlockValue(){ + assertNull(classUnderTest.tryCatchExpression()) + } + + @Test + fun givenDivisionByZero_whenMultipleCatchUsed_thenReturnsCatchBlockValue(){ + assertNull(classUnderTest.multipleCatchBlock()) + } + + @Test + fun givenDivisionByZero_whenNestedTryCatchUsed_thenReturnsNestedCatchBlockValue(){ + assertNull(classUnderTest.nestedTryCatchBlock()) + } + + @Test + fun givenInvalidConversion_whenTryCatchFinallyUsed_thenReturnsCatchAndFinallyBlock(){ + assertNull(classUnderTest.finallyBlock()) + } + + @Test + fun givenIllegalArgument_whenThrowKeywordUsed_thenThrowsException(){ + assertThrows { classUnderTest.throwKeyword() } + } + + @Test + fun whenAnnotationUsed_thenThrowsException(){ + assertThrows { classUnderTest.throwsAnnotation() } + } +} From 23dbbb579dd55ed73b47f15ea8bc8d45b9c386ba Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Mon, 13 Jul 2020 15:02:13 +0200 Subject: [PATCH 041/309] BAEL-4341 - JUnit test for System.out.println() --- testing-modules/testing-libraries/pom.xml | 15 +++++- .../systemout/SystemOutPrintlnUnitTest.java | 49 +++++++++++++++++++ .../SystemOutPrintlnWithRuleUnitTest.java | 27 ++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnUnitTest.java create mode 100644 testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnWithRuleUnitTest.java diff --git a/testing-modules/testing-libraries/pom.xml b/testing-modules/testing-libraries/pom.xml index 53b58cee17..aa22a5253e 100644 --- a/testing-modules/testing-libraries/pom.xml +++ b/testing-modules/testing-libraries/pom.xml @@ -42,7 +42,18 @@ spring-boot-starter-web 2.2.0.RELEASE - + + com.github.stefanbirkner + system-rules + ${system-rules.version} + test + + + com.github.stefanbirkner + system-lambda + ${system-lambda.version} + test + @@ -90,6 +101,8 @@ 0.4 4.8.0 3.0.0 + 1.19.0 + 1.0.0 diff --git a/testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnUnitTest.java b/testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnUnitTest.java new file mode 100644 index 0000000000..3ffc508fa5 --- /dev/null +++ b/testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnUnitTest.java @@ -0,0 +1,49 @@ +package com.baeldung.systemout; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOut; + +class SystemOutPrintlnUnitTest { + + private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream(); + private final PrintStream standardOut = System.out; + + @BeforeEach + public void setUp() { + System.setOut(new PrintStream(outputStreamCaptor)); + } + + @BeforeEach + public void tearDown() { + System.setOut(standardOut); + } + + @Test + void givenSystemOutRedirection_whenInvokePrintln_thenOutputCaptorSuccess() { + print("Hello Baeldung Readers!!"); + + Assert.assertEquals("Hello Baeldung Readers!!", outputStreamCaptor.toString() + .trim()); + } + + @Test + void givenTapSystemOut_whenInvokePrintln_thenOutputIsReturnedSuccessfully() throws Exception { + + String text = tapSystemOut(() -> { + print("Hello Baeldung Readers!!"); + }); + + Assert.assertEquals("Hello Baeldung Readers!!", text.trim()); + } + + private void print(String output) { + System.out.println(output); + } + +} diff --git a/testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnWithRuleUnitTest.java b/testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnWithRuleUnitTest.java new file mode 100644 index 0000000000..f15b71999e --- /dev/null +++ b/testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnWithRuleUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.systemout; + +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.SystemOutRule; + +public class SystemOutPrintlnWithRuleUnitTest { + + @Rule + public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); + + @Test + public void givenSystemOutRule_whenInvokePrintln_thenLogSuccess() { + print("Hello Baeldung Readers!!"); + + Assert.assertEquals("Hello Baeldung Readers!!", systemOutRule.getLog() + .trim()); + + Assert.assertEquals("Hello Baeldung Readers!!\n", systemOutRule.getLogWithNormalizedLineSeparator()); + } + + private void print(String output) { + System.out.println(output); + } + +} From c5c128033deee4fe152b550d062007c3411915cc Mon Sep 17 00:00:00 2001 From: root Date: Tue, 14 Jul 2020 18:59:16 +0000 Subject: [PATCH 042/309] Code Review BAEL-4302 --- .../com/baeldung/loadedclasslisting/ClassLoaderType.java | 6 ------ .../main/java/com/baeldung/loadedclasslisting/Launcher.java | 5 +---- .../baeldung/loadedclasslisting/ListLoadedClassesAgent.java | 4 ++++ .../loadedclasslisting/customLoader/ClassLoaderInfo.java | 1 - 4 files changed, 5 insertions(+), 11 deletions(-) delete mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ClassLoaderType.java diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ClassLoaderType.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ClassLoaderType.java deleted file mode 100644 index 1111fc21fe..0000000000 --- a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ClassLoaderType.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.loadedclasslisting; - -public enum ClassLoaderType { - - SYSTEM, EXTENSION, BOOTSTRAP, CUSTOM -} diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java index 19c42dfd8d..e1851275c9 100644 --- a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java @@ -3,6 +3,7 @@ package com.baeldung.loadedclasslisting; import java.lang.reflect.Method; import java.util.Arrays; +import com.baeldung.loadedclasslisting.ListLoadedClassesAgent.ClassLoaderType; import com.baeldung.loadedclasslisting.customLoader.ClassLoaderInfo; import com.baeldung.loadedclasslisting.customLoader.CustomClassLoader; @@ -11,13 +12,9 @@ public class Launcher { private static ClassLoader customClassLoader; public static void main(String[] args) { - printClassesLoadedBy(ClassLoaderType.BOOTSTRAP); - printClassesLoadedBy(ClassLoaderType.SYSTEM); - printClassesLoadedBy(ClassLoaderType.EXTENSION); - printClassesLoadedBy(ClassLoaderType.CUSTOM); } diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java index 03907f8b04..8f4b8ebd41 100644 --- a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java @@ -4,6 +4,10 @@ import java.lang.instrument.Instrumentation; public class ListLoadedClassesAgent { + public enum ClassLoaderType { + SYSTEM, EXTENSION, BOOTSTRAP, CUSTOM , PLATFORM + } + private static Instrumentation instrumentation; public static void premain(String agentArgs, Instrumentation instrumentation) { diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java index a787b062d5..2574394c13 100644 --- a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java @@ -5,7 +5,6 @@ import java.util.ArrayList; public class ClassLoaderInfo { public void printClassLoaders() throws ClassNotFoundException { - System.out.println("Classloader of this class:" + ClassLoaderInfo.class.getClassLoader()); System.out.println("Classloader of ArrayList:" + ArrayList.class.getClassLoader()); } From 2c62d0214cc55b32625620bb7223699875138e75 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Wed, 15 Jul 2020 21:40:56 +0530 Subject: [PATCH 043/309] Add files via upload Difference between request.getSession() and request.getSession(true) --- .../WebContent/META-INF/MANIFEST.MF | 3 ++ .../WebContent/WEB-INF/web.xml | 34 +++++++++++++++++++ .../WebContent/index.html | 13 +++++++ .../src/httpsessionexample/FirstServlet.java | 33 ++++++++++++++++++ .../src/httpsessionexample/SecondServlet.java | 31 +++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 spring-session/http-session-example/WebContent/META-INF/MANIFEST.MF create mode 100644 spring-session/http-session-example/WebContent/WEB-INF/web.xml create mode 100644 spring-session/http-session-example/WebContent/index.html create mode 100644 spring-session/http-session-example/src/httpsessionexample/FirstServlet.java create mode 100644 spring-session/http-session-example/src/httpsessionexample/SecondServlet.java diff --git a/spring-session/http-session-example/WebContent/META-INF/MANIFEST.MF b/spring-session/http-session-example/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..5e9495128c --- /dev/null +++ b/spring-session/http-session-example/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/spring-session/http-session-example/WebContent/WEB-INF/web.xml b/spring-session/http-session-example/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000000..6f88776c72 --- /dev/null +++ b/spring-session/http-session-example/WebContent/WEB-INF/web.xml @@ -0,0 +1,34 @@ + + + httpsessionexample + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + + +firstservlet +httpsessionexample.FirstServlet + + + +firstservlet +/firstservlet + + + +secondservlet +httpsessionexample.SecondServlet + + + +secondservlet +/secondservlet + + + + \ No newline at end of file diff --git a/spring-session/http-session-example/WebContent/index.html b/spring-session/http-session-example/WebContent/index.html new file mode 100644 index 0000000000..063d330854 --- /dev/null +++ b/spring-session/http-session-example/WebContent/index.html @@ -0,0 +1,13 @@ + + + + +Insert title here + + +
+Name:

+ +
+ + \ No newline at end of file diff --git a/spring-session/http-session-example/src/httpsessionexample/FirstServlet.java b/spring-session/http-session-example/src/httpsessionexample/FirstServlet.java new file mode 100644 index 0000000000..d49c0f3e14 --- /dev/null +++ b/spring-session/http-session-example/src/httpsessionexample/FirstServlet.java @@ -0,0 +1,33 @@ +package httpsessionexample; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +public class FirstServlet extends HttpServlet { + public void doGet(HttpServletRequest request, HttpServletResponse response) { + try { + HttpSession session = request.getSession(); + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + String name = request.getParameter("userName"); + out.print("Hi " + name); + + session.setAttribute("uname", name); + out.print("
"); + out.print("Session Id : " + session.getId()); + out.print("
"); + out.print("Second Servlet"); + + out.close(); + + } catch (Exception e) { + System.out.println(e); + } + } + +} diff --git a/spring-session/http-session-example/src/httpsessionexample/SecondServlet.java b/spring-session/http-session-example/src/httpsessionexample/SecondServlet.java new file mode 100644 index 0000000000..ab0b9c34ad --- /dev/null +++ b/spring-session/http-session-example/src/httpsessionexample/SecondServlet.java @@ -0,0 +1,31 @@ +package httpsessionexample; + +import java.io.PrintWriter; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +public class SecondServlet extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) { + try { + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + HttpSession session = request.getSession(true); + String name = (String) session.getAttribute("uname"); + out.print("Hi " + name); + out.print("
"); + out.print("Session Id : " + session.getId()); + out.print("
"); + out.close(); + + } catch (Exception e) { + System.out.println(e); + } + } + +} From 26cc3e84d2cf5376fb30b9e9d06a5106fae7cafc Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Wed, 15 Jul 2020 21:48:11 +0530 Subject: [PATCH 044/309] Update README.md Difference Between request.getSession() and request.getSession(true) --- spring-session/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-session/README.md b/spring-session/README.md index 65040ec734..05343f67c2 100644 --- a/spring-session/README.md +++ b/spring-session/README.md @@ -6,3 +6,4 @@ This module contains articles about Spring Session - [Guide to Spring Session](https://www.baeldung.com/spring-session) - [Spring Session with JDBC](https://www.baeldung.com/spring-session-jdbc) - [Spring Session with MongoDB](https://www.baeldung.com/spring-session-mongodb) +- [Difference Between request.getSession() and request.getSession(true)](http://inprogress.baeldung.com/?p=215685&preview=true) From 8a76711fb522814c9f0e862f9692565b1885d0cc Mon Sep 17 00:00:00 2001 From: Anirban Chatterjee Date: Thu, 16 Jul 2020 00:38:26 +0200 Subject: [PATCH 045/309] Minor code refinement --- .../com/baeldung/exceptionhandling/ExceptionHandling.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt index 137a303edb..225a1339e2 100644 --- a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt +++ b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt @@ -28,7 +28,7 @@ class ExceptionHandling { fun multipleCatchBlock(): Int? { return try { val result = 25 / 0 - return result + result } catch (exception: NumberFormatException) { println("NumberFormatException in the code") null @@ -69,10 +69,10 @@ class ExceptionHandling { } } - fun throwKeyword() { + fun throwKeyword(): Int { val message = "Welcome to Kotlin Tutorials" if (message.length > 10) throw IllegalArgumentException("String is invalid") - else println("String is valid") + else return message.length } @Throws(IOException::class) From 9e03b89e699d9dc567af844157dc9307fe3f8329 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Wed, 15 Jul 2020 20:53:23 -0400 Subject: [PATCH 046/309] BAEL-4007 Add jpa data equality unit test specs --- persistence-modules/java-jpa-3/README.md | 3 + persistence-modules/java-jpa-3/pom.xml | 139 ++++++++++++++++++ .../jpa/equality/EqualByBusinessKey.java | 54 +++++++ .../com/baeldung/jpa/equality/EqualById.java | 54 +++++++ .../jpa/equality/EqualByJavaDefault.java | 38 +++++ .../main/resources/META-INF/persistence.xml | 25 ++++ .../java-jpa-3/src/main/resources/logback.xml | 15 ++ .../jpa/equality/EqualityUnitTest.java | 74 ++++++++++ 8 files changed, 402 insertions(+) create mode 100644 persistence-modules/java-jpa-3/README.md create mode 100644 persistence-modules/java-jpa-3/pom.xml create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java create mode 100644 persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java create mode 100644 persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml create mode 100644 persistence-modules/java-jpa-3/src/main/resources/logback.xml create mode 100644 persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java diff --git a/persistence-modules/java-jpa-3/README.md b/persistence-modules/java-jpa-3/README.md new file mode 100644 index 0000000000..01fdf05b53 --- /dev/null +++ b/persistence-modules/java-jpa-3/README.md @@ -0,0 +1,3 @@ +## JPA in Java + +This module contains articles about the Java Persistence API (JPA) in Java. diff --git a/persistence-modules/java-jpa-3/pom.xml b/persistence-modules/java-jpa-3/pom.xml new file mode 100644 index 0000000000..562f337215 --- /dev/null +++ b/persistence-modules/java-jpa-3/pom.xml @@ -0,0 +1,139 @@ + + + 4.0.0 + java-jpa-3 + java-jpa-3 + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.hibernate + hibernate-jpamodelgen + ${hibernate.version} + + + com.h2database + h2 + ${h2.version} + + + + + javax.persistence + javax.persistence-api + ${javax.persistence-api.version} + + + + + org.eclipse.persistence + eclipselink + ${eclipselink.version} + runtime + + + org.postgresql + postgresql + ${postgres.version} + runtime + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + -proc:none + + + + org.bsc.maven + maven-processor-plugin + ${maven-processor-plugin.version} + + + process + + process + + generate-sources + + target/metamodel + + org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + ${build-helper-maven-plugin.version} + + + add-source + generate-sources + + add-source + + + + target/metamodel + ${project.build.directory}/generated-sources/java/ + + + + + + + com.mysema.maven + apt-maven-plugin + 1.1.3 + + + + process + + + target/generated-sources/java + com.querydsl.apt.jpa.JPAAnnotationProcessor + + + + + + + + + 5.4.14.Final + 2.7.4 + 42.2.5 + 2.2 + 3.11.1 + 3.5.1 + 3.3.3 + 3.0.0 + + + diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java new file mode 100644 index 0000000000..3e34f97d77 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java @@ -0,0 +1,54 @@ +package com.baeldung.jpa.equality; + +import javax.persistence.*; + +@Entity +public class EqualByBusinessKey { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String email; + + public EqualByBusinessKey() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((email == null) ? 0 : email.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (obj instanceof EqualByBusinessKey) + if (((EqualByBusinessKey) obj).getEmail() == getEmail()) + return true; + + return false; + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java new file mode 100644 index 0000000000..f29a152f3e --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java @@ -0,0 +1,54 @@ +package com.baeldung.jpa.equality; + +import javax.persistence.*; + +@Entity +public class EqualById { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String email; + + public EqualById() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (obj instanceof EqualById) + return ((EqualById) obj).getId() == getId(); + + return false; + } + +} diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java new file mode 100644 index 0000000000..04a81865c6 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java @@ -0,0 +1,38 @@ +package com.baeldung.jpa.equality; + +import javax.persistence.*; + +@Entity +public class EqualByJavaDefault implements Cloneable{ + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String email; + + public EqualByJavaDefault() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Object clone() throws + CloneNotSupportedException + { + return super.clone(); + } +} diff --git a/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..28a929f912 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,25 @@ + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.equality.EqualByJavaDefault + com.baeldung.jpa.equality.EqualById + com.baeldung.jpa.equality.EqualByBusinessKey + true + + + + + + + + + + + + + diff --git a/persistence-modules/java-jpa-3/src/main/resources/logback.xml b/persistence-modules/java-jpa-3/src/main/resources/logback.xml new file mode 100644 index 0000000000..2527fea245 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/main/resources/logback.xml @@ -0,0 +1,15 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - + %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java new file mode 100644 index 0000000000..c672c9e460 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.jpa.equality; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +public class EqualityUnitTest { + + private static EntityManagerFactory factory; + private static EntityManager entityManager; + + @BeforeClass + public static void setup() { + factory = Persistence.createEntityManagerFactory("jpa-h2-equality"); + entityManager = factory.createEntityManager(); + } + + @Test + public void givenObjectBasedEquality_whenUsingEquals_thenEqualIsBasedOnInstance() throws CloneNotSupportedException { + EqualByJavaDefault object1 = new EqualByJavaDefault(); + EqualByJavaDefault object2 = new EqualByJavaDefault(); + + object1.setEmail("test.user@domain.com"); + + entityManager.getTransaction().begin(); + entityManager.persist(object1); + entityManager.getTransaction().commit(); + + object2 = (EqualByJavaDefault) object1.clone(); + + Assert.assertNotEquals(object1, object2); + Assert.assertEquals(object1.getId(), object2.getId()); + Assert.assertEquals(object1.getEmail(), object2.getEmail()); + } + + @Test + public void givenIdBasedEquality_whenUsingEquals_thenEqualIsBasedOnId() { + EqualById object1 = new EqualById(); + EqualById object2 = new EqualById(); + + object1.setEmail("test.user.1@domain.com"); + object2.setEmail("test.user.2@domain.com"); + + entityManager.getTransaction().begin(); + entityManager.persist(object1); + entityManager.getTransaction().commit(); + + object2.setId(object1.getId()); + + Assert.assertEquals(object1, object2); + Assert.assertEquals(object1.getId(), object2.getId()); + Assert.assertNotEquals(object1.getEmail(), object2.getEmail()); + } + + @Test + public void givenBusinessKeyBasedEquality_whenUsingEquals_thenEqualIsBasedOnBusinessKey() { + EqualByBusinessKey object1 = new EqualByBusinessKey(); + EqualByBusinessKey object2 = new EqualByBusinessKey(); + + object1.setEmail("test.user@test-domain.com"); + object2.setEmail("test.user@test-domain.com"); + + entityManager.getTransaction().begin(); + entityManager.persist(object1); + entityManager.getTransaction().commit(); + + Assert.assertEquals(object1, object2); + Assert.assertNotEquals(object1.getId(), object2.getId()); + } +} \ No newline at end of file From 1ba39d1b95e0d6984903a2f8755d2c1026e1fa7b Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Wed, 15 Jul 2020 21:16:31 -0400 Subject: [PATCH 047/309] Remove heagonal architecture --- architecture/README.md | 3 -- architecture/pom.xml | 33 ------------ .../HexagonalArchitectureTaskApplication.java | 12 ----- .../application/task/AddNewDailyTask.java | 29 ---------- .../application/task/AddNewTask.java | 22 -------- .../application/task/GetTasks.java | 22 -------- .../commands/task/CreateTask.java | 7 --- .../commands/task/GetAllTasks.java | 7 --- .../architecture/domain/task/Task.java | 53 ------------------- .../domain/task/TaskRepository.java | 7 --- .../architecture/domain/task/TaskService.java | 22 -------- .../framework/cli/StartupRunner.java | 24 --------- .../http/task/TaskApiController.java | 42 --------------- .../framework/http/task/TaskRequest.java | 28 ---------- 14 files changed, 311 deletions(-) delete mode 100644 architecture/README.md delete mode 100644 architecture/pom.xml delete mode 100644 architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java delete mode 100644 architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java diff --git a/architecture/README.md b/architecture/README.md deleted file mode 100644 index be093f25ed..0000000000 --- a/architecture/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant articles - -- [A Quick and Practical Example of Hexagonal Architecture in Java](https://www.baeldung.com/a-quick-and-practical-example-of-hexagonal-architecture-in-java-3/) diff --git a/architecture/pom.xml b/architecture/pom.xml deleted file mode 100644 index 4ad104293e..0000000000 --- a/architecture/pom.xml +++ /dev/null @@ -1,33 +0,0 @@ - - 4.0.0 - com.baeldung.architecture - architecture - 0.0.1-SNAPSHOT - architecture - jar - A Quick and Practical Example of Hexagonal Architecture in Java - - - parent-boot-2 - com.baeldung - 0.0.1-SNAPSHOT - ../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-starter-web - - - diff --git a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java b/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java deleted file mode 100644 index 69c6f4b276..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/HexagonalArchitectureTaskApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.architecture; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class HexagonalArchitectureTaskApplication { - public static void main(String[] args) { - SpringApplication.run(HexagonalArchitectureTaskApplication.class, args); - } - -} diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java deleted file mode 100644 index f9ee97542c..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewDailyTask.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.architecture.application.task; - -import java.time.Instant; -import java.time.temporal.ChronoUnit; - -import com.baeldung.architecture.commands.task.CreateTask; -import com.baeldung.architecture.domain.task.Task; - -import org.springframework.stereotype.Component; - -@Component -public class AddNewDailyTask implements CreateTask { - - private AddNewTask addNewTask; - - public AddNewDailyTask(AddNewTask addNewTask) { - this.addNewTask = addNewTask; - } - - @Override - public void create(Task newTask) { - Instant initialDueDate = newTask.getDueDate(); - String description = newTask.getDescription(); - for (int i = 1; i <= 5; i++) { - Task task = new Task(initialDueDate.plus(i, ChronoUnit.DAYS), description); - addNewTask.create(task); - } - } -} diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java b/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java deleted file mode 100644 index 70638378f9..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/AddNewTask.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.architecture.application.task; - -import com.baeldung.architecture.domain.task.Task; -import com.baeldung.architecture.domain.task.TaskService; -import com.baeldung.architecture.commands.task.*; - -import org.springframework.stereotype.Component; - -@Component -public class AddNewTask implements CreateTask { - - private TaskService taskService; - - public AddNewTask(TaskService taskService) { - this.taskService = taskService; - } - - @Override - public void create(Task newTask) { - taskService.createTask(newTask); - } -} diff --git a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java b/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java deleted file mode 100644 index c876f7de85..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/application/task/GetTasks.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.architecture.application.task; - -import com.baeldung.architecture.domain.task.Task; -import com.baeldung.architecture.domain.task.TaskService; -import com.baeldung.architecture.commands.task.*; - -import org.springframework.stereotype.Component; - -@Component -public class GetTasks implements GetAllTasks { - - private TaskService taskService; - - public GetTasks(TaskService taskService) { - this.taskService = taskService; - } - - @Override - public Iterable getAll() { - return taskService.getAllTasks(); - } -} diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java deleted file mode 100644 index ec60868a22..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/commands/task/CreateTask.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.architecture.commands.task; - -import com.baeldung.architecture.domain.task.Task; - -public interface CreateTask { - public void create(Task newTask); -} diff --git a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java b/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java deleted file mode 100644 index c9aa1be5f8..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/commands/task/GetAllTasks.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.architecture.commands.task; - -import com.baeldung.architecture.domain.task.Task; - -public interface GetAllTasks { - public Iterable getAll(); -} diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java deleted file mode 100644 index 240dc33571..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/domain/task/Task.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.architecture.domain.task; - -import java.time.Instant; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class Task { - @Id - @GeneratedValue(strategy=GenerationType.AUTO) - private Long id; - private Instant dueDate = Instant.now(); - private String description; - - public Task() {} - - public Task(Instant dueDate, String description) { - this.dueDate = dueDate; - this.description = description; - } - - public Task(Long id, Instant dueDate, String description) { - this(dueDate, description); - this.id = id; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Instant getDueDate() { - return dueDate; - } - - public void setDueDate(Instant dueDate) { - this.dueDate = dueDate; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } -} diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java deleted file mode 100644 index d896212714..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.architecture.domain.task; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface TaskRepository extends CrudRepository {}; diff --git a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java b/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java deleted file mode 100644 index 11ef0f3e19..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/domain/task/TaskService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.architecture.domain.task; - -import org.springframework.stereotype.Service; - -@Service -public class TaskService { - - private TaskRepository taskRepository; - - public TaskService(TaskRepository taskRepository) { - this.taskRepository = taskRepository; - } - - public void createTask(Task task) { - taskRepository.save(task); - } - - public Iterable getAllTasks() { - return taskRepository.findAll(); - } - -} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java b/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java deleted file mode 100644 index 449bc9386e..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/framework/cli/StartupRunner.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.architecture.framework.cli; - -import com.baeldung.architecture.application.task.AddNewDailyTask; -import com.baeldung.architecture.domain.task.Task; - -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.stereotype.Component; - -@Component -public class StartupRunner implements ApplicationRunner { - - AddNewDailyTask addNewDailyTask; - - public StartupRunner(AddNewDailyTask addNewDailyTask) { - this.addNewDailyTask = addNewDailyTask; - } - @Override - public void run(ApplicationArguments args) throws Exception { - Task task = new Task(); - task.setDescription("Startup Task"); - addNewDailyTask.create(task); - } -} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java deleted file mode 100644 index 87a8f5fe4b..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskApiController.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.architecture.framework.http.task; - -import java.time.Instant; - -import com.baeldung.architecture.application.task.AddNewTask; -import com.baeldung.architecture.application.task.GetTasks; -import com.baeldung.architecture.domain.task.Task; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("task") -public class TaskApiController { - - private AddNewTask addNewTask; - private GetTasks getTasks; - - public TaskApiController( - AddNewTask addNewTask, - GetTasks getTasks - ) { - this.addNewTask = addNewTask; - this.getTasks = getTasks; - } - - @GetMapping - Iterable listTasks() { - return getTasks.getAll(); - } - - @PostMapping(consumes = "application/json", produces = "application/json") - void createTask(@RequestBody TaskRequest taskRequest) { - Task task = new Task(); - task.setDescription(taskRequest.getDescription()); - task.setDueDate(Instant.parse(taskRequest.getDueDate())); - addNewTask.create(task); - } -} diff --git a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java b/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java deleted file mode 100644 index 70b98a32f9..0000000000 --- a/architecture/src/main/java/com/baeldung/architecture/framework/http/task/TaskRequest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.architecture.framework.http.task; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -public class TaskRequest { - @JsonInclude(Include.NON_NULL) - private String description; - - @JsonInclude(Include.NON_NULL) - private String dueDate; - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getDueDate() { - return dueDate; - } - - public void setDueDate(String dueDate) { - this.dueDate = dueDate; - } -} From 176fc37a4479fe5d7d85bc761b362faaf241378e Mon Sep 17 00:00:00 2001 From: Loredana Date: Fri, 17 Jul 2020 09:33:34 +0300 Subject: [PATCH 048/309] JAVA-2096 remove unused dependencies --- core-java-modules/core-java-io-3/pom.xml | 27 ------------------------ 1 file changed, 27 deletions(-) diff --git a/core-java-modules/core-java-io-3/pom.xml b/core-java-modules/core-java-io-3/pom.xml index cb341ca2ae..cc4dca5fa5 100644 --- a/core-java-modules/core-java-io-3/pom.xml +++ b/core-java-modules/core-java-io-3/pom.xml @@ -46,41 +46,14 @@ ${assertj.version} test - - - com.github.tomakehurst - wiremock - ${wiremock.version} - test - - core-java-io-3 - - - src/main/resources - true - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - ${maven.compiler.source} - ${maven.compiler.target} - - - 3.6.1 - 3.0.0-M1 - 2.26.3 \ No newline at end of file From 3802825c6117bb4aa1a76f3ff31b3add9db5fc6b Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 12:57:33 +0530 Subject: [PATCH 049/309] Delete pom.xml --- bookstore/pom.xml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 bookstore/pom.xml diff --git a/bookstore/pom.xml b/bookstore/pom.xml deleted file mode 100644 index 68286076e5..0000000000 --- a/bookstore/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - 4.0.0 - com.hexagonal - bookstore - 0.0.1-SNAPSHOT - - - 1.8 - - - - org.springframework.boot - spring-boot-starter-parent - 2.3.1.RELEASE - - - - - org.springframework.boot - spring-boot-starter-web - - - \ No newline at end of file From d578a7585ef77aa6598d18a0902a9d539360cf4f Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 12:57:50 +0530 Subject: [PATCH 050/309] Delete MainApp.java --- bookstore/src/main/java/com/hexagonal/MainApp.java | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 bookstore/src/main/java/com/hexagonal/MainApp.java diff --git a/bookstore/src/main/java/com/hexagonal/MainApp.java b/bookstore/src/main/java/com/hexagonal/MainApp.java deleted file mode 100644 index 0d6ef861b3..0000000000 --- a/bookstore/src/main/java/com/hexagonal/MainApp.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.hexagonal; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; - -@SpringBootApplication -public class MainApp { - public static void main(String[] args) { - SpringApplication.run(MainApp.class, args); - } - -} \ No newline at end of file From de2955f4b39edd9a2ef80ca0bcdb5aabcef1a172 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 12:58:07 +0530 Subject: [PATCH 051/309] Delete BookController.java --- .../hexagonal/controller/BookController.java | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 bookstore/src/main/java/com/hexagonal/controller/BookController.java diff --git a/bookstore/src/main/java/com/hexagonal/controller/BookController.java b/bookstore/src/main/java/com/hexagonal/controller/BookController.java deleted file mode 100644 index 7e525deaa1..0000000000 --- a/bookstore/src/main/java/com/hexagonal/controller/BookController.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.hexagonal.controller; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -import com.hexagonal.domain.Book; -import com.hexagonal.service.BookService; - -@RestController -public class BookController { - - @Autowired - private BookService bookService; - - @RequestMapping("/book/add") - @PostMapping(produces = { MediaType.TEXT_PLAIN_VALUE }) - public void addBook(@RequestBody Book book) { - bookService.addBook(book); - } - - public Book buyBook(@PathVariable String isbn) { - return bookService.buyBook(isbn); - } - - public List listBooks() { - return bookService.listBooks(); - } - -} From d7a9fe81f9457a849cca901e4fba5d56c516213b Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 12:58:24 +0530 Subject: [PATCH 052/309] Delete Book.java --- .../main/java/com/hexagonal/domain/Book.java | 38 ------------------- 1 file changed, 38 deletions(-) delete mode 100644 bookstore/src/main/java/com/hexagonal/domain/Book.java diff --git a/bookstore/src/main/java/com/hexagonal/domain/Book.java b/bookstore/src/main/java/com/hexagonal/domain/Book.java deleted file mode 100644 index 84125391cc..0000000000 --- a/bookstore/src/main/java/com/hexagonal/domain/Book.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.hexagonal.domain; - -public class Book { - - private String name; - private String isbn; - private String author; - - @Override - public String toString() { - return "Book [name=" + name + ", ISBN=" + isbn + ", author=" + author + "]"; - } - - public String getIsbn() { - return isbn; - } - - public void setIsbn(String isbn) { - this.isbn = isbn; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - -} From fc717bb9f173d3f5e82fcef9c5ddde8e6fe1971a Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 12:58:40 +0530 Subject: [PATCH 053/309] Delete BookRepository.java --- .../com/hexagonal/repository/BookRepository.java | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 bookstore/src/main/java/com/hexagonal/repository/BookRepository.java diff --git a/bookstore/src/main/java/com/hexagonal/repository/BookRepository.java b/bookstore/src/main/java/com/hexagonal/repository/BookRepository.java deleted file mode 100644 index 1e64a2d21b..0000000000 --- a/bookstore/src/main/java/com/hexagonal/repository/BookRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hexagonal.repository; - -import java.util.List; - -import com.hexagonal.domain.Book; - -public interface BookRepository { - - public void add(Book book); - - public Book buy(String isbn); - - public List list(); - -} From d600c40573a71db98d0c5a399201df0ec65f35b5 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 12:58:51 +0530 Subject: [PATCH 054/309] Delete BookRepositoryImpl.java --- .../repository/BookRepositoryImpl.java | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 bookstore/src/main/java/com/hexagonal/repository/BookRepositoryImpl.java diff --git a/bookstore/src/main/java/com/hexagonal/repository/BookRepositoryImpl.java b/bookstore/src/main/java/com/hexagonal/repository/BookRepositoryImpl.java deleted file mode 100644 index f4f99583dd..0000000000 --- a/bookstore/src/main/java/com/hexagonal/repository/BookRepositoryImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.hexagonal.repository; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.springframework.stereotype.Repository; - -import com.hexagonal.domain.Book; - -@Repository -public class BookRepositoryImpl implements BookRepository { - - private Map bookMap = new HashMap<>(); - - @Override - public void add(Book book) { - bookMap.put(book.getIsbn(), book); - System.out.println("Book Added " + book); - } - - @Override - public Book buy(String isbn) { - return bookMap.get(isbn); - } - - @Override - public List list() { - return bookMap.values() - .stream() - .collect(Collectors.toList()); - } - -} From c7b9e81e15ad40ebc5fbfa803d3b2e0e5574de9c Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 12:59:07 +0530 Subject: [PATCH 055/309] Delete BookService.java --- .../java/com/hexagonal/service/BookService.java | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 bookstore/src/main/java/com/hexagonal/service/BookService.java diff --git a/bookstore/src/main/java/com/hexagonal/service/BookService.java b/bookstore/src/main/java/com/hexagonal/service/BookService.java deleted file mode 100644 index cb5e1a930e..0000000000 --- a/bookstore/src/main/java/com/hexagonal/service/BookService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hexagonal.service; - -import java.util.List; - -import com.hexagonal.domain.Book; - -public interface BookService { - - public void addBook(Book book); - - public Book buyBook(String isbn); - - public List listBooks(); - -} From 8cdfb5b0efcd3789807a82d3ff793e341ff6081f Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 12:59:18 +0530 Subject: [PATCH 056/309] Delete BookServiceImpl.java --- .../hexagonal/service/BookServiceImpl.java | 35 ------------------- 1 file changed, 35 deletions(-) delete mode 100644 bookstore/src/main/java/com/hexagonal/service/BookServiceImpl.java diff --git a/bookstore/src/main/java/com/hexagonal/service/BookServiceImpl.java b/bookstore/src/main/java/com/hexagonal/service/BookServiceImpl.java deleted file mode 100644 index c7e660ea36..0000000000 --- a/bookstore/src/main/java/com/hexagonal/service/BookServiceImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.hexagonal.service; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.hexagonal.domain.Book; -import com.hexagonal.repository.BookRepository; - -@Service -public class BookServiceImpl implements BookService { - - @Autowired - private BookRepository bookRepository; - - @Override - public void addBook(Book book) { - bookRepository.add(book); - - } - - @Override - public Book buyBook(String isbn) { - - return bookRepository.buy(isbn); - } - - @Override - public List listBooks() { - - return bookRepository.list(); - } - -} From 52ff90ee1aebf36b2058d60e1b516f50993a7226 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 13:00:40 +0530 Subject: [PATCH 057/309] Update pom.xml --- spring-session/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-session/pom.xml b/spring-session/pom.xml index 8388efb6c3..d5dbe28a2b 100644 --- a/spring-session/pom.xml +++ b/spring-session/pom.xml @@ -19,6 +19,7 @@ spring-session-jdbc spring-session-redis spring-session-mongodb + http-session-example - \ No newline at end of file + From 65b6b29ea1e52c666ef764449e1baa0b4d96022d Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 13:01:48 +0530 Subject: [PATCH 058/309] Update README.md --- spring-session/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-session/README.md b/spring-session/README.md index 05343f67c2..47125a6032 100644 --- a/spring-session/README.md +++ b/spring-session/README.md @@ -6,4 +6,4 @@ This module contains articles about Spring Session - [Guide to Spring Session](https://www.baeldung.com/spring-session) - [Spring Session with JDBC](https://www.baeldung.com/spring-session-jdbc) - [Spring Session with MongoDB](https://www.baeldung.com/spring-session-mongodb) -- [Difference Between request.getSession() and request.getSession(true)](http://inprogress.baeldung.com/?p=215685&preview=true) +- Difference Between request.getSession() and request.getSession(true) From 6d59756a7d0b2809640dc350fa334ce58986eda9 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 13:02:41 +0530 Subject: [PATCH 059/309] Update web.xml --- .../http-session-example/WebContent/WEB-INF/web.xml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spring-session/http-session-example/WebContent/WEB-INF/web.xml b/spring-session/http-session-example/WebContent/WEB-INF/web.xml index 6f88776c72..01b1b6f308 100644 --- a/spring-session/http-session-example/WebContent/WEB-INF/web.xml +++ b/spring-session/http-session-example/WebContent/WEB-INF/web.xml @@ -3,11 +3,6 @@ httpsessionexample index.html - index.htm - index.jsp - default.html - default.htm - default.jsp @@ -31,4 +26,4 @@ - \ No newline at end of file + From a8fc50e9b23c9bae382789f82bceea2208b9220c Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Fri, 17 Jul 2020 13:03:14 +0530 Subject: [PATCH 060/309] Delete MANIFEST.MF --- .../http-session-example/WebContent/META-INF/MANIFEST.MF | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 spring-session/http-session-example/WebContent/META-INF/MANIFEST.MF diff --git a/spring-session/http-session-example/WebContent/META-INF/MANIFEST.MF b/spring-session/http-session-example/WebContent/META-INF/MANIFEST.MF deleted file mode 100644 index 5e9495128c..0000000000 --- a/spring-session/http-session-example/WebContent/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Class-Path: - From be1f906a9a9217a7eecf612c849eac4a851db135 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Fri, 17 Jul 2020 10:54:38 +0200 Subject: [PATCH 061/309] [BAEL4288] initial commit --- persistence-modules/flyway-repair/README.MD | 3 + .../flyway-repair/docker-compose/.env | 2 + .../docker-compose/docker-compose.yaml | 23 ++++ .../flyway-repair/docker-compose/mysql.env | 5 + .../flyway-repair/docker-compose/postgres.env | 3 + persistence-modules/flyway-repair/pom.xml | 105 ++++++++++++++++++ .../flywaycallbacks/FlywayApplication.java | 13 +++ .../application-callbacks.properties | 1 + .../main/resources/application-h2.properties | 3 + .../resources/application-mysql.properties | 3 + .../resources/application-postgres.properties | 3 + .../src/main/resources/application.properties | 6 + .../db/callbacks/afterMigrateError.sql | 1 + .../db/migration/V1_0__add_table_one.sql | 3 + .../db/migration/V1_1__add_table_two.sql | 3 + .../db/migration/V1_2__add_table_three.sql | 3 + .../db/migration/V1_3__add_table.sql | 3 + .../src/main/resources/logback.xml | 19 ++++ 18 files changed, 202 insertions(+) create mode 100644 persistence-modules/flyway-repair/README.MD create mode 100644 persistence-modules/flyway-repair/docker-compose/.env create mode 100644 persistence-modules/flyway-repair/docker-compose/docker-compose.yaml create mode 100644 persistence-modules/flyway-repair/docker-compose/mysql.env create mode 100644 persistence-modules/flyway-repair/docker-compose/postgres.env create mode 100644 persistence-modules/flyway-repair/pom.xml create mode 100644 persistence-modules/flyway-repair/src/main/java/com/baeldung/flywaycallbacks/FlywayApplication.java create mode 100644 persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties create mode 100644 persistence-modules/flyway-repair/src/main/resources/application-h2.properties create mode 100644 persistence-modules/flyway-repair/src/main/resources/application-mysql.properties create mode 100644 persistence-modules/flyway-repair/src/main/resources/application-postgres.properties create mode 100644 persistence-modules/flyway-repair/src/main/resources/application.properties create mode 100644 persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql create mode 100644 persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql create mode 100644 persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql create mode 100644 persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql create mode 100644 persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql create mode 100644 persistence-modules/flyway-repair/src/main/resources/logback.xml diff --git a/persistence-modules/flyway-repair/README.MD b/persistence-modules/flyway-repair/README.MD new file mode 100644 index 0000000000..daeb9012b5 --- /dev/null +++ b/persistence-modules/flyway-repair/README.MD @@ -0,0 +1,3 @@ +### Relevant Articles: +- [Database Migrations with Flyway](http://www.baeldung.com/database-migrations-with-flyway) +- [A Guide to Flyway Callbacks](http://www.baeldung.com/flyway-callbacks) diff --git a/persistence-modules/flyway-repair/docker-compose/.env b/persistence-modules/flyway-repair/docker-compose/.env new file mode 100644 index 0000000000..52bd0d6510 --- /dev/null +++ b/persistence-modules/flyway-repair/docker-compose/.env @@ -0,0 +1,2 @@ +MYSQL_PORT=3316 +POSTGRES_PORT=5431 \ No newline at end of file diff --git a/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml new file mode 100644 index 0000000000..23270c043d --- /dev/null +++ b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml @@ -0,0 +1,23 @@ +version: '3.0' + +services: + mysql-test: + image: mysql:8.0.17 + ports: + - ${MYSQL_PORT}:3306 + env_file: + - mysql.env + networks: + - baeldung + + postgres-test: + image: postgres:11.5 + ports: + - ${POSTGRES_PORT}:5432 + env_file: postgres.env + networks: + - baeldung + +networks: + baeldung: + driver: bridge \ No newline at end of file diff --git a/persistence-modules/flyway-repair/docker-compose/mysql.env b/persistence-modules/flyway-repair/docker-compose/mysql.env new file mode 100644 index 0000000000..597344d88c --- /dev/null +++ b/persistence-modules/flyway-repair/docker-compose/mysql.env @@ -0,0 +1,5 @@ +MYSQL_ROOT_PASSWORD=password +MYSQL_RANDOM_ROOT_PASSWORD=yes +MYSQL_USER=testuser +MYSQL_PASSWORD=password +MYSQL_DATABASE=testdb \ No newline at end of file diff --git a/persistence-modules/flyway-repair/docker-compose/postgres.env b/persistence-modules/flyway-repair/docker-compose/postgres.env new file mode 100644 index 0000000000..1e7373fdf0 --- /dev/null +++ b/persistence-modules/flyway-repair/docker-compose/postgres.env @@ -0,0 +1,3 @@ +POSTGRES_USER=testuser +POSTGRES_PASSWORD=password +POSTGRES_DB=testdb diff --git a/persistence-modules/flyway-repair/pom.xml b/persistence-modules/flyway-repair/pom.xml new file mode 100644 index 0000000000..f9d62d5dad --- /dev/null +++ b/persistence-modules/flyway-repair/pom.xml @@ -0,0 +1,105 @@ + + + 4.0.0 + flyway + flyway-repair + jar + Flyway Repair Demo + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.flywaydb + flyway-core + ${flyway-core.version} + + + org.springframework.boot + spring-boot-starter-jdbc + + + + + + + org.flywaydb + flyway-maven-plugin + ${flyway-maven-plugin.version} + + + org.springframework.boot + spring-boot-maven-plugin + + + + + true + src/main/resources + + *.properties + db/**/*.sql + + + + + + + 6.5.0 + 6.5.0 + src/main/resources/application-${db.engine}.properties + + + + + + h2 + + h2 + + + + com.h2database + h2 + runtime + + + + + + mysql + + mysql + + + + mysql + mysql-connector-java + runtime + + + + + + postgres + + postgres + + + + org.postgresql + postgresql + runtime + + + + + + + diff --git a/persistence-modules/flyway-repair/src/main/java/com/baeldung/flywaycallbacks/FlywayApplication.java b/persistence-modules/flyway-repair/src/main/java/com/baeldung/flywaycallbacks/FlywayApplication.java new file mode 100644 index 0000000000..34d794f7d1 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/java/com/baeldung/flywaycallbacks/FlywayApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.flywaycallbacks; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FlywayApplication { + + public static void main(String[] args) { + SpringApplication.run(FlywayApplication.class, args); + } + +} diff --git a/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties new file mode 100644 index 0000000000..2c10fc711f --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties @@ -0,0 +1 @@ +flyway.locations=db/migration,db/callbacks \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application-h2.properties b/persistence-modules/flyway-repair/src/main/resources/application-h2.properties new file mode 100644 index 0000000000..15bd482adf --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/application-h2.properties @@ -0,0 +1,3 @@ +flyway.url=jdbc:h2:file:./testdb;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;MODE=MySQL;DATABASE_TO_UPPER=false; +flyway.user=testuser +flyway.password=password \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties b/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties new file mode 100644 index 0000000000..341f978068 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties @@ -0,0 +1,3 @@ +flyway.url=jdbc:mysql://127.0.0.1:3316/testdb +flyway.user=testuser +flyway.password=password \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties b/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties new file mode 100644 index 0000000000..5afaca96b5 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties @@ -0,0 +1,3 @@ +flyway.url=jdbc:postgresql://127.0.0.1:5431/testdb +flyway.user=testuser +flyway.password=password \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application.properties b/persistence-modules/flyway-repair/src/main/resources/application.properties new file mode 100644 index 0000000000..3fae835eb1 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.profiles.include=@db.engine@ + +spring.datasource.url=${flyway.url} +spring.datasource.username=${flyway.user} +spring.datasource.password=${flyway.password} +spring.flyway.locations=${flyway.locations:db/migration} \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql b/persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql new file mode 100644 index 0000000000..c975e85056 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql @@ -0,0 +1 @@ +DELETE FROM flyway_schema_history WHERE success=false; \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql new file mode 100644 index 0000000000..ec434dd5b2 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql @@ -0,0 +1,3 @@ +create table table_one ( + id numeric primary key +); \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql new file mode 100644 index 0000000000..48720d59d6 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql @@ -0,0 +1,3 @@ +create table table_two ( + id numeric primary key +); \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql new file mode 100644 index 0000000000..1917c88b9b --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql @@ -0,0 +1,3 @@ +create table table_three ( + id numeric primary key +); \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql new file mode 100644 index 0000000000..ec434dd5b2 --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql @@ -0,0 +1,3 @@ +create table table_one ( + id numeric primary key +); \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/logback.xml b/persistence-modules/flyway-repair/src/main/resources/logback.xml new file mode 100644 index 0000000000..56af2d397e --- /dev/null +++ b/persistence-modules/flyway-repair/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + \ No newline at end of file From 2923bae61f2704b707f0a8e7b266e0b2c7c99aad Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 17 Jul 2020 13:12:36 +0200 Subject: [PATCH 062/309] JAVA-1634: Get rid of the overriden spring-boot.version property --- spring-cloud/spring-cloud-openfeign/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-cloud/spring-cloud-openfeign/pom.xml b/spring-cloud/spring-cloud-openfeign/pom.xml index df529d7fb1..c1f3f2dc30 100644 --- a/spring-cloud/spring-cloud-openfeign/pom.xml +++ b/spring-cloud/spring-cloud-openfeign/pom.xml @@ -51,8 +51,7 @@ - 2.0.1.RELEASE - Finchley.SR2 + Hoxton.SR6 From 8a98cce3db70202418486de4962e32eaaf5c6ed9 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Fri, 17 Jul 2020 15:13:57 +0200 Subject: [PATCH 063/309] [BAEL4288] remove mysql flow --- .../flyway-repair/docker-compose/.env | 1 - .../docker-compose/docker-compose.yaml | 8 ---- .../flyway-repair/docker-compose/mysql.env | 5 --- persistence-modules/flyway-repair/pom.xml | 43 ++++--------------- .../application-callbacks.properties | 2 +- .../resources/application-mysql.properties | 3 -- .../src/main/resources/application.properties | 3 -- .../afterMigrateError__repair.sql} | 0 ..._add_table_one.sql => V1_0__add_table.sql} | 0 ..._add_table_two.sql => V1_1__add_table.sql} | 0 ...dd_table_three.sql => V1_2__add_table.sql} | 0 .../db/migration/V1_3__add_table.sql | 2 +- 12 files changed, 11 insertions(+), 56 deletions(-) delete mode 100644 persistence-modules/flyway-repair/docker-compose/mysql.env delete mode 100644 persistence-modules/flyway-repair/src/main/resources/application-mysql.properties rename persistence-modules/flyway-repair/src/main/resources/db/{callbacks/afterMigrateError.sql => callback/afterMigrateError__repair.sql} (100%) rename persistence-modules/flyway-repair/src/main/resources/db/migration/{V1_0__add_table_one.sql => V1_0__add_table.sql} (100%) rename persistence-modules/flyway-repair/src/main/resources/db/migration/{V1_1__add_table_two.sql => V1_1__add_table.sql} (100%) rename persistence-modules/flyway-repair/src/main/resources/db/migration/{V1_2__add_table_three.sql => V1_2__add_table.sql} (100%) diff --git a/persistence-modules/flyway-repair/docker-compose/.env b/persistence-modules/flyway-repair/docker-compose/.env index 52bd0d6510..69785c6e5c 100644 --- a/persistence-modules/flyway-repair/docker-compose/.env +++ b/persistence-modules/flyway-repair/docker-compose/.env @@ -1,2 +1 @@ -MYSQL_PORT=3316 POSTGRES_PORT=5431 \ No newline at end of file diff --git a/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml index 23270c043d..b3502f8775 100644 --- a/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml +++ b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml @@ -1,14 +1,6 @@ version: '3.0' services: - mysql-test: - image: mysql:8.0.17 - ports: - - ${MYSQL_PORT}:3306 - env_file: - - mysql.env - networks: - - baeldung postgres-test: image: postgres:11.5 diff --git a/persistence-modules/flyway-repair/docker-compose/mysql.env b/persistence-modules/flyway-repair/docker-compose/mysql.env deleted file mode 100644 index 597344d88c..0000000000 --- a/persistence-modules/flyway-repair/docker-compose/mysql.env +++ /dev/null @@ -1,5 +0,0 @@ -MYSQL_ROOT_PASSWORD=password -MYSQL_RANDOM_ROOT_PASSWORD=yes -MYSQL_USER=testuser -MYSQL_PASSWORD=password -MYSQL_DATABASE=testdb \ No newline at end of file diff --git a/persistence-modules/flyway-repair/pom.xml b/persistence-modules/flyway-repair/pom.xml index f9d62d5dad..4d61bd5c0e 100644 --- a/persistence-modules/flyway-repair/pom.xml +++ b/persistence-modules/flyway-repair/pom.xml @@ -18,7 +18,6 @@ org.flywaydb flyway-core - ${flyway-core.version} org.springframework.boot @@ -31,37 +30,23 @@ org.flywaydb flyway-maven-plugin - ${flyway-maven-plugin.version} org.springframework.boot spring-boot-maven-plugin - - - true - src/main/resources - - *.properties - db/**/*.sql - - -
- - 6.5.0 - 6.5.0 - src/main/resources/application-${db.engine}.properties - - h2 + + true + - h2 + h2 @@ -72,24 +57,10 @@ - - mysql - - mysql - - - - mysql - mysql-connector-java - runtime - - - - postgres - postgres + postgres @@ -102,4 +73,8 @@ + + src/main/resources/application-${spring-boot.run.profiles}.properties + + diff --git a/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties index 2c10fc711f..7fb3124764 100644 --- a/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties +++ b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties @@ -1 +1 @@ -flyway.locations=db/migration,db/callbacks \ No newline at end of file +spring.flyway.locations=classpath:db/migration,classpath:db/callback \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties b/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties deleted file mode 100644 index 341f978068..0000000000 --- a/persistence-modules/flyway-repair/src/main/resources/application-mysql.properties +++ /dev/null @@ -1,3 +0,0 @@ -flyway.url=jdbc:mysql://127.0.0.1:3316/testdb -flyway.user=testuser -flyway.password=password \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/application.properties b/persistence-modules/flyway-repair/src/main/resources/application.properties index 3fae835eb1..da666d3cc2 100644 --- a/persistence-modules/flyway-repair/src/main/resources/application.properties +++ b/persistence-modules/flyway-repair/src/main/resources/application.properties @@ -1,6 +1,3 @@ -spring.profiles.include=@db.engine@ - spring.datasource.url=${flyway.url} spring.datasource.username=${flyway.user} spring.datasource.password=${flyway.password} -spring.flyway.locations=${flyway.locations:db/migration} \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql b/persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql similarity index 100% rename from persistence-modules/flyway-repair/src/main/resources/db/callbacks/afterMigrateError.sql rename to persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql similarity index 100% rename from persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table_one.sql rename to persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql similarity index 100% rename from persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table_two.sql rename to persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql similarity index 100% rename from persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table_three.sql rename to persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql index ec434dd5b2..cf89d5f308 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql @@ -1,3 +1,3 @@ -create table table_one ( +create table table_four ( id numeric primary key ); \ No newline at end of file From c53f498e12cced788e23abe6f0d373563551aa0e Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Fri, 17 Jul 2020 15:32:41 +0200 Subject: [PATCH 064/309] [BAEL4288] small fixes --- persistence-modules/flyway-repair/README.MD | 3 +-- persistence-modules/flyway-repair/docker-compose/.env | 2 +- .../flyway-repair/docker-compose/docker-compose.yaml | 2 +- .../src/main/resources/application-callbacks.properties | 2 +- .../flyway-repair/src/main/resources/application-h2.properties | 2 +- .../src/main/resources/application-postgres.properties | 2 +- .../main/resources/db/callback/afterMigrateError__repair.sql | 2 +- .../src/main/resources/db/migration/V1_0__add_table.sql | 2 +- .../src/main/resources/db/migration/V1_1__add_table.sql | 2 +- .../src/main/resources/db/migration/V1_2__add_table.sql | 2 +- .../src/main/resources/db/migration/V1_3__add_table.sql | 2 +- 11 files changed, 11 insertions(+), 12 deletions(-) diff --git a/persistence-modules/flyway-repair/README.MD b/persistence-modules/flyway-repair/README.MD index daeb9012b5..ca029e8299 100644 --- a/persistence-modules/flyway-repair/README.MD +++ b/persistence-modules/flyway-repair/README.MD @@ -1,3 +1,2 @@ ### Relevant Articles: -- [Database Migrations with Flyway](http://www.baeldung.com/database-migrations-with-flyway) -- [A Guide to Flyway Callbacks](http://www.baeldung.com/flyway-callbacks) +- [Flyway Repair With Spring Boot](http://www.baeldung.com/flyway-repair-with-spring-boot) diff --git a/persistence-modules/flyway-repair/docker-compose/.env b/persistence-modules/flyway-repair/docker-compose/.env index 69785c6e5c..8a9d0e7954 100644 --- a/persistence-modules/flyway-repair/docker-compose/.env +++ b/persistence-modules/flyway-repair/docker-compose/.env @@ -1 +1 @@ -POSTGRES_PORT=5431 \ No newline at end of file +POSTGRES_PORT=5431 diff --git a/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml index b3502f8775..b32b48d1cf 100644 --- a/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml +++ b/persistence-modules/flyway-repair/docker-compose/docker-compose.yaml @@ -12,4 +12,4 @@ services: networks: baeldung: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties index 7fb3124764..46ad86afee 100644 --- a/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties +++ b/persistence-modules/flyway-repair/src/main/resources/application-callbacks.properties @@ -1 +1 @@ -spring.flyway.locations=classpath:db/migration,classpath:db/callback \ No newline at end of file +spring.flyway.locations=classpath:db/migration,classpath:db/callback diff --git a/persistence-modules/flyway-repair/src/main/resources/application-h2.properties b/persistence-modules/flyway-repair/src/main/resources/application-h2.properties index 15bd482adf..64e485244e 100644 --- a/persistence-modules/flyway-repair/src/main/resources/application-h2.properties +++ b/persistence-modules/flyway-repair/src/main/resources/application-h2.properties @@ -1,3 +1,3 @@ flyway.url=jdbc:h2:file:./testdb;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE;MODE=MySQL;DATABASE_TO_UPPER=false; flyway.user=testuser -flyway.password=password \ No newline at end of file +flyway.password=password diff --git a/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties b/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties index 5afaca96b5..951f8f583d 100644 --- a/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties +++ b/persistence-modules/flyway-repair/src/main/resources/application-postgres.properties @@ -1,3 +1,3 @@ flyway.url=jdbc:postgresql://127.0.0.1:5431/testdb flyway.user=testuser -flyway.password=password \ No newline at end of file +flyway.password=password diff --git a/persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql b/persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql index c975e85056..ee0cbb6cee 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/callback/afterMigrateError__repair.sql @@ -1 +1 @@ -DELETE FROM flyway_schema_history WHERE success=false; \ No newline at end of file +DELETE FROM flyway_schema_history WHERE success=false; diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql index ec434dd5b2..1774e837b7 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_0__add_table.sql @@ -1,3 +1,3 @@ create table table_one ( id numeric primary key -); \ No newline at end of file +); diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql index 48720d59d6..76f2ee7ba1 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_1__add_table.sql @@ -1,3 +1,3 @@ create table table_two ( id numeric primary key -); \ No newline at end of file +); diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql index 1917c88b9b..dd5cf34059 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_2__add_table.sql @@ -1,3 +1,3 @@ create table table_three ( id numeric primary key -); \ No newline at end of file +); diff --git a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql index cf89d5f308..4a126ffe33 100644 --- a/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql +++ b/persistence-modules/flyway-repair/src/main/resources/db/migration/V1_3__add_table.sql @@ -1,3 +1,3 @@ create table table_four ( id numeric primary key -); \ No newline at end of file +); From 8d6257111ab9d3ab11aee1a3ebc74e374628afc0 Mon Sep 17 00:00:00 2001 From: Anirban Chatterjee Date: Sat, 18 Jul 2020 12:54:29 +0200 Subject: [PATCH 065/309] Moved to new module --- .../com/baeldung/exceptionhandling/ExceptionHandling.kt | 5 +++++ .../baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt | 5 +++++ 2 files changed, 10 insertions(+) rename core-kotlin-modules/{core-kotlin-lang-2 => core-kotlin}/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt (93%) rename core-kotlin-modules/{core-kotlin-lang-2 => core-kotlin}/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt (88%) diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt similarity index 93% rename from core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt rename to core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt index 225a1339e2..6689ab43e4 100644 --- a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt +++ b/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/exceptionhandling/ExceptionHandling.kt @@ -75,6 +75,11 @@ class ExceptionHandling { else return message.length } + fun throwExpression(): Int? { + val message: String? = null + return message?.length ?: throw IllegalArgumentException("String is null") + } + @Throws(IOException::class) fun throwsAnnotation(): String?{ val filePath = null diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt similarity index 88% rename from core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt rename to core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt index 49ad3c38e0..af7aa4406f 100644 --- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt +++ b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/exceptionhandling/ExceptionHandlingUnitTest.kt @@ -39,6 +39,11 @@ class ExceptionHandlingUnitTest { assertThrows { classUnderTest.throwKeyword() } } + @Test + fun givenIllegalArgument_whenElvisExpressionUsed_thenThrowsException(){ + assertThrows { classUnderTest.throwExpression() } + } + @Test fun whenAnnotationUsed_thenThrowsException(){ assertThrows { classUnderTest.throwsAnnotation() } From 1ac7e203216efaf31147ae4820f086145836470f Mon Sep 17 00:00:00 2001 From: Nguyen Nam Thai Date: Sat, 18 Jul 2020 21:56:20 +0700 Subject: [PATCH 066/309] BAEL-4113 Measure exception performance --- .../java/com/baeldung/ExceptionBenchmark.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 jmh/src/main/java/com/baeldung/ExceptionBenchmark.java diff --git a/jmh/src/main/java/com/baeldung/ExceptionBenchmark.java b/jmh/src/main/java/com/baeldung/ExceptionBenchmark.java new file mode 100644 index 0000000000..9a166fe2ce --- /dev/null +++ b/jmh/src/main/java/com/baeldung/ExceptionBenchmark.java @@ -0,0 +1,69 @@ +package com.baeldung; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; + +import java.util.concurrent.TimeUnit; + +@Fork(1) +@Warmup(iterations = 2) +@Measurement(iterations = 10) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +public class ExceptionBenchmark { + private static final int LIMIT = 10_000; + + @Benchmark + public void doNotThrowException(Blackhole blackhole) { + for (int i = 0; i < LIMIT; i++) { + blackhole.consume(new Object()); + } + } + + @Benchmark + public void throwAndCatchException(Blackhole blackhole) { + for (int i = 0; i < LIMIT; i++) { + try { + throw new Exception(); + } catch (Exception e) { + blackhole.consume(e); + } + } + } + + @Benchmark + public void createExceptionWithoutThrowingIt(Blackhole blackhole) { + for (int i = 0; i < LIMIT; i++) { + blackhole.consume(new Exception()); + } + } + + @Benchmark + @Fork(value = 1, jvmArgs = "-XX:-StackTraceInThrowable") + public void throwExceptionWithoutAddingStackTrace(Blackhole blackhole) { + for (int i = 0; i < LIMIT; i++) { + try { + throw new Exception(); + } catch (Exception e) { + blackhole.consume(e); + } + } + } + + @Benchmark + public void throwExceptionAndUnwindStackTrace(Blackhole blackhole) { + for (int i = 0; i < LIMIT; i++) { + try { + throw new Exception(); + } catch (Exception e) { + blackhole.consume(e.getStackTrace()); + } + } + } +} From 2f2450fbb9c0d98a98e9c2142f089389bb540f89 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sat, 18 Jul 2020 23:49:58 +0530 Subject: [PATCH 067/309] used standard parent in the project --- patterns/hexagonal-architecture/pom.xml | 13 +++++++------ ...plTest.java => EmployeeServiceImplUnitTest.java} | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) rename patterns/hexagonal-architecture/src/test/java/com/baeldung/pattern/hexagonal/domain/services/{EmployeeServiceImplTest.java => EmployeeServiceImplUnitTest.java} (97%) diff --git a/patterns/hexagonal-architecture/pom.xml b/patterns/hexagonal-architecture/pom.xml index 9317a25e56..62f55c2efa 100644 --- a/patterns/hexagonal-architecture/pom.xml +++ b/patterns/hexagonal-architecture/pom.xml @@ -2,18 +2,19 @@ 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.0.RELEASE - - com.baeldung hexagonal-architecture 1.0 hexagonal-architecture Project for hexagonal architecture in java + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + 1.8 diff --git a/patterns/hexagonal-architecture/src/test/java/com/baeldung/pattern/hexagonal/domain/services/EmployeeServiceImplTest.java b/patterns/hexagonal-architecture/src/test/java/com/baeldung/pattern/hexagonal/domain/services/EmployeeServiceImplUnitTest.java similarity index 97% rename from patterns/hexagonal-architecture/src/test/java/com/baeldung/pattern/hexagonal/domain/services/EmployeeServiceImplTest.java rename to patterns/hexagonal-architecture/src/test/java/com/baeldung/pattern/hexagonal/domain/services/EmployeeServiceImplUnitTest.java index cadb3b094b..542e45d6f4 100644 --- a/patterns/hexagonal-architecture/src/test/java/com/baeldung/pattern/hexagonal/domain/services/EmployeeServiceImplTest.java +++ b/patterns/hexagonal-architecture/src/test/java/com/baeldung/pattern/hexagonal/domain/services/EmployeeServiceImplUnitTest.java @@ -11,7 +11,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -class EmployeeServiceImplTest { +class EmployeeServiceImplUnitTest { private EmployeeRepository employeeRepository; private EmployeeService testService; From 09ac6a9cf99be3ef849e87ca14a0d8eb79670213 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 19 Jul 2020 00:57:36 +0530 Subject: [PATCH 068/309] fix for the build warning --- spring-security-modules/spring-security-config/cors/pom.xml | 1 + spring-security-modules/spring-security-config/pom.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/spring-security-modules/spring-security-config/cors/pom.xml b/spring-security-modules/spring-security-config/cors/pom.xml index 19ca7f5ccc..175b21a77d 100644 --- a/spring-security-modules/spring-security-config/cors/pom.xml +++ b/spring-security-modules/spring-security-config/cors/pom.xml @@ -11,6 +11,7 @@ com.baeldung spring-security-modules 0.0.1-SNAPSHOT + ../../ diff --git a/spring-security-modules/spring-security-config/pom.xml b/spring-security-modules/spring-security-config/pom.xml index b3796d1cc6..2b6b6b6b4e 100644 --- a/spring-security-modules/spring-security-config/pom.xml +++ b/spring-security-modules/spring-security-config/pom.xml @@ -11,6 +11,7 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT + ../../ From 9b7caf3118b9b7b051fbed8f9f5b6a874996c876 Mon Sep 17 00:00:00 2001 From: STS Date: Sun, 19 Jul 2020 10:15:37 +0200 Subject: [PATCH 069/309] change excel file direcory --- .../{setFormula => setformula}/ExcelFormula.java | 2 +- .../poi/excel/setformula}/SetFormulaTest.xlsx | Bin .../ExcelFormulaUnitTest.java | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename apache-poi/src/main/java/com/baeldung/poi/excel/{setFormula => setformula}/ExcelFormula.java (93%) rename apache-poi/src/main/resources/{ => com/bealdung/poi/excel/setformula}/SetFormulaTest.xlsx (100%) rename apache-poi/src/test/java/com/baeldung/poi/excel/{setFormula => setformula}/ExcelFormulaUnitTest.java (93%) diff --git a/apache-poi/src/main/java/com/baeldung/poi/excel/setFormula/ExcelFormula.java b/apache-poi/src/main/java/com/baeldung/poi/excel/setformula/ExcelFormula.java similarity index 93% rename from apache-poi/src/main/java/com/baeldung/poi/excel/setFormula/ExcelFormula.java rename to apache-poi/src/main/java/com/baeldung/poi/excel/setformula/ExcelFormula.java index 8b1ca5a89a..f5179b19c9 100644 --- a/apache-poi/src/main/java/com/baeldung/poi/excel/setFormula/ExcelFormula.java +++ b/apache-poi/src/main/java/com/baeldung/poi/excel/setformula/ExcelFormula.java @@ -1,4 +1,4 @@ -package com.baeldung.poi.excel.setFormula; +package com.baeldung.poi.excel.setformula; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator; diff --git a/apache-poi/src/main/resources/SetFormulaTest.xlsx b/apache-poi/src/main/resources/com/bealdung/poi/excel/setformula/SetFormulaTest.xlsx similarity index 100% rename from apache-poi/src/main/resources/SetFormulaTest.xlsx rename to apache-poi/src/main/resources/com/bealdung/poi/excel/setformula/SetFormulaTest.xlsx diff --git a/apache-poi/src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java b/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java similarity index 93% rename from apache-poi/src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java rename to apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java index 990b93fcbb..45314519d4 100644 --- a/apache-poi/src/test/java/com/baeldung/poi/excel/setFormula/ExcelFormulaUnitTest.java +++ b/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.poi.excel.setFormula; +package com.baeldung.poi.excel.setformula; import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.usermodel.XSSFSheet; @@ -14,7 +14,7 @@ import java.net.URISyntaxException; import java.nio.file.Paths; class ExcelFormulaUnitTest { - private static String FILE_NAME = "SetFormulaTest.xlsx"; + private static String FILE_NAME = "com/bealdung/poi/excel/setformula/SetFormulaTest.xlsx"; private String fileLocation; private ExcelFormula excelFormula; From 2a88d24386eec8969f275f25d3b226e3ac944313 Mon Sep 17 00:00:00 2001 From: developerDiv Date: Sat, 11 Jul 2020 16:42:03 +0100 Subject: [PATCH 070/309] Initial commit of ArgumentCaptor --- .../argumentcaptor/AuthenticationStatus.java | 7 ++ .../mockito/argumentcaptor/Credentials.java | 15 +++ .../argumentcaptor/DeliveryPlatform.java | 10 ++ .../mockito/argumentcaptor/Email.java | 47 ++++++++ .../mockito/argumentcaptor/EmailService.java | 36 +++++++ .../mockito/argumentcaptor/Format.java | 6 ++ .../mockito/argumentcaptor/ServiceStatus.java | 7 ++ .../argumentcaptor/EmailServiceUnitTest.java | 100 ++++++++++++++++++ 8 files changed, 228 insertions(+) create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/AuthenticationStatus.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Credentials.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/DeliveryPlatform.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Email.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/EmailService.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Format.java create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/ServiceStatus.java create mode 100644 testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/AuthenticationStatus.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/AuthenticationStatus.java new file mode 100644 index 0000000000..8307b4323b --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/AuthenticationStatus.java @@ -0,0 +1,7 @@ +package com.baeldung.mockito.argumentcaptor; + +public enum AuthenticationStatus { + AUTHENTICATED, + NOT_AUTHENTICATED, + ERROR +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Credentials.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Credentials.java new file mode 100644 index 0000000000..5aec15505e --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Credentials.java @@ -0,0 +1,15 @@ +package com.baeldung.mockito.argumentcaptor; + +public class Credentials { + private final String name; + private final String password; + private final String key; + + public Credentials(String name, String password, String key) { + + this.name = name; + this.password = password; + this.key = key; + } +} + diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/DeliveryPlatform.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/DeliveryPlatform.java new file mode 100644 index 0000000000..dbad1e1bcf --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/DeliveryPlatform.java @@ -0,0 +1,10 @@ +package com.baeldung.mockito.argumentcaptor; + +public interface DeliveryPlatform { + + void send(Email email); + + String getServiceStatus(); + + AuthenticationStatus authenticate(Credentials credentials); +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Email.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Email.java new file mode 100644 index 0000000000..6fc753a31c --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Email.java @@ -0,0 +1,47 @@ +package com.baeldung.mockito.argumentcaptor; + +public class Email { + + private String address; + private String subject; + private String body; + private Format format; + + public Email(String address, String subject, String body) { + this.address = address; + this.subject = subject; + this.body = body; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + public Format getFormat() { + return format; + } + + public void setFormat(Format format) { + this.format = format; + } +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/EmailService.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/EmailService.java new file mode 100644 index 0000000000..c368f41d2f --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/EmailService.java @@ -0,0 +1,36 @@ +package com.baeldung.mockito.argumentcaptor; + +public class EmailService { + + private DeliveryPlatform platform; + + public EmailService(DeliveryPlatform platform) { + this.platform = platform; + } + + public void send(String to, String subject, String body, boolean html) { + Format format = Format.TEXT_ONLY; + if (html) { + format = Format.HTML; + } + Email email = new Email(to, subject, body); + email.setFormat(format); + platform.send(email); + } + + public ServiceStatus checkServiceStatus() { + if (platform.getServiceStatus().equals("OK")) { + return ServiceStatus.UP; + } else { + return ServiceStatus.DOWN; + } + } + + public boolean authenticatedSuccessfully(Credentials credentials) { + if (platform.authenticate(credentials).equals(AuthenticationStatus.AUTHENTICATED)) { + return true; + } else { + return false; + } + } +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Format.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Format.java new file mode 100644 index 0000000000..4c10375159 --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Format.java @@ -0,0 +1,6 @@ +package com.baeldung.mockito.argumentcaptor; + +public enum Format { + TEXT_ONLY, + HTML +} diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/ServiceStatus.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/ServiceStatus.java new file mode 100644 index 0000000000..65def5af64 --- /dev/null +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/ServiceStatus.java @@ -0,0 +1,7 @@ +package com.baeldung.mockito.argumentcaptor; + +public enum ServiceStatus { + UP, + DOWN, + AUTHENTICATED +} diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java new file mode 100644 index 0000000000..cdae118e92 --- /dev/null +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java @@ -0,0 +1,100 @@ +package com.baeldung.mockito.argumentcaptor; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class EmailServiceUnitTest { + + @InjectMocks + EmailService emailService; + + @Mock + DeliveryPlatform platform; + + @Captor + ArgumentCaptor emailCaptor; + + @Captor + ArgumentCaptor credentialsCaptor; + + @Test + public void whenDoesNotSupportHtml_expectTextOnlyEmailFormat() { + String to = "info@baeldung.com"; + String subject = "Using ArgumentCaptor"; + String body = "Article on using ArgumentCaptor"; + + emailService.send(to, subject, body, false); + + verify(platform).send(emailCaptor.capture()); + Email emailCaptorValue = emailCaptor.getValue(); + assertEquals(Format.TEXT_ONLY, emailCaptorValue.getFormat()); + } + + @Test + public void send_whenDoesSupportHtml_expectHTMLEmailFormat() { + String to = "baeldung@baeldung.com"; + String subject = "Great New Course!"; + String body = "Try out our new course."; + + emailService.send(to, subject, body, true); + + verify(platform).send(emailCaptor.capture()); + Email value = emailCaptor.getValue(); + assertEquals(Format.HTML, value.getFormat()); + } + + @Test + public void getServiceStatus_whenServiceRunning_expectUpResponse() { + when(platform.getServiceStatus()).thenReturn("OK"); + + ServiceStatus serviceStatus = emailService.checkServiceStatus(); + + assertEquals(ServiceStatus.UP, serviceStatus); + } + + @Test + public void getServiceStatus_whenServiceNotRunning_expectDownResponse() { + when(platform.getServiceStatus()).thenReturn("Error"); + + ServiceStatus serviceStatus = emailService.checkServiceStatus(); + + assertEquals(ServiceStatus.DOWN, serviceStatus); + } + + @Test + public void usingArgumemtMatcher_whenAuthenticatedWithValidCredentials_expectTrue() { + Credentials credentials = new Credentials("baeldung", "correct_password", "correct_key"); + when(platform.authenticate(eq(credentials))).thenReturn(AuthenticationStatus.AUTHENTICATED); + + assertTrue(emailService.authenticatedSuccessfully(credentials)); + } + + @Test + public void usingArgumentCapture_whenAuthenticatedWithValidCredentials_expectTrue() { + Credentials credentials = new Credentials("baeldung", "correct_password", "correct_key"); + when(platform.authenticate(credentialsCaptor.capture())).thenReturn(AuthenticationStatus.AUTHENTICATED); + + assertTrue(emailService.authenticatedSuccessfully(credentials)); + assertEquals(credentials, credentialsCaptor.getValue()); + } + + @Test + public void authenticate_whenNotAuthenticated_expectFalse() { + Credentials credentials = new Credentials("baeldung", "incorrect_password", "incorrect_key"); + when(platform.authenticate(credentialsCaptor.capture())).thenReturn(AuthenticationStatus.NOT_AUTHENTICATED); + + assertFalse(emailService.authenticatedSuccessfully(credentials)); + assertEquals(credentials, credentialsCaptor.getValue()); + } +} \ No newline at end of file From 92b1c62c1aebdbef3699e3a97ff9ee888550b212 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 19 Jul 2020 14:29:41 +0530 Subject: [PATCH 071/309] JAVA-66: New module spring-data-jpa-annotations --- .../spring-data-jpa-annotations/README.md | 23 +++ .../spring-data-jpa-annotations/pom.xml | 77 +++++++++ .../main/java/com/baeldung/Application.java | 13 ++ .../baeldung/boot/ddd/event/Aggregate.java | 46 ++++++ .../baeldung/boot/ddd/event/Aggregate2.java | 44 +++++ .../boot/ddd/event/Aggregate2Repository.java | 10 ++ .../baeldung/boot/ddd/event/Aggregate3.java | 23 +++ .../boot/ddd/event/Aggregate3Repository.java | 14 ++ .../boot/ddd/event/AggregateRepository.java | 10 ++ .../baeldung/boot/ddd/event/DddConfig.java | 15 ++ .../baeldung/boot/ddd/event/DomainEvent.java | 8 + .../boot/ddd/event/DomainService.java | 31 ++++ .../baeldung/composite/BookApplication.java | 12 ++ .../com/baeldung/composite/entity/Book.java | 47 ++++++ .../com/baeldung/composite/entity/BookId.java | 51 ++++++ .../composite/repository/BookRepository.java | 18 +++ .../baeldung/embeddable/model/Company.java | 71 ++++++++ .../embeddable/model/ContactPerson.java | 38 +++++ .../repositories/CompanyRepository.java | 18 +++ .../SpringBootLifecycleEventApplication.java | 11 ++ .../model/AuditTrailListener.java | 39 +++++ .../baeldung/lifecycleevents/model/User.java | 104 ++++++++++++ .../repository/UserRepository.java | 9 ++ .../java/com/baeldung/tx/TxApplication.java | 13 ++ .../java/com/baeldung/tx/model/Payment.java | 55 +++++++ .../src/main/resources/application.properties | 6 + .../src/main/resources/ddd.properties | 1 + .../src/main/resources/logback.xml | 13 ++ .../src/main/resources/persistence.properties | 14 ++ .../Aggregate2EventsIntegrationTest.java | 72 +++++++++ .../Aggregate3EventsIntegrationTest.java | 67 ++++++++ .../event/AggregateEventsIntegrationTest.java | 87 ++++++++++ .../boot/ddd/event/TestEventHandler.java | 14 ++ .../BookRepositoryIntegrationTest.java | 64 ++++++++ .../embeddable/EmbeddableIntegrationTest.java | 125 ++++++++++++++ .../tx/ManualTransactionIntegrationTest.java | 152 ++++++++++++++++++ .../UserRepositoryIntegrationTest.java | 80 +++++++++ 37 files changed, 1495 insertions(+) create mode 100644 persistence-modules/spring-data-jpa-annotations/README.md create mode 100644 persistence-modules/spring-data-jpa-annotations/pom.xml create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/Application.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DomainService.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/BookApplication.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/entity/Book.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/entity/BookId.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/repository/BookRepository.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/model/Company.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/model/ContactPerson.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/SpringBootLifecycleEventApplication.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/model/AuditTrailListener.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/model/User.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/repository/UserRepository.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/tx/TxApplication.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/tx/model/Payment.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/resources/application.properties create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/resources/ddd.properties create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/resources/logback.xml create mode 100644 persistence-modules/spring-data-jpa-annotations/src/main/resources/persistence.properties create mode 100644 persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/composite/repository/BookRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-annotations/src/test/java/lifecycleevents/UserRepositoryIntegrationTest.java diff --git a/persistence-modules/spring-data-jpa-annotations/README.md b/persistence-modules/spring-data-jpa-annotations/README.md new file mode 100644 index 0000000000..5f1c8dbc27 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/README.md @@ -0,0 +1,23 @@ +## Spring Data JPA - Annotations + +This module contains articles about annotations used in Spring Data JPA + +### Relevant articles + +- [Spring Data Annotations](https://www.baeldung.com/spring-data-annotations) +- [DDD Aggregates and @DomainEvents](https://www.baeldung.com/spring-data-ddd) +- [JPA @Embedded And @Embeddable](https://www.baeldung.com/jpa-embedded-embeddable) +- [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation) +- [Spring JPA @Embedded and @EmbeddedId](https://www.baeldung.com/spring-jpa-embedded-method-parameters) +- [Programmatic Transaction Management in Spring](https://www.baeldung.com/spring-programmatic-transaction-management) +- [JPA Entity Lifecycle Events](https://www.baeldung.com/jpa-entity-lifecycle-events) + +### Eclipse Config +After importing the project into Eclipse, you may see the following error: +"No persistence xml file found in project" + +This can be ignored: +- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" +Or: +- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator + diff --git a/persistence-modules/spring-data-jpa-annotations/pom.xml b/persistence-modules/spring-data-jpa-annotations/pom.xml new file mode 100644 index 0000000000..67b788c404 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + spring-data-jpa-annotations + spring-data-jpa-annotations + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.hibernate + hibernate-ehcache + + + org.hibernate + hibernate-envers + + + + com.h2database + h2 + + + + + org.testcontainers + postgresql + ${testcontainers.postgresql.version} + test + + + + org.postgresql + postgresql + + + + + org.springframework.security + spring-security-test + test + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.google.guava + guava + ${guava.version} + + + + + com.baeldung.boot.Application + 1.10.6 + 42.2.5 + 21.0 + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..3ea3d113da --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/Application.java @@ -0,0 +1,13 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java new file mode 100644 index 0000000000..e435f4c85c --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java @@ -0,0 +1,46 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Transient; + +import org.springframework.context.ApplicationEventPublisher; + +@Entity +class Aggregate { + @Transient + private ApplicationEventPublisher eventPublisher; + @Id + private long id; + + private Aggregate() { + } + + Aggregate(long id, ApplicationEventPublisher eventPublisher) { + this.id = id; + this.eventPublisher = eventPublisher; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "DomainEntity [id=" + id + "]"; + } + + void domainOperation() { + // some business logic + if (eventPublisher != null) { + eventPublisher.publishEvent(new DomainEvent()); + } + } + + long getId() { + return id; + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java new file mode 100644 index 0000000000..08f61db812 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java @@ -0,0 +1,44 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import java.util.ArrayList; +import java.util.Collection; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Transient; + +import org.springframework.data.domain.AfterDomainEventPublication; +import org.springframework.data.domain.DomainEvents; + +@Entity +public class Aggregate2 { + @Transient + private final Collection domainEvents; + @Id + @GeneratedValue + private long id; + + public Aggregate2() { + domainEvents = new ArrayList<>(); + } + + @AfterDomainEventPublication + public void clearEvents() { + domainEvents.clear(); + } + + public void domainOperation() { + // some domain operation + domainEvents.add(new DomainEvent()); + } + + @DomainEvents + public Collection events() { + return domainEvents; + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java new file mode 100644 index 0000000000..7f09c410fc --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java @@ -0,0 +1,10 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import org.springframework.data.repository.CrudRepository; + +public interface Aggregate2Repository extends CrudRepository { + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java new file mode 100644 index 0000000000..f664322a59 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java @@ -0,0 +1,23 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.springframework.data.domain.AbstractAggregateRoot; + +@Entity +public class Aggregate3 extends AbstractAggregateRoot { + @Id + @GeneratedValue + private long id; + + public void domainOperation() { + // some domain operation + registerEvent(new DomainEvent()); + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java new file mode 100644 index 0000000000..93f50bb5cf --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java @@ -0,0 +1,14 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import org.springframework.data.repository.CrudRepository; + +/** + * @author goobar + * + */ +public interface Aggregate3Repository extends CrudRepository { + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java new file mode 100644 index 0000000000..1c2d3884bf --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java @@ -0,0 +1,10 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import org.springframework.data.repository.CrudRepository; + +public interface AggregateRepository extends CrudRepository { + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java new file mode 100644 index 0000000000..34cf21463b --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java @@ -0,0 +1,15 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.PropertySource; + +@SpringBootConfiguration +@EnableAutoConfiguration +@PropertySource("classpath:/ddd.properties") +public class DddConfig { + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java new file mode 100644 index 0000000000..e7626e742d --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java @@ -0,0 +1,8 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +class DomainEvent { + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DomainService.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DomainService.java new file mode 100644 index 0000000000..80aa5ca6cb --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/boot/ddd/event/DomainService.java @@ -0,0 +1,31 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import javax.transaction.Transactional; + +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Service; + +@Service +public class DomainService { + private final ApplicationEventPublisher eventPublisher; + private final AggregateRepository repository; + + public DomainService(AggregateRepository repository, ApplicationEventPublisher eventPublisher) { + this.repository = repository; + this.eventPublisher = eventPublisher; + } + + @Transactional + public void serviceDomainOperation(long entityId) { + repository.findById(entityId) + .ifPresent(entity -> { + entity.domainOperation(); + repository.save(entity); + eventPublisher.publishEvent(new DomainEvent()); + }); + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/BookApplication.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/BookApplication.java new file mode 100644 index 0000000000..52f06058aa --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/BookApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.composite; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class BookApplication { + + public static void main(String[] args) { + SpringApplication.run(BookApplication.class); + } +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/entity/Book.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/entity/Book.java new file mode 100644 index 0000000000..e4f1727654 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/entity/Book.java @@ -0,0 +1,47 @@ +package com.baeldung.composite.entity; + +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; + +@Entity +public class Book { + + @EmbeddedId + private BookId id; + private String genre; + private Integer price; + + public Book() { + } + + public Book(String author, String name, String genre, Integer price) { + BookId id = new BookId(author, name); + this.id = id; + this.genre = genre; + this.price = price; + } + + public BookId getId() { + return id; + } + + public void setId(BookId id) { + this.id = id; + } + + public String getGenre() { + return genre; + } + + public void setGenre(String genre) { + this.genre = genre; + } + + public Integer getPrice() { + return price; + } + + public void setPrice(Integer price) { + this.price = price; + } +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/entity/BookId.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/entity/BookId.java new file mode 100644 index 0000000000..1524452412 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/entity/BookId.java @@ -0,0 +1,51 @@ +package com.baeldung.composite.entity; + +import javax.persistence.Embeddable; +import java.io.Serializable; +import java.util.Objects; + +@Embeddable +public class BookId implements Serializable { + + private String author; + private String name; + + public BookId() { + } + + public BookId(String author, String name) { + this.author = author; + this.name = name; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + BookId bookId = (BookId) o; + return Objects.equals(author, bookId.author) && Objects.equals(name, bookId.name); + } + + @Override + public int hashCode() { + return Objects.hash(author, name); + } +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/repository/BookRepository.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/repository/BookRepository.java new file mode 100644 index 0000000000..d5993eaf79 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/composite/repository/BookRepository.java @@ -0,0 +1,18 @@ +package com.baeldung.composite.repository; + +import com.baeldung.composite.entity.Book; +import com.baeldung.composite.entity.BookId; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface BookRepository extends JpaRepository { + + List findByIdName(String name); + + List findByIdAuthor(String author); + + List findByGenre(String genre); +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/model/Company.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/model/Company.java new file mode 100644 index 0000000000..203cff1e35 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/model/Company.java @@ -0,0 +1,71 @@ +package com.baeldung.embeddable.model; + +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Company { + + @Id + @GeneratedValue + private Integer id; + + private String name; + + private String address; + + private String phone; + + @Embedded + @AttributeOverrides(value = { + @AttributeOverride( name = "firstName", column = @Column(name = "contact_first_name")), + @AttributeOverride( name = "lastName", column = @Column(name = "contact_last_name")), + @AttributeOverride( name = "phone", column = @Column(name = "contact_phone")) + }) + private ContactPerson contactPerson; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public ContactPerson getContactPerson() { + return contactPerson; + } + + public void setContactPerson(ContactPerson contactPerson) { + this.contactPerson = contactPerson; + } +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/model/ContactPerson.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/model/ContactPerson.java new file mode 100644 index 0000000000..561da80878 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/model/ContactPerson.java @@ -0,0 +1,38 @@ +package com.baeldung.embeddable.model; + +import javax.persistence.Embeddable; + +@Embeddable +public class ContactPerson { + + private String firstName; + + private String lastName; + + private String phone; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java new file mode 100644 index 0000000000..f456b15652 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java @@ -0,0 +1,18 @@ +package com.baeldung.embeddable.repositories; + +import com.baeldung.embeddable.model.Company; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; + +public interface CompanyRepository extends JpaRepository { + + List findByContactPersonFirstName(String firstName); + + @Query("SELECT C FROM Company C WHERE C.contactPerson.firstName = ?1") + List findByContactPersonFirstNameWithJPQL(String firstName); + + @Query(value = "SELECT * FROM company WHERE contact_first_name = ?1", nativeQuery = true) + List findByContactPersonFirstNameWithNativeQuery(String firstName); +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/SpringBootLifecycleEventApplication.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/SpringBootLifecycleEventApplication.java new file mode 100644 index 0000000000..fbc861c5fe --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/SpringBootLifecycleEventApplication.java @@ -0,0 +1,11 @@ +package com.baeldung.lifecycleevents; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootLifecycleEventApplication { + public static void main(String[] args) { + SpringApplication.run(SpringBootLifecycleEventApplication.class, args); + } +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/model/AuditTrailListener.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/model/AuditTrailListener.java new file mode 100644 index 0000000000..26ebff42e4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/model/AuditTrailListener.java @@ -0,0 +1,39 @@ +package com.baeldung.lifecycleevents.model; + +import javax.persistence.PostLoad; +import javax.persistence.PostPersist; +import javax.persistence.PostRemove; +import javax.persistence.PostUpdate; +import javax.persistence.PrePersist; +import javax.persistence.PreRemove; +import javax.persistence.PreUpdate; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +public class AuditTrailListener { + private static Log log = LogFactory.getLog(AuditTrailListener.class); + + @PrePersist + @PreUpdate + @PreRemove + private void beforeAnyUpdate(User user) { + if (user.getId() == 0) { + log.info("[USER AUDIT] About to add a user"); + } else { + log.info("[USER AUDIT] About to update/delete user: " + user.getId()); + } + } + + @PostPersist + @PostUpdate + @PostRemove + private void afterAnyUpdate(User user) { + log.info("[USER AUDIT] add/update/delete complete for user: " + user.getId()); + } + + @PostLoad + private void afterLoad(User user) { + log.info("[USER AUDIT] user loaded from database: " + user.getId()); + } +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/model/User.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/model/User.java new file mode 100644 index 0000000000..a080cb3bf2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/model/User.java @@ -0,0 +1,104 @@ +package com.baeldung.lifecycleevents.model; + +import javax.persistence.Entity; +import javax.persistence.EntityListeners; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.PostLoad; +import javax.persistence.PostPersist; +import javax.persistence.PostRemove; +import javax.persistence.PostUpdate; +import javax.persistence.PrePersist; +import javax.persistence.PreRemove; +import javax.persistence.PreUpdate; +import javax.persistence.Transient; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +@Entity +@EntityListeners(AuditTrailListener.class) +public class User { + private static Log log = LogFactory.getLog(User.class); + + @Id + @GeneratedValue + private int id; + + private String userName; + private String firstName; + private String lastName; + @Transient + private String fullName; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getFullName() { + return fullName; + } + + @PrePersist + public void logNewUserAttempt() { + log.info("Attempting to add new user with username: " + userName); + } + + @PostPersist + public void logNewUserAdded() { + log.info("Added user '" + userName + "' with ID: " + id); + } + + @PreRemove + public void logUserRemovalAttempt() { + log.info("Attempting to delete user: " + userName); + } + + @PostRemove + public void logUserRemoval() { + log.info("Deleted user: " + userName); + } + + @PreUpdate + public void logUserUpdateAttempt() { + log.info("Attempting to update user: " + userName); + } + + @PostUpdate + public void logUserUpdate() { + log.info("Updated user: " + userName); + } + + @PostLoad + public void logUserLoad() { + fullName = firstName + " " + lastName; + } +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/repository/UserRepository.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/repository/UserRepository.java new file mode 100644 index 0000000000..af14117ebb --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/lifecycleevents/repository/UserRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.lifecycleevents.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.lifecycleevents.model.User; + +public interface UserRepository extends JpaRepository { + public User findByUserName(String userName); +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/tx/TxApplication.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/tx/TxApplication.java new file mode 100644 index 0000000000..4c982c91e9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/tx/TxApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.tx; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class TxApplication { + + public static void main(String[] args) { + SpringApplication.run(TxApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/tx/model/Payment.java b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/tx/model/Payment.java new file mode 100644 index 0000000000..921a1e9275 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/java/com/baeldung/tx/model/Payment.java @@ -0,0 +1,55 @@ +package com.baeldung.tx.model; + +import javax.persistence.*; + +@Entity +public class Payment { + + @Id + @GeneratedValue + private Long id; + + private Long amount; + + @Column(unique = true) + private String referenceNumber; + + @Enumerated(EnumType.STRING) + private State state; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Long getAmount() { + return amount; + } + + public void setAmount(Long amount) { + this.amount = amount; + } + + public String getReferenceNumber() { + return referenceNumber; + } + + public void setReferenceNumber(String referenceNumber) { + this.referenceNumber = referenceNumber; + } + + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } + + public enum State { + STARTED, FAILED, SUCCESSFUL + } +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-annotations/src/main/resources/application.properties new file mode 100644 index 0000000000..f127dd5e50 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.main.allow-bean-definition-overriding=true + +spring.jpa.properties.hibernate.jdbc.batch_size=4 +spring.jpa.properties.hibernate.order_inserts=true +spring.jpa.properties.hibernate.order_updates=true +spring.jpa.properties.hibernate.generate_statistics=true diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/resources/ddd.properties b/persistence-modules/spring-data-jpa-annotations/src/main/resources/ddd.properties new file mode 100644 index 0000000000..e5126b694b --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/resources/ddd.properties @@ -0,0 +1 @@ +spring.datasource.initialization-mode=never \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/resources/logback.xml b/persistence-modules/spring-data-jpa-annotations/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-annotations/src/main/resources/persistence.properties b/persistence-modules/spring-data-jpa-annotations/src/main/resources/persistence.properties new file mode 100644 index 0000000000..6bc83edf34 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/main/resources/persistence.properties @@ -0,0 +1,14 @@ +# jdbc.X +jdbc.driverClassName=org.h2.Driver +jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS +jdbc.user=sa +jdbc.pass=sa + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop +hibernate.cache.use_second_level_cache=true +hibernate.cache.use_query_cache=true +hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory + diff --git a/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java new file mode 100644 index 0000000000..e76b932cb9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java @@ -0,0 +1,72 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.baeldung.boot.ddd.event.Aggregate2; +import com.baeldung.boot.ddd.event.Aggregate2Repository; +import com.baeldung.boot.ddd.event.DomainEvent; + +@SpringJUnitConfig +@SpringBootTest +class Aggregate2EventsIntegrationTest { + @MockBean + private TestEventHandler eventHandler; + @Autowired + private Aggregate2Repository repository; + + // @formatter:off + @DisplayName("given aggregate with @AfterDomainEventPublication," + + " when do domain operation and save twice," + + " then an event is published only for the first time") + // @formatter:on + @Test + void afterDomainEvents() { + // given + Aggregate2 aggregate = new Aggregate2(); + + // when + aggregate.domainOperation(); + repository.save(aggregate); + repository.save(aggregate); + + // then + verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class)); + } + + @BeforeEach + void beforeEach() { + repository.deleteAll(); + } + + // @formatter:off + @DisplayName("given aggregate with @DomainEvents," + + " when do domain operation and save," + + " then an event is published") + // @formatter:on + @Test + void domainEvents() { + // given + Aggregate2 aggregate = new Aggregate2(); + + // when + aggregate.domainOperation(); + repository.save(aggregate); + + // then + verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class)); + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java new file mode 100644 index 0000000000..4193e932ee --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java @@ -0,0 +1,67 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.baeldung.boot.ddd.event.Aggregate3; +import com.baeldung.boot.ddd.event.Aggregate3Repository; +import com.baeldung.boot.ddd.event.DomainEvent; + +@SpringJUnitConfig +@SpringBootTest +class Aggregate3EventsIntegrationTest { + + @MockBean + private TestEventHandler eventHandler; + @Autowired + private Aggregate3Repository repository; + + // @formatter:off + @DisplayName("given aggregate extending AbstractAggregateRoot," + + " when do domain operation and save twice," + + " then an event is published only for the first time") + // @formatter:on + @Test + void afterDomainEvents() { + // given + Aggregate3 aggregate = new Aggregate3(); + + // when + aggregate.domainOperation(); + repository.save(aggregate); + repository.save(aggregate); + + // then + verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class)); + } + + // @formatter:off + @DisplayName("given aggregate extending AbstractAggregateRoot," + + " when do domain operation and save," + + " then an event is published") + // @formatter:on + @Test + void domainEvents() { + // given + Aggregate3 aggregate = new Aggregate3(); + + // when + aggregate.domainOperation(); + repository.save(aggregate); + + // then + verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class)); + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java new file mode 100644 index 0000000000..ac607063b2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java @@ -0,0 +1,87 @@ +package com.baeldung.boot.ddd.event; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.baeldung.boot.ddd.event.Aggregate; +import com.baeldung.boot.ddd.event.AggregateRepository; +import com.baeldung.boot.ddd.event.DomainEvent; +import com.baeldung.boot.ddd.event.DomainService; + +@SpringJUnitConfig +@SpringBootTest +class AggregateEventsIntegrationTest { + + @Autowired + private DomainService domainService; + + @MockBean + private TestEventHandler eventHandler; + @Autowired + private ApplicationEventPublisher eventPublisher; + @Autowired + private AggregateRepository repository; + + // @formatter:off + @DisplayName("given existing aggregate," + + " when do domain operation directly on aggregate," + + " then domain event is NOT published") + // @formatter:on + @Test + void aggregateEventsTest() { + Aggregate existingDomainEntity = new Aggregate(0, eventPublisher); + repository.save(existingDomainEntity); + + // when + repository.findById(existingDomainEntity.getId()) + .get() + .domainOperation(); + + // then + verifyZeroInteractions(eventHandler); + } + + @BeforeEach + void beforeEach() { + repository.deleteAll(); + } + + // @formatter:off + @DisplayName("given existing aggregate," + + " when do domain operation on service," + + " then domain event is published") + // @formatter:on + @Test + void serviceEventsTest() { + Aggregate existingDomainEntity = new Aggregate(1, eventPublisher); + repository.save(existingDomainEntity); + + // when + domainService.serviceDomainOperation(existingDomainEntity.getId()); + + // then + verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class)); + } + + @TestConfiguration + public static class TestConfig { + @Bean + public DomainService domainService(AggregateRepository repository, ApplicationEventPublisher eventPublisher) { + return new DomainService(repository, eventPublisher); + } + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java new file mode 100644 index 0000000000..0f499834eb --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java @@ -0,0 +1,14 @@ +/** + * + */ +package com.baeldung.boot.ddd.event; + +import org.springframework.transaction.event.TransactionalEventListener; + +import com.baeldung.boot.ddd.event.DomainEvent; + +interface TestEventHandler { + @TransactionalEventListener + void handleEvent(DomainEvent event); + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/composite/repository/BookRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/composite/repository/BookRepositoryIntegrationTest.java new file mode 100644 index 0000000000..9d25acbd96 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/composite/repository/BookRepositoryIntegrationTest.java @@ -0,0 +1,64 @@ +package com.baeldung.composite.repository; + +import com.baeldung.composite.BookApplication; +import com.baeldung.composite.entity.Book; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = BookApplication.class) +public class BookRepositoryIntegrationTest { + + public static final String JAVA_101 = "Java101"; + public static final String JANE = "Jane"; + public static final String TECH = "Tech"; + @Autowired + BookRepository repository; + + @Before + public void setUp() { + Book book1 = new Book("John", JAVA_101, TECH, 20); + Book book2 = new Book(JANE, JAVA_101, "Arch", 25); + Book book3 = new Book(JANE, "Scala101", TECH, 23); + + repository.saveAll(Arrays.asList(book1, book2, book3)); + } + + @After + public void tearDown() { + repository.deleteAll(); + } + + @Test + public void testFindByName() { + List books = repository.findByIdName(JAVA_101); + + assertEquals(2, books.size()); + } + + @Test + public void testFindByAuthor() { + List books = repository.findByIdAuthor(JANE); + + assertEquals(2, books.size()); + } + + @Test + public void testFindByGenre() { + List books = repository.findByGenre(TECH); + + assertEquals(2, books.size()); + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java new file mode 100644 index 0000000000..b4c365a2d9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java @@ -0,0 +1,125 @@ +package com.baeldung.embeddable; + +import com.baeldung.Application; +import com.baeldung.embeddable.model.Company; +import com.baeldung.embeddable.model.ContactPerson; +import com.baeldung.embeddable.repositories.CompanyRepository; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Application.class}) +public class EmbeddableIntegrationTest { + + @Autowired + private CompanyRepository companyRepository; + + @Test + @Transactional + public void whenInsertingCompany_thenEmbeddedContactPersonDetailsAreMapped() { + ContactPerson contactPerson = new ContactPerson(); + contactPerson.setFirstName("First"); + contactPerson.setLastName("Last"); + contactPerson.setPhone("123-456-789"); + + Company company = new Company(); + company.setName("Company"); + company.setAddress("1st street"); + company.setPhone("987-654-321"); + company.setContactPerson(contactPerson); + + companyRepository.save(company); + + Company result = companyRepository.getOne(company.getId()); + + assertEquals("Company", result.getName()); + assertEquals("1st street", result.getAddress()); + assertEquals("987-654-321", result.getPhone()); + assertEquals("First", result.getContactPerson().getFirstName()); + assertEquals("Last", result.getContactPerson().getLastName()); + assertEquals("123-456-789", result.getContactPerson().getPhone()); + } + + @Test + @Transactional + public void whenFindingCompanyByContactPersonAttribute_thenCompanyIsReturnedProperly() { + ContactPerson contactPerson = new ContactPerson(); + contactPerson.setFirstName("Name"); + contactPerson.setLastName("Last"); + contactPerson.setPhone("123-456-789"); + + Company company = new Company(); + company.setName("Company"); + company.setAddress("1st street"); + company.setPhone("987-654-321"); + company.setContactPerson(contactPerson); + + companyRepository.save(company); + + List result = companyRepository.findByContactPersonFirstName("Name"); + + assertEquals(1, result.size()); + + result = companyRepository.findByContactPersonFirstName("FirstName"); + + assertEquals(0, result.size()); + } + + @Test + @Transactional + public void whenFindingCompanyByContactPersonAttributeWithJPQL_thenCompanyIsReturnedProperly() { + ContactPerson contactPerson = new ContactPerson(); + contactPerson.setFirstName("@QueryName"); + contactPerson.setLastName("Last"); + contactPerson.setPhone("123-456-789"); + + Company company = new Company(); + company.setName("Company"); + company.setAddress("1st street"); + company.setPhone("987-654-321"); + company.setContactPerson(contactPerson); + + companyRepository.save(company); + + List result = companyRepository.findByContactPersonFirstNameWithJPQL("@QueryName"); + + assertEquals(1, result.size()); + + result = companyRepository.findByContactPersonFirstNameWithJPQL("FirstName"); + + assertEquals(0, result.size()); + } + + @Test + @Transactional + public void whenFindingCompanyByContactPersonAttributeWithNativeQuery_thenCompanyIsReturnedProperly() { + ContactPerson contactPerson = new ContactPerson(); + contactPerson.setFirstName("NativeQueryName"); + contactPerson.setLastName("Last"); + contactPerson.setPhone("123-456-789"); + + Company company = new Company(); + company.setName("Company"); + company.setAddress("1st street"); + company.setPhone("987-654-321"); + company.setContactPerson(contactPerson); + + companyRepository.save(company); + + List result = companyRepository.findByContactPersonFirstNameWithNativeQuery("NativeQueryName"); + + assertEquals(1, result.size()); + + result = companyRepository.findByContactPersonFirstNameWithNativeQuery("FirstName"); + + assertEquals(0, result.size()); + } +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java new file mode 100644 index 0000000000..01551348c9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java @@ -0,0 +1,152 @@ +package com.baeldung.tx; + +import com.baeldung.tx.model.Payment; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.DefaultTransactionDefinition; +import org.springframework.transaction.support.TransactionCallbackWithoutResult; +import org.springframework.transaction.support.TransactionTemplate; + +import javax.persistence.EntityManager; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.transaction.annotation.Propagation.NOT_SUPPORTED; + +@DataJpaTest +@ActiveProfiles("test") +@Transactional(propagation = NOT_SUPPORTED) +class ManualTransactionIntegrationTest { + + @Autowired + private PlatformTransactionManager transactionManager; + + @Autowired + private EntityManager entityManager; + + private TransactionTemplate transactionTemplate; + + @BeforeEach + void setUp() { + transactionTemplate = new TransactionTemplate(transactionManager); + } + + @AfterEach + void flushDb() { + transactionTemplate.execute(status -> entityManager + .createQuery("delete from Payment") + .executeUpdate()); + } + + @Test + void givenAPayment_WhenNotDuplicate_ThenShouldCommit() { + Long id = transactionTemplate.execute(status -> { + Payment payment = new Payment(); + payment.setAmount(1000L); + payment.setReferenceNumber("Ref-1"); + payment.setState(Payment.State.SUCCESSFUL); + + entityManager.persist(payment); + + return payment.getId(); + }); + + Payment payment = entityManager.find(Payment.class, id); + assertThat(payment).isNotNull(); + } + + @Test + void givenAPayment_WhenMarkAsRollback_ThenShouldRollback() { + transactionTemplate.execute(status -> { + Payment payment = new Payment(); + payment.setAmount(1000L); + payment.setReferenceNumber("Ref-1"); + payment.setState(Payment.State.SUCCESSFUL); + + entityManager.persist(payment); + status.setRollbackOnly(); + + return payment.getId(); + }); + + assertThat(entityManager + .createQuery("select p from Payment p", Payment.class) + .getResultList()).isEmpty(); + } + + @Test + void givenTwoPayments_WhenRefIsDuplicate_ThenShouldRollback() { + try { + transactionTemplate.execute(s -> { + Payment first = new Payment(); + first.setAmount(1000L); + first.setReferenceNumber("Ref-1"); + first.setState(Payment.State.SUCCESSFUL); + + Payment second = new Payment(); + second.setAmount(2000L); + second.setReferenceNumber("Ref-1"); + second.setState(Payment.State.SUCCESSFUL); + + entityManager.persist(first); + entityManager.persist(second); + + return "Ref-1"; + }); + } catch (Exception ignored) { + } + + assertThat(entityManager + .createQuery("select p from Payment p", Payment.class) + .getResultList()).isEmpty(); + } + + @Test + void givenAPayment_WhenNotExpectingAnyResult_ThenShouldCommit() { + transactionTemplate.execute(new TransactionCallbackWithoutResult() { + @Override + protected void doInTransactionWithoutResult(TransactionStatus status) { + Payment payment = new Payment(); + payment.setReferenceNumber("Ref-1"); + payment.setState(Payment.State.SUCCESSFUL); + + entityManager.persist(payment); + } + }); + + assertThat(entityManager + .createQuery("select p from Payment p", Payment.class) + .getResultList()).hasSize(1); + } + + @Test + void givenAPayment_WhenUsingTxManager_ThenShouldCommit() { + DefaultTransactionDefinition definition = new DefaultTransactionDefinition(); + definition.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ); + definition.setTimeout(3); + + TransactionStatus status = transactionManager.getTransaction(definition); + try { + Payment payment = new Payment(); + payment.setReferenceNumber("Ref-1"); + payment.setState(Payment.State.SUCCESSFUL); + + entityManager.persist(payment); + transactionManager.commit(status); + } catch (Exception ex) { + transactionManager.rollback(status); + } + + assertThat(entityManager + .createQuery("select p from Payment p", Payment.class) + .getResultList()).hasSize(1); + } + +} diff --git a/persistence-modules/spring-data-jpa-annotations/src/test/java/lifecycleevents/UserRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-annotations/src/test/java/lifecycleevents/UserRepositoryIntegrationTest.java new file mode 100644 index 0000000000..078f437474 --- /dev/null +++ b/persistence-modules/spring-data-jpa-annotations/src/test/java/lifecycleevents/UserRepositoryIntegrationTest.java @@ -0,0 +1,80 @@ +package lifecycleevents; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.lifecycleevents.SpringBootLifecycleEventApplication; +import com.baeldung.lifecycleevents.model.User; +import com.baeldung.lifecycleevents.repository.UserRepository; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SpringBootLifecycleEventApplication.class) +public class UserRepositoryIntegrationTest { + + @Autowired + private UserRepository userRepository; + + @Before + public void setup() { + User user = new User(); + user.setFirstName("Jane"); + user.setLastName("Smith"); + user.setUserName("jsmith123"); + userRepository.save(user); + } + + @After + public void cleanup() { + userRepository.deleteAll(); + } + + @Test + public void whenNewUserProvided_userIsAdded() { + User user = new User(); + user.setFirstName("John"); + user.setLastName("Doe"); + user.setUserName("jdoe123"); + user = userRepository.save(user); + assertTrue(user.getId() > 0); + } + + @Test + public void whenUserNameProvided_userIsLoaded() { + User user = userRepository.findByUserName("jsmith123"); + assertNotNull(user); + assertEquals("jsmith123", user.getUserName()); + } + + @Test + public void whenExistingUserProvided_userIsUpdated() { + User user = userRepository.findByUserName("jsmith123"); + user.setFirstName("Joe"); + user = userRepository.save(user); + assertEquals("Joe", user.getFirstName()); + } + + @Test + public void whenExistingUserDeleted_userIsDeleted() { + User user = userRepository.findByUserName("jsmith123"); + userRepository.delete(user); + user = userRepository.findByUserName("jsmith123"); + assertNull(user); + } + + @Test + public void whenExistingUserLoaded_fullNameIsAvailable() { + String expectedFullName = "Jane Smith"; + User user = userRepository.findByUserName("jsmith123"); + assertEquals(expectedFullName, user.getFullName()); + } +} From 2ca8ec847cc3f31e3fcba06f82e5ade64187cdb6 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 19 Jul 2020 14:30:00 +0530 Subject: [PATCH 072/309] JAVA-66: New module spring-data-jpa-crud --- .../spring-data-jpa-crud/README.md | 21 ++++ .../spring-data-jpa-crud/pom.xml | 71 ++++++++++++++ .../main/java/com/baeldung/Application.java | 14 +++ .../DatasourceProxyBeanPostProcessor.java | 53 ++++++++++ .../baeldung/batchinserts/model/School.java | 45 +++++++++ .../baeldung/batchinserts/model/Student.java | 44 +++++++++ .../java/com/baeldung/boot/Application.java | 17 ++++ .../boot/daos/CustomerRepository.java | 19 ++++ .../daos/impl/PersonInsertRepository.java | 31 ++++++ .../com/baeldung/boot/domain/Customer.java | 56 +++++++++++ .../java/com/baeldung/boot/domain/Person.java | 47 +++++++++ .../web/controllers/CustomerController.java | 41 ++++++++ .../baeldung/datajpadelete/entity/Book.java | 51 ++++++++++ .../datajpadelete/entity/Category.java | 60 ++++++++++++ .../repository/BookRepository.java | 19 ++++ .../repository/CategoryRepository.java | 9 ++ .../java/com/baeldung/entity/Employee.java | 36 +++++++ .../main/java/com/baeldung/entity/Fruit.java | 40 ++++++++ .../repository/EmployeeRepository.java | 9 ++ .../baeldung/repository/FruitRepository.java | 27 +++++ .../schemageneration/AccountApplication.java | 12 +++ .../schemageneration/HibernateUtil.java | 39 ++++++++ .../schemageneration/model/Account.java | 74 ++++++++++++++ .../model/AccountSetting.java | 68 +++++++++++++ .../repository/AccountRepository.java | 8 ++ .../repository/AccountSettingRepository.java | 8 ++ .../src/main/resources/application.properties | 14 +++ .../src/main/resources/logback.xml | 13 +++ .../java/com/baeldung/SpringContextTest.java | 17 ++++ .../SpringJpaContextIntegrationTest.java | 19 ++++ .../BatchInsertIntegrationTest.java | 40 ++++++++ .../JpaBatchInsertsIntegrationTest.java | 98 +++++++++++++++++++ .../JpaNoBatchInsertsIntegrationTest.java | 41 ++++++++ .../batchinserts/TestObjectHelper.java | 20 ++++ ...PersonInsertRepositoryIntegrationTest.java | 82 ++++++++++++++++ .../DeleteFromRepositoryUnitTest.java | 72 ++++++++++++++ .../DeleteInRelationshipsUnitTest.java | 60 ++++++++++++ .../EmployeeRepositoryIntegrationTest.java | 40 ++++++++ .../FruitRepositoryIntegrationTest.java | 75 ++++++++++++++ .../AccountRepositoryIntegrationTest.java | 72 ++++++++++++++ .../application-batchinserts.properties | 6 ++ .../resources/application-test.properties | 2 + .../src/test/resources/test-fruit-data.sql | 6 ++ 43 files changed, 1596 insertions(+) create mode 100644 persistence-modules/spring-data-jpa-crud/README.md create mode 100644 persistence-modules/spring-data-jpa-crud/pom.xml create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/Application.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/model/School.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/model/Student.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/Application.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/daos/CustomerRepository.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/domain/Customer.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/domain/Person.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/entity/Book.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/entity/Category.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/entity/Employee.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/entity/Fruit.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/repository/EmployeeRepository.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/repository/FruitRepository.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/AccountApplication.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/HibernateUtil.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/model/Account.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/resources/application.properties create mode 100644 persistence-modules/spring-data-jpa-crud/src/main/resources/logback.xml create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/SpringContextTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/repository/FruitRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/resources/application-batchinserts.properties create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/resources/application-test.properties create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/resources/test-fruit-data.sql diff --git a/persistence-modules/spring-data-jpa-crud/README.md b/persistence-modules/spring-data-jpa-crud/README.md new file mode 100644 index 0000000000..dc0c78c87e --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/README.md @@ -0,0 +1,21 @@ +## Spring Data JPA - CRUD + +This module contains articles about CRUD operations in Spring Data JPA + +### Relevant Articles: +- [Spring Data JPA – Derived Delete Methods](https://www.baeldung.com/spring-data-jpa-deleteby) +- [Spring Data JPA Delete and Relationships](https://www.baeldung.com/spring-data-jpa-delete) +- [INSERT Statement in JPA](https://www.baeldung.com/jpa-insert) +- [Spring Data JPA Batch Inserts](https://www.baeldung.com/spring-data-jpa-batch-inserts) +- [Batch Insert/Update with Hibernate/JPA](https://www.baeldung.com/jpa-hibernate-batch-insert-update) +- [Difference Between save() and saveAndFlush() in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-save-saveandflush) +- [Generate Database Schema with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-generate-db-schema) + +### Eclipse Config +After importing the project into Eclipse, you may see the following error: +"No persistence xml file found in project" + +This can be ignored: +- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" +Or: +- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator diff --git a/persistence-modules/spring-data-jpa-crud/pom.xml b/persistence-modules/spring-data-jpa-crud/pom.xml new file mode 100644 index 0000000000..1708d14fc2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + spring-data-jpa-crud + spring-data-jpa-crud + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + com.google.guava + guava + ${guava.version} + + + com.h2database + h2 + + + net.ttddyy + datasource-proxy + ${datasource-proxy.version} + + + org.postgresql + postgresql + + + com.h2database + h2 + runtime + + + + + org.testcontainers + postgresql + ${testcontainers.version} + test + + + + + + 1.4.1 + 21.0 + 1.12.2 + + + diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..ce10072031 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/Application.java @@ -0,0 +1,14 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +@SpringBootApplication +@EnableJpaRepositories +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java new file mode 100644 index 0000000000..504357db44 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java @@ -0,0 +1,53 @@ +package com.baeldung.batchinserts; + +import java.lang.reflect.Method; +import javax.sql.DataSource; +import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.aop.framework.ProxyFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; +import org.springframework.util.ReflectionUtils; + +@Component +@Profile("batchinserts") +public class DatasourceProxyBeanPostProcessor implements BeanPostProcessor { + + @Override + public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException { + return bean; + } + + @Override + public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { + if (bean instanceof DataSource) { + ProxyFactory factory = new ProxyFactory(bean); + factory.setProxyTargetClass(true); + factory.addAdvice(new ProxyDataSourceInterceptor((DataSource) bean)); + return factory.getProxy(); + } + + return bean; + } + + private static class ProxyDataSourceInterceptor implements MethodInterceptor { + + private final DataSource dataSource; + + public ProxyDataSourceInterceptor(final DataSource dataSource) { + this.dataSource = ProxyDataSourceBuilder.create(dataSource).name("Batch-Insert-Logger").asJson().countQuery().logQueryToSysOut().build(); + } + + @Override + public Object invoke(final MethodInvocation invocation) throws Throwable { + Method proxyMethod = ReflectionUtils.findMethod(dataSource.getClass(), invocation.getMethod().getName()); + if (proxyMethod != null) { + return proxyMethod.invoke(dataSource, invocation.getArguments()); + } + return invocation.proceed(); + } + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/model/School.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/model/School.java new file mode 100644 index 0000000000..6d2f333ac7 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/model/School.java @@ -0,0 +1,45 @@ +package com.baeldung.batchinserts.model; + +import java.util.List; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +@Entity +public class School { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String name; + + @OneToMany(mappedBy = "school") + private List students; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getStudents() { + return students; + } + + public void setStudents(List students) { + this.students = students; + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/model/Student.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/model/Student.java new file mode 100644 index 0000000000..d38214f122 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/batchinserts/model/Student.java @@ -0,0 +1,44 @@ +package com.baeldung.batchinserts.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class Student { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String name; + + @ManyToOne + private School school; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public School getSchool() { + return school; + } + + public void setSchool(School school) { + this.school = school; + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/Application.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/Application.java new file mode 100644 index 0000000000..aaca760499 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/Application.java @@ -0,0 +1,17 @@ +package com.baeldung.boot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +@SpringBootApplication +@EnableJpaRepositories("com.baeldung") +@EntityScan("com.baeldung") +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/daos/CustomerRepository.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/daos/CustomerRepository.java new file mode 100644 index 0000000000..7cb7e45b27 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/daos/CustomerRepository.java @@ -0,0 +1,19 @@ +package com.baeldung.boot.daos; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.boot.domain.Customer; + +/** + * JPA CrudRepository interface + * + * @author ysharma2512 + * + */ +@Repository +@Transactional +public interface CustomerRepository extends CrudRepository{ + +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java new file mode 100644 index 0000000000..373532e1c3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java @@ -0,0 +1,31 @@ +package com.baeldung.boot.daos.impl; + +import org.springframework.stereotype.Repository; + +import com.baeldung.boot.domain.Person; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; + +@Repository +public class PersonInsertRepository { + + @PersistenceContext + private EntityManager entityManager; + + @Transactional + public void insertWithQuery(Person person) { + entityManager.createNativeQuery("INSERT INTO person (id, first_name, last_name) VALUES (?,?,?)") + .setParameter(1, person.getId()) + .setParameter(2, person.getFirstName()) + .setParameter(3, person.getLastName()) + .executeUpdate(); + } + + @Transactional + public void insertWithEntityManager(Person person) { + this.entityManager.persist(person); + } + +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/domain/Customer.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/domain/Customer.java new file mode 100644 index 0000000000..af88be0be6 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/domain/Customer.java @@ -0,0 +1,56 @@ +package com.baeldung.boot.domain; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +/** + * Customer Entity class + * @author ysharma2512 + * + */ +@Entity +public class Customer { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + private String firstName; + private String lastName; + + public Customer(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public String toString() { + return String.format("Customer[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); + } + +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/domain/Person.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/domain/Person.java new file mode 100644 index 0000000000..88894ccc72 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/domain/Person.java @@ -0,0 +1,47 @@ +package com.baeldung.boot.domain; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Person { + + @Id + private Long id; + private String firstName; + private String lastName; + + public Person() { + } + + public Person(Long id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java new file mode 100644 index 0000000000..e13afd9b45 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java @@ -0,0 +1,41 @@ +package com.baeldung.boot.web.controllers; + +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.List; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.boot.daos.CustomerRepository; +import com.baeldung.boot.domain.Customer; + +/** + * A simple controller to test the JPA CrudRepository operations + * controllers + * + * @author ysharma2512 + * + */ +@RestController +public class CustomerController { + + CustomerRepository customerRepository; + + public CustomerController(CustomerRepository customerRepository2) { + this.customerRepository = customerRepository2; + } + + @PostMapping("/customers") + public ResponseEntity> insertCustomers() throws URISyntaxException { + Customer c1 = new Customer("James", "Gosling"); + Customer c2 = new Customer("Doug", "Lea"); + Customer c3 = new Customer("Martin", "Fowler"); + Customer c4 = new Customer("Brian", "Goetz"); + List customers = Arrays.asList(c1, c2, c3, c4); + customerRepository.saveAll(customers); + return ResponseEntity.ok(customers); + } + +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/entity/Book.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/entity/Book.java new file mode 100644 index 0000000000..deac24548a --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/entity/Book.java @@ -0,0 +1,51 @@ +package com.baeldung.datajpadelete.entity; + +import javax.persistence.*; + +@Entity +public class Book { + + @Id + @GeneratedValue + private Long id; + private String title; + + @ManyToOne + private Category category; + + public Book() { + } + + public Book(String title) { + this.title = title; + } + + public Book(String title, Category category) { + this.title = title; + this.category = category; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/entity/Category.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/entity/Category.java new file mode 100644 index 0000000000..16f1a4157f --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/entity/Category.java @@ -0,0 +1,60 @@ +package com.baeldung.datajpadelete.entity; + +import javax.persistence.*; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Entity +public class Category { + + @Id + @GeneratedValue + private Long id; + private String name; + + @OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true) + private List books; + + public Category() { + } + + public Category(String name) { + this.name = name; + } + + public Category(String name, Book... books) { + this.name = name; + this.books = Stream.of(books).collect(Collectors.toList()); + this.books.forEach(x -> x.setCategory(this)); + } + + public Category(String name, List books) { + this.name = name; + this.books = books; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getBooks() { + return books; + } + + public void setBooks(List books) { + this.books = books; + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java new file mode 100644 index 0000000000..5d0f45f127 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java @@ -0,0 +1,19 @@ +package com.baeldung.datajpadelete.repository; + +import com.baeldung.datajpadelete.entity.Book; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +@Repository +public interface BookRepository extends CrudRepository { + + long deleteByTitle(String title); + + @Modifying + @Query("delete from Book b where b.title=:title") + void deleteBooks(@Param("title") String title); + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java new file mode 100644 index 0000000000..6fe7058a78 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.datajpadelete.repository; + +import com.baeldung.datajpadelete.entity.Category; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CategoryRepository extends CrudRepository { +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/entity/Employee.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/entity/Employee.java new file mode 100644 index 0000000000..4c3dbd25b7 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/entity/Employee.java @@ -0,0 +1,36 @@ +package com.baeldung.entity; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Employee { + + @Id + private Long id; + private String name; + + public Employee() { + } + + public Employee(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/entity/Fruit.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/entity/Fruit.java new file mode 100644 index 0000000000..d45ac33db8 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/entity/Fruit.java @@ -0,0 +1,40 @@ +package com.baeldung.entity; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@Entity +public class Fruit { + + @Id + private long id; + private String name; + private String color; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/repository/EmployeeRepository.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/repository/EmployeeRepository.java new file mode 100644 index 0000000000..8f0a80814b --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/repository/EmployeeRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.entity.Employee; + +public interface EmployeeRepository extends JpaRepository { + +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/repository/FruitRepository.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/repository/FruitRepository.java new file mode 100644 index 0000000000..5055252adf --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/repository/FruitRepository.java @@ -0,0 +1,27 @@ +package com.baeldung.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import com.baeldung.entity.Fruit; + +@Repository +public interface FruitRepository extends JpaRepository { + + Long deleteByName(String name); + + List deleteByColor(String color); + + Long removeByName(String name); + + List removeByColor(String color); + + @Modifying + @Query("delete from Fruit f where f.name=:name or f.color=:color") + int deleteFruits(@Param("name") String name, @Param("color") String color); +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/AccountApplication.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/AccountApplication.java new file mode 100644 index 0000000000..547992a6c1 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/AccountApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.schemageneration; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AccountApplication { + + public static void main(String[] args) { + SpringApplication.run(AccountApplication.class, args); + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/HibernateUtil.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/HibernateUtil.java new file mode 100644 index 0000000000..7d69d65705 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/HibernateUtil.java @@ -0,0 +1,39 @@ +package com.baeldung.schemageneration; + +import com.baeldung.schemageneration.model.Account; +import com.baeldung.schemageneration.model.AccountSetting; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Environment; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.schema.TargetType; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +public class HibernateUtil { + + /** + * Generates database create commands for the specified entities using Hibernate native API, SchemaExport. + * Creation commands are exported into the create.sql file. + */ + public static void generateSchema() { + Map settings = new HashMap<>(); + settings.put(Environment.URL, "jdbc:h2:mem:schema"); + + StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(settings).build(); + + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + metadataSources.addAnnotatedClass(Account.class); + metadataSources.addAnnotatedClass(AccountSetting.class); + Metadata metadata = metadataSources.buildMetadata(); + + SchemaExport schemaExport = new SchemaExport(); + schemaExport.setFormat(true); + schemaExport.setOutputFile("create.sql"); + schemaExport.createOnly(EnumSet.of(TargetType.SCRIPT), metadata); + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/model/Account.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/model/Account.java new file mode 100644 index 0000000000..785e275e26 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/model/Account.java @@ -0,0 +1,74 @@ +package com.baeldung.schemageneration.model; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Table(name = "accounts") +public class Account { + + @Id + @GeneratedValue + private Long id; + + @Column(nullable = false, length = 100) + private String name; + + @Column(name = "email_address") + private String emailAddress; + + @OneToMany(mappedBy = "account", cascade = CascadeType.ALL) + private List accountSettings = new ArrayList<>(); + + public Account() { + } + + public Account(String name, String emailAddress) { + this.name = name; + this.emailAddress = emailAddress; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public List getAccountSettings() { + return accountSettings; + } + + public void setAccountSettings(List accountSettings) { + this.accountSettings = accountSettings; + } + + public void addAccountSetting(AccountSetting setting) { + this.accountSettings.add(setting); + setting.setAccount(this); + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java new file mode 100644 index 0000000000..61e43894a8 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java @@ -0,0 +1,68 @@ +package com.baeldung.schemageneration.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "account_settings") +public class AccountSetting { + + @Id + @GeneratedValue + private Long id; + + @Column(name = "name", nullable = false) + private String settingName; + + @Column(name = "value", nullable = false) + private String settingValue; + + @ManyToOne() + @JoinColumn(name ="account_id", nullable = false) + private Account account; + + public AccountSetting() { + } + + public AccountSetting(String settingName, String settingValue) { + this.settingName = settingName; + this.settingValue = settingValue; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getSettingName() { + return settingName; + } + + public void setSettingName(String settingName) { + this.settingName = settingName; + } + + public String getSettingValue() { + return settingValue; + } + + public void setSettingValue(String settingValue) { + this.settingValue = settingValue; + } + + public Account getAccount() { + return account; + } + + public void setAccount(Account account) { + this.account = account; + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java new file mode 100644 index 0000000000..dc57ffe6d3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.schemageneration.repository; + +import com.baeldung.schemageneration.model.Account; +import org.springframework.data.repository.CrudRepository; + +public interface AccountRepository extends CrudRepository { + Account findByName(String name); +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java new file mode 100644 index 0000000000..c2b8ff7398 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.schemageneration.repository; + +import com.baeldung.schemageneration.model.AccountSetting; +import org.springframework.data.repository.CrudRepository; + +public interface AccountSettingRepository extends CrudRepository { + AccountSetting findByAccountId(Long accountId); +} diff --git a/persistence-modules/spring-data-jpa-crud/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-crud/src/main/resources/application.properties new file mode 100644 index 0000000000..af0df308cd --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/resources/application.properties @@ -0,0 +1,14 @@ +spring.main.allow-bean-definition-overriding=true + +spring.jpa.properties.hibernate.jdbc.batch_size=4 +spring.jpa.properties.hibernate.order_inserts=true +spring.jpa.properties.hibernate.order_updates=true +spring.jpa.properties.hibernate.generate_statistics=true + +# JPA-Schema-Generation +# Use below configuration to generate database schema create commands based on the entity models +# and export them into the create.sql file +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-source=metadata +#spring.jpa.properties.hibernate.format_sql=true \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/main/resources/logback.xml b/persistence-modules/spring-data-jpa-crud/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..eaccf4acba --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/SpringContextTest.java @@ -0,0 +1,17 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.Application; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java new file mode 100644 index 0000000000..27c71c5bcc --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java @@ -0,0 +1,19 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.Application; + +@RunWith(SpringRunner.class) +@DataJpaTest +@ContextConfiguration(classes = Application.class) +public class SpringJpaContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java new file mode 100644 index 0000000000..7ddf36d3f0 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java @@ -0,0 +1,40 @@ +package com.baeldung.batchinserts; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; + +import com.baeldung.boot.Application; +import com.baeldung.boot.daos.CustomerRepository; +import com.baeldung.boot.web.controllers.CustomerController; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes=Application.class) +@AutoConfigureMockMvc +public class BatchInsertIntegrationTest { + + @Autowired + private CustomerRepository customerRepository; + private MockMvc mockMvc; + @Before + public void setUp() throws Exception { + mockMvc = MockMvcBuilders.standaloneSetup( new CustomerController(customerRepository)) + .build(); + } + + @Test + public void whenInsertingCustomers_thenCustomersAreCreated() throws Exception { + this.mockMvc.perform(post("/customers")) + .andExpect(status().isOk()); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java new file mode 100644 index 0000000000..311f227322 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java @@ -0,0 +1,98 @@ +package com.baeldung.batchinserts; + +import static com.baeldung.batchinserts.TestObjectHelper.createSchool; +import static com.baeldung.batchinserts.TestObjectHelper.createStudent; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; + +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.batchinserts.model.School; +import com.baeldung.batchinserts.model.Student; +import com.baeldung.boot.Application; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +@Transactional +@ActiveProfiles("batchinserts") +public class JpaBatchInsertsIntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + private static final int BATCH_SIZE = 5; + + @Transactional + @Test + public void whenInsertingSingleTypeOfEntity_thenCreatesSingleBatch() { + for (int i = 0; i < 10; i++) { + School school = createSchool(i); + entityManager.persist(school); + } + } + + @Transactional + @Test + public void whenFlushingAfterBatch_ThenClearsMemory() { + for (int i = 0; i < 10; i++) { + if (i > 0 && i % BATCH_SIZE == 0) { + entityManager.flush(); + entityManager.clear(); + } + + School school = createSchool(i); + entityManager.persist(school); + } + } + + @Transactional + @Test + public void whenThereAreMultipleEntities_ThenCreatesNewBatch() { + for (int i = 0; i < 10; i++) { + if (i > 0 && i % BATCH_SIZE == 0) { + entityManager.flush(); + entityManager.clear(); + } + + School school = createSchool(i); + entityManager.persist(school); + Student firstStudent = createStudent(school); + Student secondStudent = createStudent(school); + entityManager.persist(firstStudent); + entityManager.persist(secondStudent); + } + } + + @Transactional + @Test + public void whenUpdatingEntities_thenCreatesBatch() { + for (int i = 0; i < 10; i++) { + School school = createSchool(i); + entityManager.persist(school); + } + + entityManager.flush(); + + TypedQuery schoolQuery = entityManager.createQuery("SELECT s from School s", School.class); + List allSchools = schoolQuery.getResultList(); + + for (School school : allSchools) { + school.setName("Updated_" + school.getName()); + } + } + + @After + public void tearDown() { + entityManager.flush(); + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java new file mode 100644 index 0000000000..75b3f1f3aa --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java @@ -0,0 +1,41 @@ +package com.baeldung.batchinserts; + +import static com.baeldung.batchinserts.TestObjectHelper.createSchool; + +import com.baeldung.batchinserts.model.School; +import com.baeldung.boot.Application; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +@Transactional +@ActiveProfiles("batchinserts") +@TestPropertySource(properties = "spring.jpa.properties.hibernate.jdbc.batch_size=-1") +public class JpaNoBatchInsertsIntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + @Test + public void whenNotConfigured_ThenSendsInsertsSeparately() { + for (int i = 0; i < 10; i++) { + School school = createSchool(i); + entityManager.persist(school); + } + } + + @After + public void tearDown() { + entityManager.flush(); + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java new file mode 100644 index 0000000000..fcd26cb721 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java @@ -0,0 +1,20 @@ +package com.baeldung.batchinserts; + +import com.baeldung.batchinserts.model.School; +import com.baeldung.batchinserts.model.Student; + +public class TestObjectHelper { + + public static School createSchool(int nameIdentifier) { + School school = new School(); + school.setName("School" + (nameIdentifier + 1)); + return school; + } + + public static Student createStudent(School school) { + Student student = new Student(); + student.setName("Student-" + school.getName()); + student.setSchool(school); + return student; + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java new file mode 100644 index 0000000000..9d45c17035 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java @@ -0,0 +1,82 @@ +package com.baeldung.boot.daos; + +import com.baeldung.boot.daos.impl.PersonInsertRepository; +import com.baeldung.boot.domain.Person; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.persistence.EntityExistsException; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceException; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +@RunWith(SpringRunner.class) +@DataJpaTest +@Import(PersonInsertRepository.class) +public class PersonInsertRepositoryIntegrationTest { + + private static final Long ID = 1L; + private static final String FIRST_NAME = "firstname"; + private static final String LAST_NAME = "lastname"; + private static final Person PERSON = new Person(ID, FIRST_NAME, LAST_NAME); + + @Autowired + private PersonInsertRepository personInsertRepository; + + @Autowired + private EntityManager entityManager; + + @Test + public void givenPersonEntity_whenInsertWithNativeQuery_ThenPersonIsPersisted() { + insertWithQuery(); + + assertPersonPersisted(); + } + + @Test + public void givenPersonEntity_whenInsertedTwiceWithNativeQuery_thenPersistenceExceptionExceptionIsThrown() { + assertThatExceptionOfType(PersistenceException.class).isThrownBy(() -> { + insertWithQuery(); + insertWithQuery(); + }); + } + + @Test + public void givenPersonEntity_whenInsertWithEntityManager_thenPersonIsPersisted() { + insertPersonWithEntityManager(); + + assertPersonPersisted(); + } + + @Test + public void givenPersonEntity_whenInsertedTwiceWithEntityManager_thenEntityExistsExceptionIsThrown() { + assertThatExceptionOfType(EntityExistsException.class).isThrownBy(() -> { + insertPersonWithEntityManager(); + insertPersonWithEntityManager(); + }); + } + + private void insertWithQuery() { + personInsertRepository.insertWithQuery(PERSON); + } + + private void insertPersonWithEntityManager() { + personInsertRepository.insertWithEntityManager(new Person(ID, FIRST_NAME, LAST_NAME)); + } + + private void assertPersonPersisted() { + Person person = entityManager.find(Person.class, ID); + + assertThat(person).isNotNull(); + assertThat(person.getId()).isEqualTo(PERSON.getId()); + assertThat(person.getFirstName()).isEqualTo(PERSON.getFirstName()); + assertThat(person.getLastName()).isEqualTo(PERSON.getLastName()); + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java new file mode 100644 index 0000000000..5f4a36bc0e --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java @@ -0,0 +1,72 @@ +package com.baeldung.datajpadelete; + +import com.baeldung.Application; +import com.baeldung.datajpadelete.entity.Book; +import com.baeldung.datajpadelete.repository.BookRepository; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Application.class}) +public class DeleteFromRepositoryUnitTest { + + @Autowired + private BookRepository repository; + + Book book1; + Book book2; + + @Before + public void setup() { + book1 = new Book("The Hobbit"); + book2 = new Book("All Quiet on the Western Front"); + + repository.saveAll(Arrays.asList(book1, book2)); + } + + @After + public void teardown() { + repository.deleteAll(); + } + + @Test + public void whenDeleteByIdFromRepository_thenDeletingShouldBeSuccessful() { + repository.deleteById(book1.getId()); + + assertThat(repository.count()).isEqualTo(1); + } + + @Test + public void whenDeleteAllFromRepository_thenRepositoryShouldBeEmpty() { + repository.deleteAll(); + + assertThat(repository.count()).isEqualTo(0); + } + + @Test + @Transactional + public void whenDeleteFromDerivedQuery_thenDeletingShouldBeSuccessful() { + long deletedRecords = repository.deleteByTitle("The Hobbit"); + + assertThat(deletedRecords).isEqualTo(1); + } + + @Test + @Transactional + public void whenDeleteFromCustomQuery_thenDeletingShouldBeSuccessful() { + repository.deleteBooks("The Hobbit"); + + assertThat(repository.count()).isEqualTo(1); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java new file mode 100644 index 0000000000..6275ace6e0 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java @@ -0,0 +1,60 @@ +package com.baeldung.datajpadelete; + +import com.baeldung.Application; +import com.baeldung.datajpadelete.entity.Book; +import com.baeldung.datajpadelete.entity.Category; +import com.baeldung.datajpadelete.repository.BookRepository; +import com.baeldung.datajpadelete.repository.CategoryRepository; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Application.class}) +public class DeleteInRelationshipsUnitTest { + + @Autowired + private BookRepository bookRepository; + + @Autowired + private CategoryRepository categoryRepository; + + @Before + public void setup() { + Book book1 = new Book("The Hobbit"); + Category category1 = new Category("Cat1", book1); + categoryRepository.save(category1); + + Book book2 = new Book("All Quiet on the Western Front"); + Category category2 = new Category("Cat2", book2); + categoryRepository.save(category2); + } + + @After + public void teardown() { + bookRepository.deleteAll(); + categoryRepository.deleteAll(); + } + + @Test + public void whenDeletingCategories_thenBooksShouldAlsoBeDeleted() { + categoryRepository.deleteAll(); + + assertThat(bookRepository.count()).isEqualTo(0); + assertThat(categoryRepository.count()).isEqualTo(0); + } + + @Test + public void whenDeletingBooks_thenCategoriesShouldAlsoBeDeleted() { + bookRepository.deleteAll(); + + assertThat(bookRepository.count()).isEqualTo(0); + assertThat(categoryRepository.count()).isEqualTo(2); + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java new file mode 100644 index 0000000000..0fc9918701 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java @@ -0,0 +1,40 @@ +package com.baeldung.repository; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.Application; +import com.baeldung.entity.Employee; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +public class EmployeeRepositoryIntegrationTest { + + private static final Employee EMPLOYEE1 = new Employee(1L, "John"); + private static final Employee EMPLOYEE2 = new Employee(2L, "Alice"); + + @Autowired + private EmployeeRepository employeeRepository; + + @Test + public void givenEmployeeEntity_whenInsertWithSave_ThenEmployeeIsPersisted() { + employeeRepository.save(EMPLOYEE1); + assertEmployeePersisted(EMPLOYEE1); + } + + @Test + public void givenEmployeeEntity_whenInsertWithSaveAndFlush_ThenEmployeeIsPersisted() { + employeeRepository.saveAndFlush(EMPLOYEE2); + assertEmployeePersisted(EMPLOYEE2); + } + + private void assertEmployeePersisted(Employee input) { + Employee employee = employeeRepository.getOne(input.getId()); + assertThat(employee).isNotNull(); + } +} diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/repository/FruitRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/repository/FruitRepositoryIntegrationTest.java new file mode 100644 index 0000000000..cf771dc833 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/repository/FruitRepositoryIntegrationTest.java @@ -0,0 +1,75 @@ +package com.baeldung.repository; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.entity.Fruit; + +@RunWith(SpringRunner.class) +@SpringBootTest +class FruitRepositoryIntegrationTest { + + @Autowired + private FruitRepository fruitRepository; + + @Transactional + @Test + @Sql(scripts = { "/test-fruit-data.sql" }) + public void givenFruits_WhenDeletedByColor_ThenDeletedFruitsShouldReturn() { + + List fruits = fruitRepository.deleteByColor("green"); + + assertEquals("number of fruits are not matching", 2, fruits.size()); + fruits.forEach(fruit -> assertEquals("Its not a green fruit", "green", fruit.getColor())); + } + + @Transactional + @Test + @Sql(scripts = { "/test-fruit-data.sql" }) + public void givenFruits_WhenDeletedByName_ThenDeletedFruitCountShouldReturn() { + + Long deletedFruitCount = fruitRepository.deleteByName("apple"); + + assertEquals("deleted fruit count is not matching", 1, deletedFruitCount.intValue()); + } + + @Transactional + @Test + @Sql(scripts = { "/test-fruit-data.sql" }) + public void givenFruits_WhenRemovedByColor_ThenDeletedFruitsShouldReturn() { + + List fruits = fruitRepository.removeByColor("green"); + + assertEquals("number of fruits are not matching", 2, fruits.size()); + fruits.forEach(fruit -> assertEquals("Its not a green fruit", "green", fruit.getColor())); + } + + @Transactional + @Test + @Sql(scripts = { "/test-fruit-data.sql" }) + public void givenFruits_WhenRemovedByName_ThenDeletedFruitCountShouldReturn() { + + Long deletedFruitCount = fruitRepository.removeByName("apple"); + + assertEquals("deleted fruit count is not matching", 1, deletedFruitCount.intValue()); + } + + @Transactional + @Test + @Sql(scripts = { "/test-fruit-data.sql" }) + public void givenFruits_WhenDeletedByColorOrName_ThenDeletedFruitsShouldReturn() { + + int deletedCount = fruitRepository.deleteFruits("apple", "green"); + + assertEquals("number of fruits are not matching", 3, deletedCount); + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java new file mode 100644 index 0000000000..86a7671fe4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java @@ -0,0 +1,72 @@ +package com.baeldung.schemageneration; + +import com.baeldung.schemageneration.model.Account; +import com.baeldung.schemageneration.model.AccountSetting; +import com.baeldung.schemageneration.repository.AccountRepository; +import com.baeldung.schemageneration.repository.AccountSettingRepository; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AccountApplication.class) +public class AccountRepositoryIntegrationTest { + + private static final String USER_NAME = "Eduard"; + private static final String USER_EMAIL_ADDRESS = "eduard@gmx.com"; + private static final String ACCOUNT_SETTING_NAME = "Timezone"; + private static final String ACCOUNT_SETTING_VALUE = "UTC+02"; + + @Autowired + private AccountRepository accountRepository; + + @Autowired + private AccountSettingRepository accountSettingRepository; + + @After + public void tearDown() { + accountRepository.deleteAll(); + } + + @Test + public void givenNewAccount_whenSave_thenSuccess() { + Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS); + accountRepository.save(account); + + assertEquals(1, accountRepository.count()); + } + + @Test + public void givenSavedAccount_whenFindByName_thenFound() { + Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS); + accountRepository.save(account); + + Account accountFound = accountRepository.findByName(USER_NAME); + + assertNotNull(accountFound); + assertEquals(USER_NAME, accountFound.getName()); + assertEquals(USER_EMAIL_ADDRESS, accountFound.getEmailAddress()); + } + + @Test + public void givenSavedAccount_whenAccountSettingIsAdded_thenPersisted() { + Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS); + account.addAccountSetting(new AccountSetting(ACCOUNT_SETTING_NAME, ACCOUNT_SETTING_VALUE)); + accountRepository.save(account); + + Account accountFound = accountRepository.findByName(USER_NAME); + assertNotNull(accountFound); + AccountSetting accountSetting = accountSettingRepository.findByAccountId(accountFound.getId()); + + assertNotNull(accountSetting); + assertEquals(ACCOUNT_SETTING_NAME, accountSetting.getSettingName()); + assertEquals(ACCOUNT_SETTING_VALUE, accountSetting.getSettingValue()); + } + +} diff --git a/persistence-modules/spring-data-jpa-crud/src/test/resources/application-batchinserts.properties b/persistence-modules/spring-data-jpa-crud/src/test/resources/application-batchinserts.properties new file mode 100644 index 0000000000..4141f5668e --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/resources/application-batchinserts.properties @@ -0,0 +1,6 @@ +spring.jpa.show-sql=false + +spring.jpa.properties.hibernate.jdbc.batch_size=5 +spring.jpa.properties.hibernate.order_inserts=true +spring.jpa.properties.hibernate.order_updates=true +spring.jpa.properties.hibernate.batch_versioned_data=true \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/test/resources/application-test.properties b/persistence-modules/spring-data-jpa-crud/src/test/resources/application-test.properties new file mode 100644 index 0000000000..f9497c8f37 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/resources/application-test.properties @@ -0,0 +1,2 @@ +spring.jpa.hibernate.ddl-auto=update +spring.datasource.url=jdbc:h2:mem:jpa3 \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/test/resources/test-fruit-data.sql b/persistence-modules/spring-data-jpa-crud/src/test/resources/test-fruit-data.sql new file mode 100644 index 0000000000..d99f42e5a7 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/resources/test-fruit-data.sql @@ -0,0 +1,6 @@ +truncate table fruit; + +insert into fruit(id,name,color) values (1,'apple','red'); +insert into fruit(id,name,color) values (2,'custard apple','green'); +insert into fruit(id,name,color) values (3,'mango','yellow'); +insert into fruit(id,name,color) values (4,'guava','green'); \ No newline at end of file From 2f815070760802c98023faff9969e8483d6e4661 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 19 Jul 2020 14:30:26 +0530 Subject: [PATCH 073/309] JAVA-66: New module spring-data-jpa-enterprise --- .../spring-data-jpa-enterprise/README.md | 24 + .../spring-data-jpa-enterprise/pom.xml | 107 ++++ .../main/java/com/baeldung/Application.java | 13 + .../java/com/baeldung/boot/Application.java | 17 + .../boot/config/PersistenceConfiguration.java | 23 + .../boot/daos/IBarCrudRepository.java | 11 + .../java/com/baeldung/boot/daos/IFooDao.java | 13 + .../boot/daos/user/UserRepository.java | 99 ++++ .../boot/daos/user/UserRepositoryCustom.java | 14 + .../daos/user/UserRepositoryCustomImpl.java | 57 ++ .../java/com/baeldung/boot/domain/Bar.java | 220 +++++++ .../java/com/baeldung/boot/domain/Foo.java | 94 +++ .../com/baeldung/boot/domain/Possession.java | 83 +++ .../java/com/baeldung/boot/domain/User.java | 132 +++++ .../baeldung/boot/services/IBarService.java | 7 + .../baeldung/boot/services/IFooService.java | 14 + .../baeldung/boot/services/IOperations.java | 26 + .../boot/services/impl/AbstractService.java | 61 ++ .../impl/AbstractSpringDataJpaService.java | 45 ++ .../impl/BarSpringDataJpaService.java | 31 + .../boot/services/impl/FooService.java | 55 ++ .../ElementCollectionApplication.java | 11 + .../elementcollection/model/Employee.java | 68 +++ .../elementcollection/model/Phone.java | 62 ++ .../repository/EmployeeRepository.java | 46 ++ .../multipledb/MultipleDbApplication.java | 14 + .../PersistenceProductAutoConfiguration.java | 71 +++ .../PersistenceProductConfiguration.java | 68 +++ .../PersistenceUserAutoConfiguration.java | 75 +++ .../PersistenceUserConfiguration.java | 69 +++ .../dao/product/ProductRepository.java | 14 + .../dao/user/PossessionRepository.java | 9 + .../multipledb/dao/user/UserRepository.java | 8 + .../multipledb/model/product/Product.java | 67 +++ .../model/user/PossessionMultipleDB.java | 82 +++ .../multipledb/model/user/UserMultipleDB.java | 88 +++ .../com/baeldung/namingstrategy/Person.java | 35 ++ .../namingstrategy/PersonRepository.java | 6 + .../QuotedLowerCaseNamingStrategy.java | 12 + .../QuotedUpperCaseNamingStrategy.java | 12 + ...ingDataJpaNamingConventionApplication.java | 7 + .../UnquotedLowerCaseNamingStrategy.java | 12 + .../UnquotedUpperCaseNamingStrategy.java | 12 + .../com/baeldung/osiv/OsivApplication.java | 13 + .../com/baeldung/osiv/model/BasicUser.java | 42 ++ .../osiv/repository/BasicUserRepository.java | 19 + .../osiv/service/SimpleUserService.java | 25 + .../baeldung/osiv/service/UserService.java | 9 + .../baeldung/osiv/web/DetailedUserDto.java | 45 ++ .../com/baeldung/osiv/web/UserController.java | 27 + .../PartialUpdateApplication.java | 12 + .../partialupdate/model/ContactPhone.java | 22 + .../partialupdate/model/Customer.java | 23 + .../partialupdate/model/CustomerDto.java | 31 + .../model/CustomerStructured.java | 27 + .../repository/ContactPhoneRepository.java | 12 + .../repository/CustomerRepository.java | 18 + .../CustomerStructuredRepository.java | 11 + .../service/CustomerService.java | 87 +++ .../partialupdate/util/CustomerMapper.java | 15 + .../src/main/resources/application.properties | 16 + .../persistence-multiple-db-boot.properties | 11 + .../persistence-multiple-db.properties | 13 + .../java/com/baeldung/SpringContextTest.java | 17 + .../SpringJpaContextIntegrationTest.java | 25 + .../boot/daos/UserRepositoryCommon.java | 545 ++++++++++++++++++ .../daos/UserRepositoryIntegrationTest.java | 37 ++ .../daos/UserRepositoryTCAutoLiveTest.java | 43 ++ .../boot/daos/UserRepositoryTCLiveTest.java | 58 ++ ...ractServicePersistenceIntegrationTest.java | 252 ++++++++ .../FooServicePersistenceIntegrationTest.java | 75 +++ .../SpringDataJPABarAuditIntegrationTest.java | 75 +++ .../ElementCollectionIntegrationTest.java | 64 ++ .../JpaMultipleDBIntegrationTest.java | 96 +++ .../ProductRepositoryIntegrationTest.java | 144 +++++ ...erCaseNamingStrategyH2IntegrationTest.java | 81 +++ ...werCaseNamingStrategyPostgresLiveTest.java | 85 +++ ...erCaseNamingStrategyH2IntegrationTest.java | 85 +++ ...perCaseNamingStrategyPostgresLiveTest.java | 81 +++ ...ysicalNamingStrategyH2IntegrationTest.java | 85 +++ ...hysicalNamingStrategyPostgresLiveTest.java | 85 +++ ...erCaseNamingStrategyH2IntegrationTest.java | 86 +++ ...werCaseNamingStrategyPostgresLiveTest.java | 85 +++ ...erCaseNamingStrategyH2IntegrationTest.java | 85 +++ ...perCaseNamingStrategyPostgresLiveTest.java | 85 +++ .../osiv/UserControllerIntegrationTest.java | 56 ++ .../partialupdate/PartialUpdateUnitTest.java | 63 ++ .../util/BaeldungPostgresqlContainer.java | 35 ++ .../test/java/com/baeldung/util/IDUtil.java | 33 ++ .../resources/application-test.properties | 3 + ...ase-naming-strategy-on-postgres.properties | 9 + ...oted-lower-case-naming-strategy.properties | 9 + ...ase-naming-strategy-on-postgres.properties | 9 + ...oted-upper-case-naming-strategy.properties | 9 + ...cal-naming-strategy-on-postgres.properties | 9 + ...spring-physical-naming-strategy.properties | 9 + ...ase-naming-strategy-on-postgres.properties | 9 + ...oted-lower-case-naming-strategy.properties | 9 + ...ase-naming-strategy-on-postgres.properties | 9 + ...oted-upper-case-naming-strategy.properties | 9 + 100 files changed, 5026 insertions(+) create mode 100644 persistence-modules/spring-data-jpa-enterprise/README.md create mode 100644 persistence-modules/spring-data-jpa-enterprise/pom.xml create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/Application.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/Application.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/IFooDao.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepository.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Bar.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Foo.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Possession.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/User.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IBarService.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IFooService.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IOperations.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/AbstractService.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/FooService.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Employee.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Phone.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java create mode 100755 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java create mode 100755 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/product/Product.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/Person.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/PersonRepository.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/OsivApplication.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/model/BasicUser.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/service/SimpleUserService.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/service/UserService.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/web/UserController.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/Customer.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/service/CustomerService.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/resources/application.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db-boot.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/util/IDUtil.java create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/application-test.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties create mode 100644 persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties diff --git a/persistence-modules/spring-data-jpa-enterprise/README.md b/persistence-modules/spring-data-jpa-enterprise/README.md new file mode 100644 index 0000000000..81398b1f00 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/README.md @@ -0,0 +1,24 @@ +## Spring Data JPA - Enterprise + +This module contains articles about Spring Data JPA used in enterprise applications such as transactions, sessions, naming conventions and more + +### Relevant Articles: + +- [Spring JPA – Multiple Databases](https://www.baeldung.com/spring-data-jpa-multiple-databases) +- [Spring Data Java 8 Support](https://www.baeldung.com/spring-data-java-8) +- [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting) +- [DB Integration Tests with Spring Boot and Testcontainers](https://www.baeldung.com/spring-boot-testcontainers-integration-test) +- [A Guide to Spring’s Open Session In View](https://www.baeldung.com/spring-open-session-in-view) +- [Working with Lazy Element Collections in JPA](https://www.baeldung.com/java-jpa-lazy-collections) +- [Custom Naming Convention with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-custom-naming) +- [Partial Data Update with Spring Data](https://www.baeldung.com/spring-data-partial-update) + +### Eclipse Config +After importing the project into Eclipse, you may see the following error: +"No persistence xml file found in project" + +This can be ignored: +- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" +Or: +- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator + diff --git a/persistence-modules/spring-data-jpa-enterprise/pom.xml b/persistence-modules/spring-data-jpa-enterprise/pom.xml new file mode 100644 index 0000000000..093059ad78 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/pom.xml @@ -0,0 +1,107 @@ + + + + 4.0.0 + spring-data-jpa-enterprise + spring-data-jpa-enterprise + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + + org.springframework.boot + spring-boot-starter-cache + + + + com.h2database + h2 + + + + org.hibernate + hibernate-envers + + + + com.google.guava + guava + ${guava.version} + + + + org.mapstruct + mapstruct-jdk8 + ${mapstruct.version} + provided + + + + org.springframework.security + spring-security-test + test + + + + + org.testcontainers + postgresql + ${testcontainers.version} + test + + + + + + src/main/java + + + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + 1.3.1.Final + + + + + + + + + 2.1.9.RELEASE + com.baeldung.springdatageode.app.ClientCacheApp + 1.1.1.RELEASE + 2.1.9.RELEASE + 1.3.1.Final + 21.0 + 1.12.2 + + + diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..3ea3d113da --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/Application.java @@ -0,0 +1,13 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/Application.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/Application.java new file mode 100644 index 0000000000..aaca760499 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/Application.java @@ -0,0 +1,17 @@ +package com.baeldung.boot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +@SpringBootApplication +@EnableJpaRepositories("com.baeldung") +@EntityScan("com.baeldung") +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java new file mode 100644 index 0000000000..76d5887030 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java @@ -0,0 +1,23 @@ +package com.baeldung.boot.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import com.baeldung.boot.services.IBarService; +import com.baeldung.boot.services.impl.BarSpringDataJpaService; + +@Configuration +@Profile("!tc") +@EnableTransactionManagement +@EnableJpaAuditing +public class PersistenceConfiguration { + + @Bean + public IBarService barSpringDataJpaService() { + return new BarSpringDataJpaService(); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java new file mode 100644 index 0000000000..921fabe3fb --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.boot.daos; + +import org.springframework.data.repository.CrudRepository; + +import com.baeldung.boot.domain.Bar; + +import java.io.Serializable; + +public interface IBarCrudRepository extends CrudRepository { + // +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/IFooDao.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/IFooDao.java new file mode 100644 index 0000000000..d537772076 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/IFooDao.java @@ -0,0 +1,13 @@ +package com.baeldung.boot.daos; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import com.baeldung.boot.domain.Foo; + +public interface IFooDao extends JpaRepository { + + @Query("SELECT f FROM Foo f WHERE LOWER(f.name) = LOWER(:name)") + Foo retrieveByName(@Param("name") String name); +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepository.java new file mode 100644 index 0000000000..53f692ff28 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepository.java @@ -0,0 +1,99 @@ +package com.baeldung.boot.daos.user; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import com.baeldung.boot.domain.User; + +import java.time.LocalDate; +import java.util.Collection; +import java.util.List; +import java.util.stream.Stream; + +public interface UserRepository extends JpaRepository , UserRepositoryCustom{ + + Stream findAllByName(String name); + + @Query("SELECT u FROM User u WHERE u.status = 1") + Collection findAllActiveUsers(); + + @Query("select u from User u where u.email like '%@gmail.com'") + List findUsersWithGmailAddress(); + + @Query(value = "SELECT * FROM Users u WHERE u.status = 1", nativeQuery = true) + Collection findAllActiveUsersNative(); + + @Query("SELECT u FROM User u WHERE u.status = ?1") + User findUserByStatus(Integer status); + + @Query(value = "SELECT * FROM Users u WHERE u.status = ?1", nativeQuery = true) + User findUserByStatusNative(Integer status); + + @Query("SELECT u FROM User u WHERE u.status = ?1 and u.name = ?2") + User findUserByStatusAndName(Integer status, String name); + + @Query("SELECT u FROM User u WHERE u.status = :status and u.name = :name") + User findUserByStatusAndNameNamedParams(@Param("status") Integer status, @Param("name") String name); + + @Query(value = "SELECT * FROM Users u WHERE u.status = :status AND u.name = :name", nativeQuery = true) + User findUserByStatusAndNameNamedParamsNative(@Param("status") Integer status, @Param("name") String name); + + @Query("SELECT u FROM User u WHERE u.status = :status and u.name = :name") + User findUserByUserStatusAndUserName(@Param("status") Integer userStatus, @Param("name") String userName); + + @Query("SELECT u FROM User u WHERE u.name like ?1%") + User findUserByNameLike(String name); + + @Query("SELECT u FROM User u WHERE u.name like :name%") + User findUserByNameLikeNamedParam(@Param("name") String name); + + @Query(value = "SELECT * FROM users u WHERE u.name LIKE ?1%", nativeQuery = true) + User findUserByNameLikeNative(String name); + + @Query(value = "SELECT u FROM User u") + List findAllUsers(Sort sort); + + @Query(value = "SELECT u FROM User u ORDER BY id") + Page findAllUsersWithPagination(Pageable pageable); + + @Query(value = "SELECT * FROM Users ORDER BY id", countQuery = "SELECT count(*) FROM Users", nativeQuery = true) + Page findAllUsersWithPaginationNative(Pageable pageable); + + @Modifying + @Query("update User u set u.status = :status where u.name = :name") + int updateUserSetStatusForName(@Param("status") Integer status, @Param("name") String name); + + @Modifying + @Query(value = "UPDATE Users u SET u.status = ? WHERE u.name = ?", nativeQuery = true) + int updateUserSetStatusForNameNative(Integer status, String name); + + @Query(value = "INSERT INTO Users (name, age, email, status, active) VALUES (:name, :age, :email, :status, :active)", nativeQuery = true) + @Modifying + void insertUser(@Param("name") String name, @Param("age") Integer age, @Param("email") String email, @Param("status") Integer status, @Param("active") boolean active); + + @Modifying + @Query(value = "UPDATE Users u SET status = ? WHERE u.name = ?", nativeQuery = true) + int updateUserSetStatusForNameNativePostgres(Integer status, String name); + + @Query(value = "SELECT u FROM User u WHERE u.name IN :names") + List findUserByNameList(@Param("names") Collection names); + + void deleteAllByCreationDateAfter(LocalDate date); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("update User u set u.active = false where u.lastLoginDate < :date") + void deactivateUsersNotLoggedInSince(@Param("date") LocalDate date); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("delete User u where u.active = false") + int deleteDeactivatedUsers(); + + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query(value = "alter table USERS add column deleted int(1) not null default 0", nativeQuery = true) + void addDeletedColumn(); +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java new file mode 100644 index 0000000000..c586b54027 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java @@ -0,0 +1,14 @@ +package com.baeldung.boot.daos.user; + +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.function.Predicate; + +import com.baeldung.boot.domain.User; + +public interface UserRepositoryCustom { + List findUserByEmails(Set emails); + + List findAllUsersByPredicates(Collection> predicates); +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java new file mode 100644 index 0000000000..63a743b6b5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java @@ -0,0 +1,57 @@ +package com.baeldung.boot.daos.user; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Path; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import com.baeldung.boot.domain.User; + +public class UserRepositoryCustomImpl implements UserRepositoryCustom { + + @PersistenceContext + private EntityManager entityManager; + + @Override + public List findUserByEmails(Set emails) { + CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + CriteriaQuery query = cb.createQuery(User.class); + Root user = query.from(User.class); + + Path emailPath = user.get("email"); + + List predicates = new ArrayList<>(); + for (String email : emails) { + + predicates.add(cb.like(emailPath, email)); + + } + query.select(user) + .where(cb.or(predicates.toArray(new Predicate[predicates.size()]))); + + return entityManager.createQuery(query) + .getResultList(); + } + + @Override + public List findAllUsersByPredicates(Collection> predicates) { + List allUsers = entityManager.createQuery("select u from User u", User.class).getResultList(); + Stream allUsersStream = allUsers.stream(); + for (java.util.function.Predicate predicate : predicates) { + allUsersStream = allUsersStream.filter(predicate); + } + + return allUsersStream.collect(Collectors.toList()); + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Bar.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Bar.java new file mode 100644 index 0000000000..35d1903801 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Bar.java @@ -0,0 +1,220 @@ +package com.baeldung.boot.domain; + +import com.google.common.collect.Sets; +import org.hibernate.annotations.OrderBy; +import org.hibernate.envers.Audited; +import org.jboss.logging.Logger; +import org.springframework.data.annotation.CreatedBy; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedBy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; +import java.util.Set; + +@Entity +@NamedQuery(name = "Bar.findAll", query = "SELECT b FROM Bar b") +@Audited +@EntityListeners(AuditingEntityListener.class) +public class Bar implements Serializable { + + private static Logger logger = Logger.getLogger(Bar.class); + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private int id; + + @Column(name = "name") + private String name; + @OneToMany(mappedBy = "bar", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @OrderBy(clause = "NAME DESC") + // @NotAudited + private Set fooSet = Sets.newHashSet(); + @Column(name = "operation") + private String operation; + @Column(name = "timestamp") + private long timestamp; + @Column(name = "created_date", updatable = false, nullable = false) + @CreatedDate + private long createdDate; + @Column(name = "modified_date") + @LastModifiedDate + private long modifiedDate; + @Column(name = "created_by") + @CreatedBy + private String createdBy; + @Column(name = "modified_by") + @LastModifiedBy + private String modifiedBy; + + public Bar() { + super(); + } + + public Bar(final String name) { + super(); + + this.name = name; + } + + public Set getFooSet() { + return fooSet; + } + + // API + + public void setFooSet(final Set fooSet) { + this.fooSet = fooSet; + } + + public int getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public OPERATION getOperation() { + return OPERATION.parse(operation); + } + + public void setOperation(final String operation) { + this.operation = operation; + } + + public void setOperation(final OPERATION operation) { + this.operation = operation.getValue(); + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(final long timestamp) { + this.timestamp = timestamp; + } + + public long getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(final long createdDate) { + this.createdDate = createdDate; + } + + public long getModifiedDate() { + return modifiedDate; + } + + public void setModifiedDate(final long modifiedDate) { + this.modifiedDate = modifiedDate; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(final String createdBy) { + this.createdBy = createdBy; + } + + public String getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(final String modifiedBy) { + this.modifiedBy = modifiedBy; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final Bar other = (Bar) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Bar [name=").append(name).append("]"); + return builder.toString(); + } + + @PrePersist + public void onPrePersist() { + logger.info("@PrePersist"); + audit(OPERATION.INSERT); + } + + @PreUpdate + public void onPreUpdate() { + logger.info("@PreUpdate"); + audit(OPERATION.UPDATE); + } + + @PreRemove + public void onPreRemove() { + logger.info("@PreRemove"); + audit(OPERATION.DELETE); + } + + private void audit(final OPERATION operation) { + setOperation(operation); + setTimestamp((new Date()).getTime()); + } + + public enum OPERATION { + INSERT, UPDATE, DELETE; + private String value; + + OPERATION() { + value = toString(); + } + + public static OPERATION parse(final String value) { + OPERATION operation = null; + for (final OPERATION op : OPERATION.values()) { + if (op.getValue().equals(value)) { + operation = op; + break; + } + } + return operation; + } + + public String getValue() { + return value; + } + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Foo.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Foo.java new file mode 100644 index 0000000000..5030e5600b --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Foo.java @@ -0,0 +1,94 @@ +package com.baeldung.boot.domain; + +import org.hibernate.envers.Audited; + +import javax.persistence.*; +import java.io.Serializable; + +@NamedNativeQueries({@NamedNativeQuery(name = "callGetAllFoos", query = "CALL GetAllFoos()", resultClass = Foo.class), @NamedNativeQuery(name = "callGetFoosByName", query = "CALL GetFoosByName(:fooName)", resultClass = Foo.class)}) +@Entity +@Audited +// @Proxy(lazy = false) +public class Foo implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private long id; + + @Column(name = "name", nullable = false) + private String name; + + @ManyToOne(targetEntity = Bar.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "BAR_ID") + private Bar bar = new Bar(); + + public Foo() { + super(); + } + + public Foo(final String name) { + super(); + this.name = name; + } + + // + + public Bar getBar() { + return bar; + } + + public void setBar(final Bar bar) { + this.bar = bar; + } + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + // + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final Foo other = (Foo) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Foo [name=").append(name).append("]"); + return builder.toString(); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Possession.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Possession.java new file mode 100644 index 0000000000..f13491ad82 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/Possession.java @@ -0,0 +1,83 @@ +package com.baeldung.boot.domain; + +import javax.persistence.*; +import com.baeldung.boot.domain.Possession; + +@Entity +@Table +public class Possession { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private String name; + + public Possession() { + super(); + } + + public Possession(final String name) { + super(); + + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = (prime * result) + (int) (id ^ (id >>> 32)); + result = (prime * result) + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Possession other = (Possession) obj; + if (id != other.id) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Possesion [id=").append(id).append(", name=").append(name).append("]"); + return builder.toString(); + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/User.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/User.java new file mode 100644 index 0000000000..cca00e52a2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/domain/User.java @@ -0,0 +1,132 @@ +package com.baeldung.boot.domain; + +import javax.persistence.*; + +import java.time.LocalDate; +import java.util.List; +import java.util.Objects; + +@Entity +@Table(name = "users") +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + private String name; + private LocalDate creationDate; + private LocalDate lastLoginDate; + private boolean active; + private int age; + @Column(unique = true, nullable = false) + private String email; + private Integer status; + @OneToMany + List possessionList; + + public User() { + super(); + } + + public User(String name, LocalDate creationDate,String email, Integer status) { + this.name = name; + this.creationDate = creationDate; + this.email = email; + this.status = status; + this.active = true; + } + + public int getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(final String email) { + this.email = email; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public int getAge() { + return age; + } + + public void setAge(final int age) { + this.age = age; + } + + public LocalDate getCreationDate() { + return creationDate; + } + + public List getPossessionList() { + return possessionList; + } + + public void setPossessionList(List possessionList) { + this.possessionList = possessionList; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("User [name=").append(name).append(", id=").append(id).append("]"); + return builder.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + User user = (User) o; + return id == user.id && + age == user.age && + Objects.equals(name, user.name) && + Objects.equals(creationDate, user.creationDate) && + Objects.equals(email, user.email) && + Objects.equals(status, user.status); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, creationDate, age, email, status); + } + + public LocalDate getLastLoginDate() { + return lastLoginDate; + } + + public void setLastLoginDate(LocalDate lastLoginDate) { + this.lastLoginDate = lastLoginDate; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IBarService.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IBarService.java new file mode 100644 index 0000000000..8054cbba59 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IBarService.java @@ -0,0 +1,7 @@ +package com.baeldung.boot.services; + +import com.baeldung.boot.domain.Bar; + +public interface IBarService extends IOperations { + // +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IFooService.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IFooService.java new file mode 100644 index 0000000000..871cccdd45 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IFooService.java @@ -0,0 +1,14 @@ +package com.baeldung.boot.services; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import com.baeldung.boot.domain.Foo; + +public interface IFooService extends IOperations { + + Foo retrieveByName(String name); + + Page findPaginated(Pageable pageable); + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IOperations.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IOperations.java new file mode 100644 index 0000000000..ec2b866b6f --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/IOperations.java @@ -0,0 +1,26 @@ +package com.baeldung.boot.services; + +import org.springframework.data.domain.Page; + +import java.io.Serializable; +import java.util.List; + +public interface IOperations { + + T findOne(final long id); + + List findAll(); + + Page findPaginated(int page, int size); + + // write + + T create(final T entity); + + T update(final T entity); + + void delete(final T entity); + + void deleteById(final long entityId); + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/AbstractService.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/AbstractService.java new file mode 100644 index 0000000000..f88d018bbb --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/AbstractService.java @@ -0,0 +1,61 @@ +package com.baeldung.boot.services.impl; + +import com.baeldung.boot.services.IOperations; +import com.google.common.collect.Lists; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.transaction.annotation.Transactional; + +import java.io.Serializable; +import java.util.List; + +@Transactional +public abstract class AbstractService implements IOperations { + + // read - one + + @Override + @Transactional(readOnly = true) + public T findOne(final long id) { + return getDao().findById(id).orElse(null); + } + + // read - all + + @Override + @Transactional(readOnly = true) + public List findAll() { + return Lists.newArrayList(getDao().findAll()); + } + + @Override + public Page findPaginated(final int page, final int size) { + return getDao().findAll(PageRequest.of(page, size)); + } + + // write + + @Override + public T create(final T entity) { + return getDao().save(entity); + } + + @Override + public T update(final T entity) { + return getDao().save(entity); + } + + @Override + public void delete(final T entity) { + getDao().delete(entity); + } + + @Override + public void deleteById(final long entityId) { + getDao().deleteById(entityId); + } + + protected abstract PagingAndSortingRepository getDao(); + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java new file mode 100644 index 0000000000..a73a6bd7fc --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java @@ -0,0 +1,45 @@ +package com.baeldung.boot.services.impl; + +import com.baeldung.boot.services.IOperations; +import com.google.common.collect.Lists; +import org.springframework.data.repository.CrudRepository; +import org.springframework.transaction.annotation.Transactional; + +import java.io.Serializable; +import java.util.List; + +@Transactional(value = "transactionManager") +public abstract class AbstractSpringDataJpaService implements IOperations { + + @Override + public T findOne(final long id) { + return getDao().findById(id).orElse(null); + } + + @Override + public List findAll() { + return Lists.newArrayList(getDao().findAll()); + } + + @Override + public T create(final T entity) { + return getDao().save(entity); + } + + @Override + public T update(final T entity) { + return getDao().save(entity); + } + + @Override + public void delete(final T entity) { + getDao().delete(entity); + } + + @Override + public void deleteById(final long entityId) { + getDao().deleteById(entityId); + } + + protected abstract CrudRepository getDao(); +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java new file mode 100644 index 0000000000..80568f2fd4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java @@ -0,0 +1,31 @@ +package com.baeldung.boot.services.impl; + +import com.baeldung.boot.daos.IBarCrudRepository; +import com.baeldung.boot.domain.Bar; +import com.baeldung.boot.services.IBarService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.repository.CrudRepository; + +import java.io.Serializable; + +public class BarSpringDataJpaService extends AbstractSpringDataJpaService implements IBarService { + + @Autowired + private IBarCrudRepository dao; + + public BarSpringDataJpaService() { + super(); + } + + @Override + protected CrudRepository getDao() { + return dao; + } + + @Override + public Page findPaginated(int page, int size) { + throw new UnsupportedOperationException("Not implemented yet"); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/FooService.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/FooService.java new file mode 100644 index 0000000000..04eec63854 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/services/impl/FooService.java @@ -0,0 +1,55 @@ +package com.baeldung.boot.services.impl; + +import com.google.common.collect.Lists; +import com.baeldung.boot.daos.IFooDao; +import com.baeldung.boot.domain.Foo; +import com.baeldung.boot.services.IFooService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.PagingAndSortingRepository; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@Service +@Transactional +public class FooService extends AbstractService implements IFooService { + + @Autowired + private IFooDao dao; + + public FooService() { + super(); + } + + // API + + @Override + protected PagingAndSortingRepository getDao() { + return dao; + } + + // custom methods + + @Override + public Foo retrieveByName(final String name) { + return dao.retrieveByName(name); + } + + // overridden to be secured + + @Override + @Transactional(readOnly = true) + public List findAll() { + return Lists.newArrayList(getDao().findAll()); + } + + @Override + public Page findPaginated(Pageable pageable) { + return dao.findAll(pageable); + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java new file mode 100644 index 0000000000..3f152a6ffc --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java @@ -0,0 +1,11 @@ +package com.baeldung.elementcollection; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ElementCollectionApplication { + public static void main(String[] args) { + SpringApplication.run(ElementCollectionApplication.class, args); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Employee.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Employee.java new file mode 100644 index 0000000000..8b98164d63 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Employee.java @@ -0,0 +1,68 @@ +package com.baeldung.elementcollection.model; + +import javax.persistence.*; +import java.util.List; +import java.util.Objects; + +@Entity +public class Employee { + @Id + private int id; + private String name; + @ElementCollection + @CollectionTable(name = "employee_phone", joinColumns = @JoinColumn(name = "employee_id")) + private List phones; + + public Employee() { + } + + public Employee(int id) { + this.id = id; + } + + public Employee(int id, String name) { + this.id = id; + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getPhones() { + return phones; + } + + public void setPhones(List phones) { + this.phones = phones; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Employee)) { + return false; + } + Employee user = (Employee) o; + return getId() == user.getId(); + } + + @Override + public int hashCode() { + return Objects.hash(getId()); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Phone.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Phone.java new file mode 100644 index 0000000000..d73d30c47a --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/model/Phone.java @@ -0,0 +1,62 @@ +package com.baeldung.elementcollection.model; + +import javax.persistence.Embeddable; +import java.util.Objects; + +@Embeddable +public class Phone { + private String type; + private String areaCode; + private String number; + + public Phone() { + } + + public Phone(String type, String areaCode, String number) { + this.type = type; + this.areaCode = areaCode; + this.number = number; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getAreaCode() { + return areaCode; + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Phone)) { + return false; + } + Phone phone = (Phone) o; + return getType().equals(phone.getType()) && getAreaCode().equals(phone.getAreaCode()) + && getNumber().equals(phone.getNumber()); + } + + @Override + public int hashCode() { + return Objects.hash(getType(), getAreaCode(), getNumber()); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java new file mode 100644 index 0000000000..49180c35eb --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java @@ -0,0 +1,46 @@ +package com.baeldung.elementcollection.repository; + +import com.baeldung.elementcollection.model.Employee; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import javax.persistence.EntityGraph; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import java.util.HashMap; +import java.util.Map; + +@Repository +public class EmployeeRepository { + + @PersistenceContext + private EntityManager em; + + @Transactional + public void save(Employee employee) { + em.persist(employee); + } + + @Transactional + public void remove(int id) { + Employee employee = findById(id); + em.remove(employee); + } + + public Employee findById(int id) { + return em.find(Employee.class, id); + } + + public Employee findByJPQL(int id) { + return em.createQuery("SELECT u FROM Employee AS u JOIN FETCH u.phones WHERE u.id=:id", Employee.class) + .setParameter("id", id).getSingleResult(); + } + + public Employee findByEntityGraph(int id) { + EntityGraph entityGraph = em.createEntityGraph(Employee.class); + entityGraph.addAttributeNodes("name", "phones"); + Map properties = new HashMap<>(); + properties.put("javax.persistence.fetchgraph", entityGraph); + return em.find(Employee.class, id, properties); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java new file mode 100644 index 0000000000..3b9aa2cc18 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java @@ -0,0 +1,14 @@ +package com.baeldung.multipledb; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MultipleDbApplication { + + public static void main(String[] args) { + SpringApplication.run(MultipleDbApplication.class, args); + } + +} + diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java new file mode 100644 index 0000000000..a6f8f0829f --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java @@ -0,0 +1,71 @@ +package com.baeldung.multipledb; + +import java.util.HashMap; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.PlatformTransactionManager; + +/** + * By default, the persistence-multiple-db.properties file is read for + * non auto configuration in PersistenceProductConfiguration. + *

+ * If we need to use persistence-multiple-db-boot.properties and auto configuration + * then uncomment the below @Configuration class and comment out PersistenceProductConfiguration. + */ +//@Configuration +@PropertySource({"classpath:persistence-multiple-db-boot.properties"}) +@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.product", entityManagerFactoryRef = "productEntityManager", transactionManagerRef = "productTransactionManager") +@Profile("!tc") +public class PersistenceProductAutoConfiguration { + @Autowired + private Environment env; + + public PersistenceProductAutoConfiguration() { + super(); + } + + // + + @Bean + public LocalContainerEntityManagerFactoryBean productEntityManager() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(productDataSource()); + em.setPackagesToScan("com.baeldung.multipledb.model.product"); + + final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + em.setJpaVendorAdapter(vendorAdapter); + final HashMap properties = new HashMap(); + properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); + em.setJpaPropertyMap(properties); + + return em; + } + + @Bean + @ConfigurationProperties(prefix="spring.second-datasource") + public DataSource productDataSource() { + return DataSourceBuilder.create().build(); + } + + @Bean + public PlatformTransactionManager productTransactionManager() { + final JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(productEntityManager().getObject()); + return transactionManager; + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java new file mode 100644 index 0000000000..bcf2cd84eb --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java @@ -0,0 +1,68 @@ +package com.baeldung.multipledb; + +import com.google.common.base.Preconditions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.PlatformTransactionManager; + +import javax.sql.DataSource; +import java.util.HashMap; + +@Configuration +@PropertySource({"classpath:persistence-multiple-db.properties"}) +@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.product", entityManagerFactoryRef = "productEntityManager", transactionManagerRef = "productTransactionManager") +@Profile("!tc") +public class PersistenceProductConfiguration { + @Autowired + private Environment env; + + public PersistenceProductConfiguration() { + super(); + } + + // + + @Bean + public LocalContainerEntityManagerFactoryBean productEntityManager() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(productDataSource()); + em.setPackagesToScan("com.baeldung.multipledb.model.product"); + + final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + em.setJpaVendorAdapter(vendorAdapter); + final HashMap properties = new HashMap(); + properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); + em.setJpaPropertyMap(properties); + + return em; + } + + @Bean + public DataSource productDataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("product.jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + public PlatformTransactionManager productTransactionManager() { + final JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(productEntityManager().getObject()); + return transactionManager; + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java new file mode 100644 index 0000000000..e04a1621b2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java @@ -0,0 +1,75 @@ +package com.baeldung.multipledb; + +import java.util.HashMap; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.PlatformTransactionManager; + +/** + * By default, the persistence-multiple-db.properties file is read for + * non auto configuration in PersistenceUserConfiguration. + *

+ * If we need to use persistence-multiple-db-boot.properties and auto configuration + * then uncomment the below @Configuration class and comment out PersistenceUserConfiguration. + */ +//@Configuration +@PropertySource({"classpath:persistence-multiple-db-boot.properties"}) +@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.user", entityManagerFactoryRef = "userEntityManager", transactionManagerRef = "userTransactionManager") +@Profile("!tc") +public class PersistenceUserAutoConfiguration { + @Autowired + private Environment env; + + public PersistenceUserAutoConfiguration() { + super(); + } + + // + + @Primary + @Bean + public LocalContainerEntityManagerFactoryBean userEntityManager() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(userDataSource()); + em.setPackagesToScan("com.baeldung.multipledb.model.user"); + + final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + em.setJpaVendorAdapter(vendorAdapter); + final HashMap properties = new HashMap(); + properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); + em.setJpaPropertyMap(properties); + + return em; + } + + @Bean + @Primary + @ConfigurationProperties(prefix="spring.datasource") + public DataSource userDataSource() { + return DataSourceBuilder.create().build(); + } + + @Primary + @Bean + public PlatformTransactionManager userTransactionManager() { + final JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(userEntityManager().getObject()); + return transactionManager; + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java new file mode 100644 index 0000000000..6b48455c0c --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java @@ -0,0 +1,69 @@ +package com.baeldung.multipledb; + +import com.google.common.base.Preconditions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.*; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.PlatformTransactionManager; + +import javax.sql.DataSource; +import java.util.HashMap; + +@Configuration +@PropertySource({"classpath:persistence-multiple-db.properties"}) +@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.user", entityManagerFactoryRef = "userEntityManager", transactionManagerRef = "userTransactionManager") +@Profile("!tc") +public class PersistenceUserConfiguration { + @Autowired + private Environment env; + + public PersistenceUserConfiguration() { + super(); + } + + // + + @Primary + @Bean + public LocalContainerEntityManagerFactoryBean userEntityManager() { + System.out.println("loading config"); + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(userDataSource()); + em.setPackagesToScan("com.baeldung.multipledb.model.user"); + + final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + em.setJpaVendorAdapter(vendorAdapter); + final HashMap properties = new HashMap(); + properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); + em.setJpaPropertyMap(properties); + + return em; + } + + @Primary + @Bean + public DataSource userDataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("user.jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Primary + @Bean + public PlatformTransactionManager userTransactionManager() { + final JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(userEntityManager().getObject()); + return transactionManager; + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java new file mode 100755 index 0000000000..f1256e2c72 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java @@ -0,0 +1,14 @@ +package com.baeldung.multipledb.dao.product; + +import java.util.List; + +import org.springframework.data.domain.Pageable; +import org.springframework.data.repository.PagingAndSortingRepository; + +import com.baeldung.multipledb.model.product.Product; + +public interface ProductRepository extends PagingAndSortingRepository { + + + List findAllByPrice(double price, Pageable pageable); +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java new file mode 100644 index 0000000000..ae37fde20d --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.multipledb.dao.user; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.multipledb.model.user.PossessionMultipleDB; + +public interface PossessionRepository extends JpaRepository { + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java new file mode 100644 index 0000000000..267a61a93f --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.multipledb.dao.user; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.multipledb.model.user.UserMultipleDB; + +public interface UserRepository extends JpaRepository { +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/product/Product.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/product/Product.java new file mode 100755 index 0000000000..eaf471043c --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/product/Product.java @@ -0,0 +1,67 @@ +package com.baeldung.multipledb.model.product; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(schema = "products") +public class Product { + + @Id + private int id; + + private String name; + + private double price; + + public Product() { + super(); + } + + private Product(int id, String name, double price) { + super(); + this.id = id; + this.name = name; + this.price = price; + } + + public static Product from(int id, String name, double price) { + return new Product(id, name, price); + } + + public int getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(final double price) { + this.price = price; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Product [name=") + .append(name) + .append(", id=") + .append(id) + .append("]"); + return builder.toString(); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java new file mode 100644 index 0000000000..a6a3c88bd0 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java @@ -0,0 +1,82 @@ +package com.baeldung.multipledb.model.user; + +import javax.persistence.*; + +@Entity +@Table +public class PossessionMultipleDB { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private String name; + + public PossessionMultipleDB() { + super(); + } + + public PossessionMultipleDB(final String name) { + super(); + + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = (prime * result) + (int) (id ^ (id >>> 32)); + result = (prime * result) + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final PossessionMultipleDB other = (PossessionMultipleDB) obj; + if (id != other.id) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Possesion [id=").append(id).append(", name=").append(name).append("]"); + return builder.toString(); + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java new file mode 100644 index 0000000000..c7cd07f7a1 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java @@ -0,0 +1,88 @@ +package com.baeldung.multipledb.model.user; + +import javax.persistence.*; + +import java.util.List; + +@Entity +@Table(name = "users") +public class UserMultipleDB { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int id; + private String name; + private int age; + @Column(unique = true, nullable = false) + private String email; + private Integer status; + + @OneToMany + List possessionList; + + public UserMultipleDB() { + super(); + } + + public UserMultipleDB(String name, String email, Integer status) { + this.name = name; + this.email = email; + this.status = status; + } + + public int getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(final String email) { + this.email = email; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public int getAge() { + return age; + } + + public void setAge(final int age) { + this.age = age; + } + + public List getPossessionList() { + return possessionList; + } + + public void setPossessionList(List possessionList) { + this.possessionList = possessionList; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("User [name=").append(name).append(", id=").append(id).append("]"); + return builder.toString(); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/Person.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/Person.java new file mode 100644 index 0000000000..cfb6e67c2c --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/Person.java @@ -0,0 +1,35 @@ +package com.baeldung.namingstrategy; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Person { + @Id + private Long id; + + private String firstName; + + private String lastName; + + public Person() {} + + public Person(Long id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Long id() { + return id; + } + + public String firstName() { + return firstName; + } + + public String lastName() { + return lastName; + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/PersonRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/PersonRepository.java new file mode 100644 index 0000000000..3c7c25bbcb --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/PersonRepository.java @@ -0,0 +1,6 @@ +package com.baeldung.namingstrategy; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface PersonRepository extends JpaRepository { +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java new file mode 100644 index 0000000000..16b01e50e3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java @@ -0,0 +1,12 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; + +public class QuotedLowerCaseNamingStrategy extends SpringPhysicalNamingStrategy { + @Override + protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) { + return new Identifier(name.toLowerCase(), true); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java new file mode 100644 index 0000000000..3cb62aa5a2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java @@ -0,0 +1,12 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; + +public class QuotedUpperCaseNamingStrategy extends SpringPhysicalNamingStrategy { + @Override + protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) { + return new Identifier(name.toUpperCase(), true); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java new file mode 100644 index 0000000000..f223015db8 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java @@ -0,0 +1,7 @@ +package com.baeldung.namingstrategy; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringDataJpaNamingConventionApplication { +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java new file mode 100644 index 0000000000..69e96aee27 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java @@ -0,0 +1,12 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; + +public class UnquotedLowerCaseNamingStrategy extends SpringPhysicalNamingStrategy { + @Override + protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) { + return new Identifier(name.toLowerCase(), false); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java new file mode 100644 index 0000000000..cb87af10f4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java @@ -0,0 +1,12 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; + +public class UnquotedUpperCaseNamingStrategy extends SpringPhysicalNamingStrategy { + @Override + protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) { + return new Identifier(name.toUpperCase(), false); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/OsivApplication.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/OsivApplication.java new file mode 100644 index 0000000000..4cfcf83e56 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/OsivApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.osiv; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class OsivApplication { + + public static void main(String[] args) { + SpringApplication.run(OsivApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/model/BasicUser.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/model/BasicUser.java new file mode 100644 index 0000000000..98f4e379d4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/model/BasicUser.java @@ -0,0 +1,42 @@ +package com.baeldung.osiv.model; + +import javax.persistence.*; +import java.util.Set; + +@Entity +@Table(name = "users") +public class BasicUser { + + @Id + @GeneratedValue + private Long id; + + private String username; + + @ElementCollection + private Set permissions; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Set getPermissions() { + return permissions; + } + + public void setPermissions(Set permissions) { + this.permissions = permissions; + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java new file mode 100644 index 0000000000..e8d5955d91 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java @@ -0,0 +1,19 @@ +package com.baeldung.osiv.repository; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.EntityGraph; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.osiv.model.BasicUser; + +@Repository +@Transactional +public interface BasicUserRepository extends JpaRepository { + + @EntityGraph(attributePaths = "permissions") + Optional findDetailedByUsername(String username); + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/service/SimpleUserService.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/service/SimpleUserService.java new file mode 100644 index 0000000000..1de51678d5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/service/SimpleUserService.java @@ -0,0 +1,25 @@ +package com.baeldung.osiv.service; + +import java.util.Optional; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.osiv.model.BasicUser; +import com.baeldung.osiv.repository.BasicUserRepository; + +@Service +public class SimpleUserService implements UserService { + + private final BasicUserRepository userRepository; + + public SimpleUserService(BasicUserRepository userRepository) { + this.userRepository = userRepository; + } + + @Override + @Transactional(readOnly = true) + public Optional findOne(String username) { + return userRepository.findDetailedByUsername(username); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/service/UserService.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/service/UserService.java new file mode 100644 index 0000000000..3d089fa41b --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/service/UserService.java @@ -0,0 +1,9 @@ +package com.baeldung.osiv.service; + +import com.baeldung.osiv.model.BasicUser; + +import java.util.Optional; + +public interface UserService { + Optional findOne(String username); +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java new file mode 100644 index 0000000000..fd2882c2d5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java @@ -0,0 +1,45 @@ +package com.baeldung.osiv.web; + +import com.baeldung.osiv.model.BasicUser; + +import java.util.Set; + +public class DetailedUserDto { + + private Long id; + private String username; + private Set permissions; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Set getPermissions() { + return permissions; + } + + public void setPermissions(Set permissions) { + this.permissions = permissions; + } + + public static DetailedUserDto fromEntity(BasicUser user) { + DetailedUserDto detailed = new DetailedUserDto(); + detailed.setId(user.getId()); + detailed.setUsername(user.getUsername()); + detailed.setPermissions(user.getPermissions()); + + return detailed; + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/web/UserController.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/web/UserController.java new file mode 100644 index 0000000000..5466b95166 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/web/UserController.java @@ -0,0 +1,27 @@ +package com.baeldung.osiv.web; + +import com.baeldung.osiv.service.UserService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/users") +public class UserController { + + private final UserService userService; + + public UserController(UserService userService) { + this.userService = userService; + } + + @GetMapping("/{username}") + public ResponseEntity findOne(@PathVariable String username) { + return userService.findOne(username) + .map(DetailedUserDto::fromEntity) + .map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java new file mode 100644 index 0000000000..a750fcadf7 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.partialupdate; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PartialUpdateApplication { + + public static void main(String[] args) { + SpringApplication.run(PartialUpdateApplication.class, args); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java new file mode 100644 index 0000000000..352e361bd9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java @@ -0,0 +1,22 @@ +package com.baeldung.partialupdate.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class ContactPhone { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + public long id; + @Column(nullable=false) + public long customerId; + public String phone; + + @Override + public String toString() { + return phone; + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/Customer.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/Customer.java new file mode 100644 index 0000000000..b19d0b7952 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/Customer.java @@ -0,0 +1,23 @@ +package com.baeldung.partialupdate.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Customer { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + public long id; + public String name; + public String phone; + //... + public String phone99; + + @Override public String toString() { + return String.format("Customer %s, Phone: %s", + this.name, this.phone); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java new file mode 100644 index 0000000000..0ecf206d9a --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java @@ -0,0 +1,31 @@ +package com.baeldung.partialupdate.model; + +public class CustomerDto { + private long id; + public String name; + public String phone; + //... + private String phone99; + + public CustomerDto(long id) { + this.id = id; + } + + public CustomerDto(Customer c) { + this.id = c.id; + this.name = c.name; + this.phone = c.phone; + } + + public long getId() { + return this.id; + } + + public Customer convertToEntity() { + Customer c = new Customer(); + c.id = id; + c.name = name; + c.phone = phone; + return c; + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java new file mode 100644 index 0000000000..dd053a963d --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java @@ -0,0 +1,27 @@ +package com.baeldung.partialupdate.model; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +@Entity +public class CustomerStructured { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + public long id; + public String name; + @OneToMany(fetch = FetchType.EAGER, targetEntity = ContactPhone.class, mappedBy = "customerId") + public List contactPhones; + + @Override public String toString() { + return String.format("Customer %s, Phone: %s", + this.name, this.contactPhones.stream() + .map(e -> e.toString()).reduce("", String::concat)); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java new file mode 100644 index 0000000000..4668181e05 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java @@ -0,0 +1,12 @@ +package com.baeldung.partialupdate.repository; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.partialupdate.model.ContactPhone; + +@Repository +public interface ContactPhoneRepository extends CrudRepository { + ContactPhone findById(long id); + ContactPhone findByCustomerId(long id); +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java new file mode 100644 index 0000000000..43e61df8ab --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java @@ -0,0 +1,18 @@ +package com.baeldung.partialupdate.repository; + +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import com.baeldung.partialupdate.model.Customer; + +@Repository +public interface CustomerRepository extends CrudRepository { + Customer findById(long id); + + @Modifying + @Query("update Customer u set u.phone = :phone where u.id = :id") + void updatePhone(@Param(value = "id") long id, @Param(value = "phone") String phone); +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java new file mode 100644 index 0000000000..0f9fd1e92e --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.partialupdate.repository; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.partialupdate.model.CustomerStructured; + +@Repository +public interface CustomerStructuredRepository extends CrudRepository { + CustomerStructured findById(long id); +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/service/CustomerService.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/service/CustomerService.java new file mode 100644 index 0000000000..9da97a7775 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/service/CustomerService.java @@ -0,0 +1,87 @@ +package com.baeldung.partialupdate.service; + +import javax.transaction.Transactional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baeldung.partialupdate.model.ContactPhone; +import com.baeldung.partialupdate.model.Customer; +import com.baeldung.partialupdate.model.CustomerDto; +import com.baeldung.partialupdate.model.CustomerStructured; +import com.baeldung.partialupdate.repository.ContactPhoneRepository; +import com.baeldung.partialupdate.repository.CustomerRepository; +import com.baeldung.partialupdate.repository.CustomerStructuredRepository; +import com.baeldung.partialupdate.util.CustomerMapper; + +@Service +@Transactional +public class CustomerService { + + @Autowired + CustomerRepository repo; + @Autowired + CustomerStructuredRepository repo2; + @Autowired + ContactPhoneRepository repo3; + @Autowired + CustomerMapper mapper; + + public Customer getCustomer(long id) { + return repo.findById(id); + } + + public void updateCustomerWithCustomQuery(long id, String phone) { + repo.updatePhone(id, phone); + } + + public Customer addCustomer(String name) { + Customer myCustomer = new Customer(); + myCustomer.name = name; + repo.save(myCustomer); + return myCustomer; + } + + public Customer updateCustomer(long id, String phone) { + Customer myCustomer = repo.findById(id); + myCustomer.phone = phone; + repo.save(myCustomer); + return myCustomer; + } + + public Customer addCustomer(CustomerDto dto) { + Customer myCustomer = new Customer(); + mapper.updateCustomerFromDto(dto, myCustomer); + repo.save(myCustomer); + return myCustomer; + } + + public Customer updateCustomer(CustomerDto dto) { + Customer myCustomer = repo.findById(dto.getId()); + mapper.updateCustomerFromDto(dto, myCustomer); + repo.save(myCustomer); + return myCustomer; + } + + public CustomerStructured addCustomerStructured(String name) { + CustomerStructured myCustomer = new CustomerStructured(); + myCustomer.name = name; + repo2.save(myCustomer); + return myCustomer; + } + + public void addCustomerPhone(long customerId, String phone) { + ContactPhone myPhone = new ContactPhone(); + myPhone.phone = phone; + myPhone.customerId = customerId; + repo3.save(myPhone); + } + + public CustomerStructured updateCustomerStructured(long id, String name) { + CustomerStructured myCustomer = repo2.findById(id); + myCustomer.name = name; + repo2.save(myCustomer); + return myCustomer; + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java new file mode 100644 index 0000000000..8a666e3e6c --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java @@ -0,0 +1,15 @@ +package com.baeldung.partialupdate.util; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; + +import com.baeldung.partialupdate.model.Customer; +import com.baeldung.partialupdate.model.CustomerDto; + +@Mapper(componentModel = "spring") +public interface CustomerMapper { + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + void updateCustomerFromDto(CustomerDto dto, @MappingTarget Customer entity); +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-enterprise/src/main/resources/application.properties new file mode 100644 index 0000000000..29326c6061 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/resources/application.properties @@ -0,0 +1,16 @@ + +spring.datasource.url=jdbc:h2:mem:baeldung + +# JPA-Schema-Generation +# Use below configuration to generate database schema create commands based on the entity models +# and export them into the create.sql file +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-source=metadata +#spring.jpa.properties.hibernate.format_sql=true + +spring.jpa.show-sql=true +spring.main.allow-bean-definition-overriding=true + +#hibernate.dialect=org.hibernate.dialect.H2Dialect +spring.jpa.properties.hibernate.id.new_generator_mappings=false \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db-boot.properties b/persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db-boot.properties new file mode 100644 index 0000000000..ffca79b3f5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db-boot.properties @@ -0,0 +1,11 @@ +hibernate.hbm2ddl.auto=create-drop +hibernate.cache.use_second_level_cache=false +hibernate.cache.use_query_cache=false + +spring.datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS +spring.datasource.username=sa +spring.datasource.password=sa + +spring.second-datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS +spring.second-datasource.username=sa +spring.second-datasource.password=sa diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db.properties b/persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db.properties new file mode 100644 index 0000000000..75534e8a54 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/resources/persistence-multiple-db.properties @@ -0,0 +1,13 @@ +# jdbc.X +jdbc.driverClassName=org.h2.Driver +user.jdbc.url=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS +product.jdbc.url=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS +jdbc.user=sa +jdbc.pass=sa + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop +hibernate.cache.use_second_level_cache=false +hibernate.cache.use_query_cache=false \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..eaccf4acba --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringContextTest.java @@ -0,0 +1,17 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.Application; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java new file mode 100644 index 0000000000..f3697bf39f --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.Application; +import com.baeldung.boot.config.PersistenceConfiguration; +import com.baeldung.multipledb.PersistenceProductConfiguration; +import com.baeldung.multipledb.PersistenceUserConfiguration; + +@RunWith(SpringRunner.class) +@DataJpaTest(excludeAutoConfiguration = { + PersistenceConfiguration.class, + PersistenceUserConfiguration.class, + PersistenceProductConfiguration.class }) +@ContextConfiguration(classes = Application.class) +public class SpringJpaContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java new file mode 100644 index 0000000000..b2581b8034 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java @@ -0,0 +1,545 @@ +package com.baeldung.boot.daos; + +import org.junit.After; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.domain.JpaSort; +import org.springframework.data.mapping.PropertyReferenceException; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.boot.daos.user.UserRepository; +import com.baeldung.boot.domain.User; + +import javax.persistence.EntityManager; +import javax.persistence.Query; +import java.time.LocalDate; +import java.util.*; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.*; + +public class UserRepositoryCommon { + + final String USER_EMAIL = "email@example.com"; + final String USER_EMAIL2 = "email2@example.com"; + final String USER_EMAIL3 = "email3@example.com"; + final String USER_EMAIL4 = "email4@example.com"; + final Integer INACTIVE_STATUS = 0; + final Integer ACTIVE_STATUS = 1; + final String USER_EMAIL5 = "email5@example.com"; + final String USER_EMAIL6 = "email6@example.com"; + final String USER_NAME_ADAM = "Adam"; + final String USER_NAME_PETER = "Peter"; + + @Autowired + protected UserRepository userRepository; + @Autowired + private EntityManager entityManager; + + @Test + @Transactional + public void givenUsersWithSameNameInDB_WhenFindAllByName_ThenReturnStreamOfUsers() { + User user1 = new User(); + user1.setName(USER_NAME_ADAM); + user1.setEmail(USER_EMAIL); + userRepository.save(user1); + + User user2 = new User(); + user2.setName(USER_NAME_ADAM); + user2.setEmail(USER_EMAIL2); + userRepository.save(user2); + + User user3 = new User(); + user3.setName(USER_NAME_ADAM); + user3.setEmail(USER_EMAIL3); + userRepository.save(user3); + + User user4 = new User(); + user4.setName("SAMPLE"); + user4.setEmail(USER_EMAIL4); + userRepository.save(user4); + + try (Stream foundUsersStream = userRepository.findAllByName(USER_NAME_ADAM)) { + assertThat(foundUsersStream.count()).isEqualTo(3l); + } + } + + @Test + public void givenUsersInDB_WhenFindAllWithQueryAnnotation_ThenReturnCollectionWithActiveUsers() { + User user1 = new User(); + user1.setName(USER_NAME_ADAM); + user1.setEmail(USER_EMAIL); + user1.setStatus(ACTIVE_STATUS); + userRepository.save(user1); + + User user2 = new User(); + user2.setName(USER_NAME_ADAM); + user2.setEmail(USER_EMAIL2); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User user3 = new User(); + user3.setName(USER_NAME_ADAM); + user3.setEmail(USER_EMAIL3); + user3.setStatus(INACTIVE_STATUS); + userRepository.save(user3); + + Collection allActiveUsers = userRepository.findAllActiveUsers(); + + assertThat(allActiveUsers.size()).isEqualTo(2); + } + + @Test + public void givenUsersInDB_WhenFindAllWithQueryAnnotationNative_ThenReturnCollectionWithActiveUsers() { + User user1 = new User(); + user1.setName(USER_NAME_ADAM); + user1.setEmail(USER_EMAIL); + user1.setStatus(ACTIVE_STATUS); + userRepository.save(user1); + + User user2 = new User(); + user2.setName(USER_NAME_ADAM); + user2.setEmail(USER_EMAIL2); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User user3 = new User(); + user3.setName(USER_NAME_ADAM); + user3.setEmail(USER_EMAIL3); + user3.setStatus(INACTIVE_STATUS); + userRepository.save(user3); + + Collection allActiveUsers = userRepository.findAllActiveUsersNative(); + + assertThat(allActiveUsers.size()).isEqualTo(2); + } + + @Test + public void givenUserInDB_WhenFindUserByStatusWithQueryAnnotation_ThenReturnActiveUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setEmail(USER_EMAIL); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User userByStatus = userRepository.findUserByStatus(ACTIVE_STATUS); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUserInDB_WhenFindUserByStatusWithQueryAnnotationNative_ThenReturnActiveUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setEmail(USER_EMAIL); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User userByStatus = userRepository.findUserByStatusNative(ACTIVE_STATUS); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationIndexedParams_ThenReturnOneUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setEmail(USER_EMAIL); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User user2 = new User(); + user2.setName(USER_NAME_PETER); + user2.setEmail(USER_EMAIL2); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User userByStatus = userRepository.findUserByStatusAndName(ACTIVE_STATUS, USER_NAME_ADAM); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationNamedParams_ThenReturnOneUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setEmail(USER_EMAIL); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User user2 = new User(); + user2.setName(USER_NAME_PETER); + user2.setEmail(USER_EMAIL2); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User userByStatus = userRepository.findUserByStatusAndNameNamedParams(ACTIVE_STATUS, USER_NAME_ADAM); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationNativeNamedParams_ThenReturnOneUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setEmail(USER_EMAIL); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User user2 = new User(); + user2.setName(USER_NAME_PETER); + user2.setEmail(USER_EMAIL2); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User userByStatus = userRepository.findUserByStatusAndNameNamedParamsNative(ACTIVE_STATUS, USER_NAME_ADAM); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationNamedParamsCustomNames_ThenReturnOneUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setEmail(USER_EMAIL); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User user2 = new User(); + user2.setName(USER_NAME_PETER); + user2.setEmail(USER_EMAIL2); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User userByStatus = userRepository.findUserByUserStatusAndUserName(ACTIVE_STATUS, USER_NAME_ADAM); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDB_WhenFindUserByNameLikeWithQueryAnnotationIndexedParams_ThenReturnUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setEmail(USER_EMAIL); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User userByStatus = userRepository.findUserByNameLike("Ad"); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDB_WhenFindUserByNameLikeWithQueryAnnotationNamedParams_ThenReturnUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setEmail(USER_EMAIL); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User userByStatus = userRepository.findUserByNameLikeNamedParam("Ad"); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDB_WhenFindUserByNameLikeWithQueryAnnotationNative_ThenReturnUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setEmail(USER_EMAIL); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User userByStatus = userRepository.findUserByNameLikeNative("Ad"); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDB_WhenFindAllWithSortByName_ThenReturnUsersSorted() { + userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); + userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); + + List usersSortByName = userRepository.findAll(Sort.by(Sort.Direction.ASC, "name")); + + assertThat(usersSortByName.get(0) + .getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test(expected = PropertyReferenceException.class) + public void givenUsersInDB_WhenFindAllSortWithFunction_ThenThrowException() { + userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); + userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); + + userRepository.findAll(Sort.by(Sort.Direction.ASC, "name")); + + List usersSortByNameLength = userRepository.findAll(Sort.by("LENGTH(name)")); + + assertThat(usersSortByNameLength.get(0) + .getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDB_WhenFindAllSortWithFunctionQueryAnnotationJPQL_ThenReturnUsersSorted() { + userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); + userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); + + userRepository.findAllUsers(Sort.by("name")); + + List usersSortByNameLength = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)")); + + assertThat(usersSortByNameLength.get(0) + .getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDB_WhenFindAllWithPageRequestQueryAnnotationJPQL_ThenReturnPageOfUsers() { + userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); + userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL4, INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE2", LocalDate.now(), USER_EMAIL5, INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL6, INACTIVE_STATUS)); + + Page usersPage = userRepository.findAllUsersWithPagination(PageRequest.of(1, 3)); + + assertThat(usersPage.getContent() + .get(0) + .getName()).isEqualTo("SAMPLE1"); + } + + @Test + public void givenUsersInDB_WhenFindAllWithPageRequestQueryAnnotationNative_ThenReturnPageOfUsers() { + userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); + userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL4, INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE2", LocalDate.now(), USER_EMAIL5, INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL6, INACTIVE_STATUS)); + + Page usersSortByNameLength = userRepository.findAllUsersWithPaginationNative(PageRequest.of(1, 3)); + + assertThat(usersSortByNameLength.getContent() + .get(0) + .getName()).isEqualTo(USER_NAME_PETER); + } + + @Test + @Transactional + public void givenUsersInDB_WhenUpdateStatusForNameModifyingQueryAnnotationJPQL_ThenModifyMatchingUsers() { + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); + + int updatedUsersSize = userRepository.updateUserSetStatusForName(INACTIVE_STATUS, "SAMPLE"); + + assertThat(updatedUsersSize).isEqualTo(2); + } + + @Test + public void givenUsersInDB_WhenFindByEmailsWithDynamicQuery_ThenReturnCollection() { + + User user1 = new User(); + user1.setEmail(USER_EMAIL); + userRepository.save(user1); + + User user2 = new User(); + user2.setEmail(USER_EMAIL2); + userRepository.save(user2); + + User user3 = new User(); + user3.setEmail(USER_EMAIL3); + userRepository.save(user3); + + Set emails = new HashSet<>(); + emails.add(USER_EMAIL2); + emails.add(USER_EMAIL3); + + Collection usersWithEmails = userRepository.findUserByEmails(emails); + + assertThat(usersWithEmails.size()).isEqualTo(2); + } + + @Test + public void givenUsersInDBWhenFindByNameListReturnCollection() { + + User user1 = new User(); + user1.setName(USER_NAME_ADAM); + user1.setEmail(USER_EMAIL); + userRepository.save(user1); + + User user2 = new User(); + user2.setName(USER_NAME_PETER); + user2.setEmail(USER_EMAIL2); + userRepository.save(user2); + + List names = Arrays.asList(USER_NAME_ADAM, USER_NAME_PETER); + + List usersWithNames = userRepository.findUserByNameList(names); + + assertThat(usersWithNames.size()).isEqualTo(2); + } + + + @Test + @Transactional + public void whenInsertedWithQuery_ThenUserIsPersisted() { + userRepository.insertUser(USER_NAME_ADAM, 1, USER_EMAIL, ACTIVE_STATUS, true); + userRepository.insertUser(USER_NAME_PETER, 1, USER_EMAIL2, ACTIVE_STATUS, true); + + User userAdam = userRepository.findUserByNameLike(USER_NAME_ADAM); + User userPeter = userRepository.findUserByNameLike(USER_NAME_PETER); + + assertThat(userAdam).isNotNull(); + assertThat(userAdam.getEmail()).isEqualTo(USER_EMAIL); + assertThat(userPeter).isNotNull(); + assertThat(userPeter.getEmail()).isEqualTo(USER_EMAIL2); + } + + + @Test + @Transactional + public void givenTwoUsers_whenFindByNameUsr01_ThenUserUsr01() { + User usr01 = new User("usr01", LocalDate.now(), "usr01@baeldung.com", 1); + User usr02 = new User("usr02", LocalDate.now(), "usr02@baeldung.com", 1); + + userRepository.save(usr01); + userRepository.save(usr02); + + try (Stream users = userRepository.findAllByName("usr01")) { + assertTrue(users.allMatch(usr -> usr.equals(usr01))); + } + } + + @Test + @Transactional + public void givenTwoUsers_whenFindByNameUsr00_ThenNoUsers() { + User usr01 = new User("usr01", LocalDate.now(), "usr01@baeldung.com", 1); + User usr02 = new User("usr02", LocalDate.now(), "usr02@baeldung.com", 1); + + userRepository.save(usr01); + userRepository.save(usr02); + + try (Stream users = userRepository.findAllByName("usr00")) { + assertEquals(0, users.count()); + } + } + + @Test + public void givenTwoUsers_whenFindUsersWithGmailAddress_ThenUserUsr02() { + User usr01 = new User("usr01", LocalDate.now(), "usr01@baeldung.com", 1); + User usr02 = new User("usr02", LocalDate.now(), "usr02@gmail.com", 1); + + userRepository.save(usr01); + userRepository.save(usr02); + + List users = userRepository.findUsersWithGmailAddress(); + assertEquals(1, users.size()); + assertEquals(usr02, users.get(0)); + } + + @Test + @Transactional + public void givenTwoUsers_whenDeleteAllByCreationDateAfter_ThenOneUserRemains() { + User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); + User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.com", 1); + + userRepository.save(usr01); + userRepository.save(usr02); + + userRepository.deleteAllByCreationDateAfter(LocalDate.of(2018, 5, 1)); + + List users = userRepository.findAll(); + + assertEquals(1, users.size()); + assertEquals(usr01, users.get(0)); + } + + @Test + public void givenTwoUsers_whenFindAllUsersByPredicates_ThenUserUsr01() { + User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); + User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.org", 1); + + userRepository.save(usr01); + userRepository.save(usr02); + + List> predicates = new ArrayList<>(); + predicates.add(usr -> usr.getCreationDate().isAfter(LocalDate.of(2017, 12, 31))); + predicates.add(usr -> usr.getEmail().endsWith(".com")); + + List users = userRepository.findAllUsersByPredicates(predicates); + + assertEquals(1, users.size()); + assertEquals(usr01, users.get(0)); + } + + @Test + @Transactional + public void givenTwoUsers_whenDeactivateUsersNotLoggedInSince_ThenUserUsr02Deactivated() { + User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); + usr01.setLastLoginDate(LocalDate.now()); + User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.org", 1); + usr02.setLastLoginDate(LocalDate.of(2018, 7, 20)); + + userRepository.save(usr01); + userRepository.save(usr02); + + userRepository.deactivateUsersNotLoggedInSince(LocalDate.of(2018, 8, 1)); + + List users = userRepository.findAllUsers(Sort.by(Sort.Order.asc("name"))); + assertTrue(users.get(0).isActive()); + assertFalse(users.get(1).isActive()); + } + + @Test + @Transactional + public void givenTwoUsers_whenDeleteDeactivatedUsers_ThenUserUsr02Deleted() { + User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); + usr01.setLastLoginDate(LocalDate.now()); + User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.com", 0); + usr02.setLastLoginDate(LocalDate.of(2018, 7, 20)); + usr02.setActive(false); + + userRepository.save(usr01); + userRepository.save(usr02); + + int deletedUsersCount = userRepository.deleteDeactivatedUsers(); + + List users = userRepository.findAll(); + assertEquals(1, users.size()); + assertEquals(usr01, users.get(0)); + assertEquals(1, deletedUsersCount); + } + + @Test + @Transactional + public void givenTwoUsers_whenAddDeletedColumn_ThenUsersHaveDeletedColumn() { + User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); + usr01.setLastLoginDate(LocalDate.now()); + User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.org", 1); + usr02.setLastLoginDate(LocalDate.of(2018, 7, 20)); + usr02.setActive(false); + + userRepository.save(usr01); + userRepository.save(usr02); + + userRepository.addDeletedColumn(); + + Query nativeQuery = entityManager.createNativeQuery("select deleted from USERS where NAME = 'usr01'"); + assertEquals(0, nativeQuery.getResultList().get(0)); + } + + @After + public void cleanUp() { + userRepository.deleteAll(); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java new file mode 100644 index 0000000000..1b1d264574 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java @@ -0,0 +1,37 @@ +package com.baeldung.boot.daos; + +import com.baeldung.boot.Application; +import com.baeldung.boot.domain.User; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Created by adam. + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +@DirtiesContext +public class UserRepositoryIntegrationTest extends UserRepositoryCommon { + + @Test + @Transactional + public void givenUsersInDBWhenUpdateStatusForNameModifyingQueryAnnotationNativeThenModifyMatchingUsers() { + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); + userRepository.flush(); + + int updatedUsersSize = userRepository.updateUserSetStatusForNameNative(INACTIVE_STATUS, "SAMPLE"); + + assertThat(updatedUsersSize).isEqualTo(2); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java new file mode 100644 index 0000000000..99eabc8271 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java @@ -0,0 +1,43 @@ +package com.baeldung.boot.daos; + +import com.baeldung.boot.Application; +import com.baeldung.boot.domain.User; +import com.baeldung.util.BaeldungPostgresqlContainer; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; +import org.testcontainers.containers.PostgreSQLContainer; + +import java.time.LocalDate; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Created by adam. + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +@ActiveProfiles({"tc", "tc-auto"}) +public class UserRepositoryTCAutoLiveTest extends UserRepositoryCommon { + + @ClassRule + public static PostgreSQLContainer postgreSQLContainer = BaeldungPostgresqlContainer.getInstance(); + + @Test + @Transactional + public void givenUsersInDB_WhenUpdateStatusForNameModifyingQueryAnnotationNativePostgres_ThenModifyMatchingUsers() { + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); + userRepository.flush(); + + int updatedUsersSize = userRepository.updateUserSetStatusForNameNativePostgres(INACTIVE_STATUS, "SAMPLE"); + + assertThat(updatedUsersSize).isEqualTo(2); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java new file mode 100644 index 0000000000..be8843c166 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java @@ -0,0 +1,58 @@ +package com.baeldung.boot.daos; + +import com.baeldung.boot.Application; +import com.baeldung.boot.domain.User; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; +import org.testcontainers.containers.PostgreSQLContainer; + +import java.time.LocalDate; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) +@ActiveProfiles("tc") +@ContextConfiguration(initializers = {UserRepositoryTCLiveTest.Initializer.class}) +public class UserRepositoryTCLiveTest extends UserRepositoryCommon { + + @ClassRule + public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:11.1") + .withDatabaseName("integration-tests-db") + .withUsername("sa") + .withPassword("sa"); + + @Test + @Transactional + public void givenUsersInDB_WhenUpdateStatusForNameModifyingQueryAnnotationNative_ThenModifyMatchingUsers() { + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); + userRepository.flush(); + + int updatedUsersSize = userRepository.updateUserSetStatusForNameNativePostgres(INACTIVE_STATUS, "SAMPLE"); + + assertThat(updatedUsersSize).isEqualTo(2); + } + + static class Initializer + implements ApplicationContextInitializer { + public void initialize(ConfigurableApplicationContext configurableApplicationContext) { + TestPropertyValues.of( + "spring.datasource.url=" + postgreSQLContainer.getJdbcUrl(), + "spring.datasource.username=" + postgreSQLContainer.getUsername(), + "spring.datasource.password=" + postgreSQLContainer.getPassword() + ).applyTo(configurableApplicationContext.getEnvironment()); + } + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java new file mode 100644 index 0000000000..bf0c85fca6 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java @@ -0,0 +1,252 @@ +package com.baeldung.boot.services; + +import com.baeldung.boot.domain.Foo; +import com.baeldung.boot.services.IOperations; +import com.baeldung.util.IDUtil; +import org.hamcrest.Matchers; +import org.junit.Ignore; +import org.junit.Test; +import org.springframework.dao.DataAccessException; + +import java.io.Serializable; +import java.util.List; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.*; + +public abstract class AbstractServicePersistenceIntegrationTest { + + // tests + + // find - one + + @Test + /**/public final void givenResourceDoesNotExist_whenResourceIsRetrieved_thenNoResourceIsReceived() { + // When + final Foo createdResource = getApi().findOne(IDUtil.randomPositiveLong()); + + // Then + assertNull(createdResource); + } + + @Test + public void givenResourceExists_whenResourceIsRetrieved_thenNoExceptions() { + final Foo existingResource = persistNewEntity(); + getApi().findOne(existingResource.getId()); + } + + @Test + public void givenResourceDoesNotExist_whenResourceIsRetrieved_thenNoExceptions() { + getApi().findOne(IDUtil.randomPositiveLong()); + } + + @Test + public void givenResourceExists_whenResourceIsRetrieved_thenTheResultIsNotNull() { + final Foo existingResource = persistNewEntity(); + final Foo retrievedResource = getApi().findOne(existingResource.getId()); + assertNotNull(retrievedResource); + } + + @Test + public void givenResourceExists_whenResourceIsRetrieved_thenResourceIsRetrievedCorrectly() { + final Foo existingResource = persistNewEntity(); + final Foo retrievedResource = getApi().findOne(existingResource.getId()); + assertEquals(existingResource, retrievedResource); + } + + // find - one - by name + + // find - all + + @Test + /**/public void whenAllResourcesAreRetrieved_thenNoExceptions() { + getApi().findAll(); + } + + @Test + /**/public void whenAllResourcesAreRetrieved_thenTheResultIsNotNull() { + final List resources = getApi().findAll(); + + assertNotNull(resources); + } + + @Test + /**/public void givenAtLeastOneResourceExists_whenAllResourcesAreRetrieved_thenRetrievedResourcesAreNotEmpty() { + persistNewEntity(); + + // When + final List allResources = getApi().findAll(); + + // Then + assertThat(allResources, not(Matchers. empty())); + } + + @Test + /**/public void givenAnResourceExists_whenAllResourcesAreRetrieved_thenTheExistingResourceIsIndeedAmongThem() { + final Foo existingResource = persistNewEntity(); + + final List resources = getApi().findAll(); + + assertThat(resources, hasItem(existingResource)); + } + + @Test + /**/public void whenAllResourcesAreRetrieved_thenResourcesHaveIds() { + persistNewEntity(); + + // When + final List allResources = getApi().findAll(); + + // Then + for (final Foo resource : allResources) { + assertNotNull(resource.getId()); + } + } + + // create + + @Test(expected = RuntimeException.class) + /**/public void whenNullResourceIsCreated_thenException() { + getApi().create(null); + } + + @Test + /**/public void whenResourceIsCreated_thenNoExceptions() { + persistNewEntity(); + } + + @Test + /**/public void whenResourceIsCreated_thenResourceIsRetrievable() { + final Foo existingResource = persistNewEntity(); + + assertNotNull(getApi().findOne(existingResource.getId())); + } + + @Test + /**/public void whenResourceIsCreated_thenSavedResourceIsEqualToOriginalResource() { + final Foo originalResource = createNewEntity(); + final Foo savedResource = getApi().create(originalResource); + + assertEquals(originalResource, savedResource); + } + + @Test(expected = RuntimeException.class) + public void whenResourceWithFailedConstraintsIsCreated_thenException() { + final Foo invalidResource = createNewEntity(); + invalidate(invalidResource); + + getApi().create(invalidResource); + } + + /** + * -- specific to the persistence engine + */ + @Test(expected = DataAccessException.class) + @Ignore("Hibernate simply ignores the id silently and still saved (tracking this)") + public void whenResourceWithIdIsCreated_thenDataAccessException() { + final Foo resourceWithId = createNewEntity(); + resourceWithId.setId(IDUtil.randomPositiveLong()); + + getApi().create(resourceWithId); + } + + // update + + @Test(expected = RuntimeException.class) + /**/public void whenNullResourceIsUpdated_thenException() { + getApi().update(null); + } + + @Test + /**/public void givenResourceExists_whenResourceIsUpdated_thenNoExceptions() { + // Given + final Foo existingResource = persistNewEntity(); + + // When + getApi().update(existingResource); + } + + /** + * - can also be the ConstraintViolationException which now occurs on the update operation will not be translated; as a consequence, it will be a TransactionSystemException + */ + @Test(expected = RuntimeException.class) + public void whenResourceIsUpdatedWithFailedConstraints_thenException() { + final Foo existingResource = persistNewEntity(); + invalidate(existingResource); + + getApi().update(existingResource); + } + + @Test + /**/public void givenResourceExists_whenResourceIsUpdated_thenUpdatesArePersisted() { + // Given + final Foo existingResource = persistNewEntity(); + + // When + change(existingResource); + getApi().update(existingResource); + + final Foo updatedResource = getApi().findOne(existingResource.getId()); + + // Then + assertEquals(existingResource, updatedResource); + } + + // delete + + // @Test(expected = RuntimeException.class) + // public void givenResourceDoesNotExists_whenResourceIsDeleted_thenException() { + // // When + // getApi().delete(IDUtil.randomPositiveLong()); + // } + // + // @Test(expected = RuntimeException.class) + // public void whenResourceIsDeletedByNegativeId_thenException() { + // // When + // getApi().delete(IDUtil.randomNegativeLong()); + // } + // + // @Test + // public void givenResourceExists_whenResourceIsDeleted_thenNoExceptions() { + // // Given + // final Foo existingResource = persistNewEntity(); + // + // // When + // getApi().delete(existingResource.getId()); + // } + // + // @Test + // /**/public final void givenResourceExists_whenResourceIsDeleted_thenResourceNoLongerExists() { + // // Given + // final Foo existingResource = persistNewEntity(); + // + // // When + // getApi().delete(existingResource.getId()); + // + // // Then + // assertNull(getApi().findOne(existingResource.getId())); + // } + + // template method + + protected Foo createNewEntity() { + return new Foo(randomAlphabetic(6)); + } + + protected abstract IOperations getApi(); + + private final void invalidate(final Foo entity) { + entity.setName(null); + } + + private final void change(final Foo entity) { + entity.setName(randomAlphabetic(6)); + } + + protected Foo persistNewEntity() { + return getApi().create(createNewEntity()); + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java new file mode 100644 index 0000000000..72de4918a2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java @@ -0,0 +1,75 @@ +package com.baeldung.boot.services; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.junit.Assert.assertNotNull; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.Application; +import com.baeldung.boot.domain.Foo; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes=Application.class) +public class FooServicePersistenceIntegrationTest extends AbstractServicePersistenceIntegrationTest { + + @Autowired + private IFooService service; + + // tests + + @Test + public final void whenContextIsBootstrapped_thenNoExceptions() { + // + } + + @Test + public final void whenEntityIsCreated_thenNoExceptions() { + service.create(new Foo(randomAlphabetic(6))); + } + + @Test(expected = DataIntegrityViolationException.class) + public final void whenInvalidEntityIsCreated_thenDataException() { + service.create(new Foo()); + } + + @Test(expected = DataIntegrityViolationException.class) + public final void whenEntityWithLongNameIsCreated_thenDataException() { + service.create(new Foo(randomAlphabetic(2048))); + } + + // custom Query method + + @Test + public final void givenUsingCustomQuery_whenRetrievingEntity_thenFound() { + final String name = randomAlphabetic(6); + service.create(new Foo(name)); + + final Foo retrievedByName = service.retrieveByName(name); + assertNotNull(retrievedByName); + } + + // work in progress + + @Test(expected = InvalidDataAccessApiUsageException.class) + @Ignore("Right now, persist has saveOrUpdate semantics, so this will no longer fail") + public final void whenSameEntityIsCreatedTwice_thenDataException() { + final Foo entity = new Foo(randomAlphabetic(8)); + service.create(entity); + service.create(entity); + } + + // API + + @Override + protected final IOperations getApi() { + return service; + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java new file mode 100644 index 0000000000..644d1ec805 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java @@ -0,0 +1,75 @@ +package com.baeldung.boot.services; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.Application; +import com.baeldung.boot.domain.Bar; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes=Application.class) +public class SpringDataJPABarAuditIntegrationTest { + + private static Logger logger = LoggerFactory.getLogger(SpringDataJPABarAuditIntegrationTest.class); + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + logger.info("setUpBeforeClass()"); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + logger.info("tearDownAfterClass()"); + } + + @Autowired + @Qualifier("barSpringDataJpaService") + private IBarService barService; + + @Autowired + private EntityManagerFactory entityManagerFactory; + + private EntityManager em; + + @Before + public void setUp() throws Exception { + logger.info("setUp()"); + em = entityManagerFactory.createEntityManager(); + } + + @After + public void tearDown() throws Exception { + logger.info("tearDown()"); + em.close(); + } + + @Test + @WithMockUser(username = "tutorialuser") + public final void whenBarsModified_thenBarsAudited() { + Bar bar = new Bar("BAR1"); + barService.create(bar); + assertEquals(bar.getCreatedDate(), bar.getModifiedDate()); + assertEquals("tutorialuser", bar.getCreatedBy(), bar.getModifiedBy()); + bar.setName("BAR2"); + bar = barService.update(bar); + assertTrue(bar.getCreatedDate() < bar.getModifiedDate()); + assertEquals("tutorialuser", bar.getCreatedBy(), bar.getModifiedBy()); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java new file mode 100644 index 0000000000..306798aa68 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java @@ -0,0 +1,64 @@ +package com.baeldung.elementcollection; + +import com.baeldung.elementcollection.model.Employee; +import com.baeldung.elementcollection.model.Phone; +import com.baeldung.elementcollection.repository.EmployeeRepository; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Arrays; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ElementCollectionApplication.class) +public class ElementCollectionIntegrationTest { + + @Autowired + private EmployeeRepository employeeRepository; + + @Before + public void init() { + Employee employee = new Employee(1, "Fred"); + employee.setPhones( + Arrays.asList(new Phone("work", "+55", "99999-9999"), new Phone("home", "+55", "98888-8888"))); + employeeRepository.save(employee); + } + + @After + public void clean() { + employeeRepository.remove(1); + } + + @Test(expected = org.hibernate.LazyInitializationException.class) + public void whenAccessLazyCollection_thenThrowLazyInitializationException() { + Employee employee = employeeRepository.findById(1); + assertThat(employee.getPhones().size(), is(2)); + } + + @Test + public void whenUseJPAQL_thenFetchResult() { + Employee employee = employeeRepository.findByJPQL(1); + assertThat(employee.getPhones().size(), is(2)); + } + + @Test + public void whenUseEntityGraph_thenFetchResult() { + Employee employee = employeeRepository.findByEntityGraph(1); + assertThat(employee.getPhones().size(), is(2)); + } + + @Test + @Transactional + public void whenUseTransaction_thenFetchResult() { + Employee employee = employeeRepository.findById(1); + assertThat(employee.getPhones().size(), is(2)); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java new file mode 100644 index 0000000000..a1f4a3fa2c --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java @@ -0,0 +1,96 @@ +package com.baeldung.multipledb; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.Collections; +import java.util.Optional; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.multipledb.dao.product.ProductRepository; +import com.baeldung.multipledb.dao.user.PossessionRepository; +import com.baeldung.multipledb.dao.user.UserRepository; +import com.baeldung.multipledb.model.product.Product; +import com.baeldung.multipledb.model.user.PossessionMultipleDB; +import com.baeldung.multipledb.model.user.UserMultipleDB; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes=MultipleDbApplication.class) +@EnableTransactionManagement +public class JpaMultipleDBIntegrationTest { + + @Autowired + private UserRepository userRepository; + + @Autowired + private PossessionRepository possessionRepository; + + @Autowired + private ProductRepository productRepository; + + // tests + + @Test + @Transactional("userTransactionManager") + public void whenCreatingUser_thenCreated() { + UserMultipleDB user = new UserMultipleDB(); + user.setName("John"); + user.setEmail("john@test.com"); + user.setAge(20); + PossessionMultipleDB p = new PossessionMultipleDB("sample"); + p = possessionRepository.save(p); + user.setPossessionList(Collections.singletonList(p)); + user = userRepository.save(user); + final Optional result = userRepository.findById(user.getId()); + assertTrue(result.isPresent()); + System.out.println(result.get().getPossessionList()); + assertEquals(1, result.get().getPossessionList().size()); + } + + @Test + @Transactional("userTransactionManager") + public void whenCreatingUsersWithSameEmail_thenRollback() { + UserMultipleDB user1 = new UserMultipleDB(); + user1.setName("John"); + user1.setEmail("john@test.com"); + user1.setAge(20); + user1 = userRepository.save(user1); + assertTrue(userRepository.findById(user1.getId()).isPresent()); + + UserMultipleDB user2 = new UserMultipleDB(); + user2.setName("Tom"); + user2.setEmail("john@test.com"); + user2.setAge(10); + try { + user2 = userRepository.save(user2); + userRepository.flush(); + fail("DataIntegrityViolationException should be thrown!"); + } catch (final DataIntegrityViolationException e) { + // Expected + } catch (final Exception e) { + fail("DataIntegrityViolationException should be thrown, instead got: " + e); + } + } + + @Test + @Transactional("productTransactionManager") + public void whenCreatingProduct_thenCreated() { + Product product = new Product(); + product.setName("Book"); + product.setId(2); + product.setPrice(20); + product = productRepository.save(product); + + assertTrue(productRepository.findById(product.getId()).isPresent()); + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java new file mode 100644 index 0000000000..9bfba61a3b --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java @@ -0,0 +1,144 @@ +package com.baeldung.multipledb; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.multipledb.PersistenceProductConfiguration; +import com.baeldung.multipledb.dao.product.ProductRepository; +import com.baeldung.multipledb.model.product.Product; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes=MultipleDbApplication.class) +@EnableTransactionManagement +public class ProductRepositoryIntegrationTest { + + @Autowired + private ProductRepository productRepository; + + @Before + @Transactional("productTransactionManager") + public void setUp() { + productRepository.save(Product.from(1001, "Book", 21)); + productRepository.save(Product.from(1002, "Coffee", 10)); + productRepository.save(Product.from(1003, "Jeans", 30)); + productRepository.save(Product.from(1004, "Shirt", 32)); + productRepository.save(Product.from(1005, "Bacon", 10)); + } + + @Test + public void whenRequestingFirstPageOfSizeTwo_ThenReturnFirstPage() { + Pageable pageRequest = PageRequest.of(0, 2); + + Page result = productRepository.findAll(pageRequest); + + assertThat(result.getContent(), hasSize(2)); + assertTrue(result.stream() + .map(Product::getId) + .allMatch(id -> Arrays.asList(1001, 1002) + .contains(id))); + } + + @Test + public void whenRequestingSecondPageOfSizeTwo_ThenReturnSecondPage() { + Pageable pageRequest = PageRequest.of(1, 2); + + Page result = productRepository.findAll(pageRequest); + + assertThat(result.getContent(), hasSize(2)); + assertTrue(result.stream() + .map(Product::getId) + .allMatch(id -> Arrays.asList(1003, 1004) + .contains(id))); + } + + @Test + public void whenRequestingLastPage_ThenReturnLastPageWithRemData() { + Pageable pageRequest = PageRequest.of(2, 2); + + Page result = productRepository.findAll(pageRequest); + + assertThat(result.getContent(), hasSize(1)); + assertTrue(result.stream() + .map(Product::getId) + .allMatch(id -> Arrays.asList(1005) + .contains(id))); + } + + @Test + public void whenSortingByNameAscAndPaging_ThenReturnSortedPagedResult() { + Pageable pageRequest = PageRequest.of(0, 3, Sort.by("name")); + + Page result = productRepository.findAll(pageRequest); + + assertThat(result.getContent(), hasSize(3)); + assertThat(result.getContent() + .stream() + .map(Product::getId) + .collect(Collectors.toList()), equalTo(Arrays.asList(1005, 1001, 1002))); + + } + + @Test + public void whenSortingByPriceDescAndPaging_ThenReturnSortedPagedResult() { + Pageable pageRequest = PageRequest.of(0, 3, Sort.by("price") + .descending()); + + Page result = productRepository.findAll(pageRequest); + + assertThat(result.getContent(), hasSize(3)); + assertThat(result.getContent() + .stream() + .map(Product::getId) + .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001))); + + } + + @Test + public void whenSortingByPriceDescAndNameAscAndPaging_ThenReturnSortedPagedResult() { + Pageable pageRequest = PageRequest.of(0, 5, Sort.by("price") + .descending() + .and(Sort.by("name"))); + + Page result = productRepository.findAll(pageRequest); + + assertThat(result.getContent(), hasSize(5)); + assertThat(result.getContent() + .stream() + .map(Product::getId) + .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001, 1005, 1002))); + + } + + @Test + public void whenRequestingFirstPageOfSizeTwoUsingCustomMethod_ThenReturnFirstPage() { + Pageable pageRequest = PageRequest.of(0, 2); + + List result = productRepository.findAllByPrice(10, pageRequest); + + assertThat(result, hasSize(2)); + assertTrue(result.stream() + .map(Product::getId) + .allMatch(id -> Arrays.asList(1002, 1005) + .contains(id))); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java new file mode 100644 index 0000000000..71a4dbda3f --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java @@ -0,0 +1,81 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.exception.SQLGrammarException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.TestPropertySource; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) +@TestPropertySource("quoted-lower-case-naming-strategy.properties") +class QuotedLowerCaseNamingStrategyH2IntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PersonRepository personRepository; + + @BeforeEach + void insertPeople() { + personRepository.saveAll(Arrays.asList( + new Person(1L, "John", "Doe"), + new Person(2L, "Jane", "Doe"), + new Person(3L, "Ted", "Mosby") + )); + } + + @ParameterizedTest + @ValueSource(strings = {"person", "PERSON", "Person"}) + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonUnquoted_thenException(String tableName) { + Query query = entityManager.createNativeQuery("select * from " + tableName); + + // Unexpected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + @Test + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { + Query query = entityManager.createNativeQuery("select * from \"PERSON\""); + + // Expected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + @Test + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { + Query query = entityManager.createNativeQuery("select * from \"person\""); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + public Person fromDatabase(Object databaseRow) { + Object[] typedDatabaseRow = (Object[]) databaseRow; + + return new Person( + ((BigInteger) typedDatabaseRow[0]).longValue(), + (String) typedDatabaseRow[1], + (String) typedDatabaseRow[2] + ); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java new file mode 100644 index 0000000000..6b1c984600 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java @@ -0,0 +1,85 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.exception.SQLGrammarException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.TestPropertySource; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) +@TestPropertySource("quoted-lower-case-naming-strategy-on-postgres.properties") +class QuotedLowerCaseNamingStrategyPostgresLiveTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PersonRepository personRepository; + + @BeforeEach + void insertPeople() { + personRepository.saveAll(Arrays.asList( + new Person(1L, "John", "Doe"), + new Person(2L, "Jane", "Doe"), + new Person(3L, "Ted", "Mosby") + )); + } + + @ParameterizedTest + @ValueSource(strings = {"person", "PERSON", "Person"}) + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { + Query query = entityManager.createNativeQuery("select * from " + tableName); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { + Query query = entityManager.createNativeQuery("select * from \"PERSON\""); + + // Expected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + @Test + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { + Query query = entityManager.createNativeQuery("select * from \"person\""); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + public Person fromDatabase(Object databaseRow) { + Object[] typedDatabaseRow = (Object[]) databaseRow; + + return new Person( + ((BigInteger) typedDatabaseRow[0]).longValue(), + (String) typedDatabaseRow[1], + (String) typedDatabaseRow[2] + ); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java new file mode 100644 index 0000000000..f819327a5c --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java @@ -0,0 +1,85 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.exception.SQLGrammarException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.TestPropertySource; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) +@TestPropertySource("quoted-upper-case-naming-strategy.properties") +class QuotedUpperCaseNamingStrategyH2IntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PersonRepository personRepository; + + @BeforeEach + void insertPeople() { + personRepository.saveAll(Arrays.asList( + new Person(1L, "John", "Doe"), + new Person(2L, "Jane", "Doe"), + new Person(3L, "Ted", "Mosby") + )); + } + + @ParameterizedTest + @ValueSource(strings = {"person", "PERSON", "Person"}) + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonUnquoted_thenException(String tableName) { + Query query = entityManager.createNativeQuery("select * from " + tableName); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenResult() { + Query query = entityManager.createNativeQuery("select * from \"PERSON\""); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenException() { + Query query = entityManager.createNativeQuery("select * from \"person\""); + + // Expected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + public Person fromDatabase(Object databaseRow) { + Object[] typedDatabaseRow = (Object[]) databaseRow; + + return new Person( + ((BigInteger) typedDatabaseRow[0]).longValue(), + (String) typedDatabaseRow[1], + (String) typedDatabaseRow[2] + ); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java new file mode 100644 index 0000000000..bd23b81b4b --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java @@ -0,0 +1,81 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.exception.SQLGrammarException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.TestPropertySource; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) +@TestPropertySource("quoted-upper-case-naming-strategy-on-postgres.properties") +class QuotedUpperCaseNamingStrategyPostgresLiveTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PersonRepository personRepository; + + @BeforeEach + void insertPeople() { + personRepository.saveAll(Arrays.asList( + new Person(1L, "John", "Doe"), + new Person(2L, "Jane", "Doe"), + new Person(3L, "Ted", "Mosby") + )); + } + + @ParameterizedTest + @ValueSource(strings = {"person", "PERSON", "Person"}) + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { + Query query = entityManager.createNativeQuery("select * from " + tableName); + + // Unexpected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + @Test + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { + Query query = entityManager.createNativeQuery("select * from \"PERSON\""); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { + Query query = entityManager.createNativeQuery("select * from \"person\""); + + // Expected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + public Person fromDatabase(Object databaseRow) { + Object[] typedDatabaseRow = (Object[]) databaseRow; + + return new Person( + ((BigInteger) typedDatabaseRow[0]).longValue(), + (String) typedDatabaseRow[1], + (String) typedDatabaseRow[2] + ); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java new file mode 100644 index 0000000000..1850fea173 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java @@ -0,0 +1,85 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.exception.SQLGrammarException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.TestPropertySource; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) +@TestPropertySource("spring-physical-naming-strategy.properties") +class SpringPhysicalNamingStrategyH2IntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PersonRepository personRepository; + + @BeforeEach + void insertPeople() { + personRepository.saveAll(Arrays.asList( + new Person(1L, "John", "Doe"), + new Person(2L, "Jane", "Doe"), + new Person(3L, "Ted", "Mosby") + )); + } + + @ParameterizedTest + @ValueSource(strings = {"person", "PERSON", "Person"}) + void givenPeopleAndSpringNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { + Query query = entityManager.createNativeQuery("select * from " + tableName); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndSpringNamingStrategy_whenQueryPersonQuotedUpperCase_thenResult() { + Query query = entityManager.createNativeQuery("select * from \"PERSON\""); + + // Unexpected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndSpringNamingStrategy_whenQueryPersonQuotedLowerCase_thenException() { + Query query = entityManager.createNativeQuery("select * from \"person\""); + + // Unexpected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + public Person fromDatabase(Object databaseRow) { + Object[] typedDatabaseRow = (Object[]) databaseRow; + + return new Person( + ((BigInteger) typedDatabaseRow[0]).longValue(), + (String) typedDatabaseRow[1], + (String) typedDatabaseRow[2] + ); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java new file mode 100644 index 0000000000..e26ebb148d --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java @@ -0,0 +1,85 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.exception.SQLGrammarException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.TestPropertySource; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) +@TestPropertySource("spring-physical-naming-strategy-on-postgres.properties") +class SpringPhysicalNamingStrategyPostgresLiveTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PersonRepository personRepository; + + @BeforeEach + void insertPeople() { + personRepository.saveAll(Arrays.asList( + new Person(1L, "John", "Doe"), + new Person(2L, "Jane", "Doe"), + new Person(3L, "Ted", "Mosby") + )); + } + + @ParameterizedTest + @ValueSource(strings = {"person", "PERSON", "Person"}) + void givenPeopleAndSpringNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { + Query query = entityManager.createNativeQuery("select * from " + tableName); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndSpringNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { + Query query = entityManager.createNativeQuery("select * from \"PERSON\""); + + // Expected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + @Test + void givenPeopleAndSpringNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { + Query query = entityManager.createNativeQuery("select * from \"person\""); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + public Person fromDatabase(Object databaseRow) { + Object[] typedDatabaseRow = (Object[]) databaseRow; + + return new Person( + ((BigInteger) typedDatabaseRow[0]).longValue(), + (String) typedDatabaseRow[1], + (String) typedDatabaseRow[2] + ); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java new file mode 100644 index 0000000000..6311c42e93 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java @@ -0,0 +1,86 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.exception.SQLGrammarException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.TestPropertySource; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) +@TestPropertySource("unquoted-lower-case-naming-strategy.properties") +class UnquotedLowerCaseNamingStrategyH2IntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PersonRepository personRepository; + + @BeforeEach + void insertPeople() { + personRepository.saveAll(Arrays.asList( + new Person(1L, "John", "Doe"), + new Person(2L, "Jane", "Doe"), + new Person(3L, "Ted", "Mosby") + )); + } + + @ParameterizedTest + @ValueSource(strings = {"person", "PERSON", "Person"}) + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { + Query query = entityManager.createNativeQuery("select * from " + tableName); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenResult() { + Query query = entityManager.createNativeQuery("select * from \"PERSON\""); + + // Unexpected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenException() { + Query query = entityManager.createNativeQuery("select * from \"person\""); + + // Unexpected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + public Person fromDatabase(Object databaseRow) { + Object[] typedDatabaseRow = (Object[]) databaseRow; + + return new Person( + ((BigInteger) typedDatabaseRow[0]).longValue(), + (String) typedDatabaseRow[1], + (String) typedDatabaseRow[2] + ); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java new file mode 100644 index 0000000000..033a213cf5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java @@ -0,0 +1,85 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.exception.SQLGrammarException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.TestPropertySource; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) +@TestPropertySource("unquoted-lower-case-naming-strategy-on-postgres.properties") +class UnquotedLowerCaseNamingStrategyPostgresLiveTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PersonRepository personRepository; + + @BeforeEach + void insertPeople() { + personRepository.saveAll(Arrays.asList( + new Person(1L, "John", "Doe"), + new Person(2L, "Jane", "Doe"), + new Person(3L, "Ted", "Mosby") + )); + } + + @ParameterizedTest + @ValueSource(strings = {"person", "PERSON", "Person"}) + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { + Query query = entityManager.createNativeQuery("select * from " + tableName); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { + Query query = entityManager.createNativeQuery("select * from \"PERSON\""); + + // Expected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + @Test + void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { + Query query = entityManager.createNativeQuery("select * from \"person\""); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + public Person fromDatabase(Object databaseRow) { + Object[] typedDatabaseRow = (Object[]) databaseRow; + + return new Person( + ((BigInteger) typedDatabaseRow[0]).longValue(), + (String) typedDatabaseRow[1], + (String) typedDatabaseRow[2] + ); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java new file mode 100644 index 0000000000..7af8001854 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java @@ -0,0 +1,85 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.exception.SQLGrammarException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.TestPropertySource; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) +@TestPropertySource("unquoted-upper-case-naming-strategy.properties") +class UnquotedUpperCaseNamingStrategyH2IntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PersonRepository personRepository; + + @BeforeEach + void insertPeople() { + personRepository.saveAll(Arrays.asList( + new Person(1L, "John", "Doe"), + new Person(2L, "Jane", "Doe"), + new Person(3L, "Ted", "Mosby") + )); + } + + @ParameterizedTest + @ValueSource(strings = {"person", "PERSON", "Person"}) + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { + Query query = entityManager.createNativeQuery("select * from " + tableName); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenResult() { + Query query = entityManager.createNativeQuery("select * from \"PERSON\""); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenException() { + Query query = entityManager.createNativeQuery("select * from \"person\""); + + // Expected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + public Person fromDatabase(Object databaseRow) { + Object[] typedDatabaseRow = (Object[]) databaseRow; + + return new Person( + ((BigInteger) typedDatabaseRow[0]).longValue(), + (String) typedDatabaseRow[1], + (String) typedDatabaseRow[2] + ); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java new file mode 100644 index 0000000000..0151e7ece4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java @@ -0,0 +1,85 @@ +package com.baeldung.namingstrategy; + +import org.hibernate.exception.SQLGrammarException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.TestPropertySource; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) +@TestPropertySource("unquoted-upper-case-naming-strategy-on-postgres.properties") +class UnquotedUpperCaseNamingStrategyPostgresLiveTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private PersonRepository personRepository; + + @BeforeEach + void insertPeople() { + personRepository.saveAll(Arrays.asList( + new Person(1L, "John", "Doe"), + new Person(2L, "Jane", "Doe"), + new Person(3L, "Ted", "Mosby") + )); + } + + @ParameterizedTest + @ValueSource(strings = {"person", "PERSON", "Person"}) + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { + Query query = entityManager.createNativeQuery("select * from " + tableName); + + // Expected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + @Test + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { + Query query = entityManager.createNativeQuery("select * from \"PERSON\""); + + // Unexpected result + assertThrows(SQLGrammarException.class, query::getResultStream); + } + + @Test + void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { + Query query = entityManager.createNativeQuery("select * from \"person\""); + + // Unexpected result + List result = (List) query.getResultStream() + .map(this::fromDatabase) + .collect(Collectors.toList()); + + assertThat(result).isNotEmpty(); + } + + public Person fromDatabase(Object databaseRow) { + Object[] typedDatabaseRow = (Object[]) databaseRow; + + return new Person( + ((BigInteger) typedDatabaseRow[0]).longValue(), + (String) typedDatabaseRow[1], + (String) typedDatabaseRow[2] + ); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java new file mode 100644 index 0000000000..350b67e1c9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java @@ -0,0 +1,56 @@ +package com.baeldung.osiv; + +import com.baeldung.osiv.model.BasicUser; +import com.baeldung.osiv.repository.BasicUserRepository; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.web.servlet.MockMvc; + +import java.util.Arrays; +import java.util.HashSet; + +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@SpringBootTest +@AutoConfigureMockMvc +@ActiveProfiles("test") +@ContextConfiguration(classes = OsivApplication.class) +class UserControllerIntegrationTest { + + @Autowired + private BasicUserRepository userRepository; + + @Autowired + private MockMvc mockMvc; + + @BeforeEach + void setUp() { + BasicUser user = new BasicUser(); + user.setUsername("root"); + user.setPermissions(new HashSet<>(Arrays.asList("PERM_READ", "PERM_WRITE"))); + + userRepository.save(user); + } + + @Test + void givenTheUserExists_WhenOsivIsEnabled_ThenLazyInitWorkEverywhere() throws Exception { + mockMvc.perform(get("/users/root")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.username").value("root")) + .andExpect(jsonPath("$.permissions", containsInAnyOrder("PERM_READ", "PERM_WRITE"))); + } + + @AfterEach + void flushDb() { + userRepository.deleteAll(); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java new file mode 100644 index 0000000000..874e18c4ad --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.partialupdate; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.partialupdate.model.Customer; +import com.baeldung.partialupdate.model.CustomerDto; +import com.baeldung.partialupdate.model.CustomerStructured; +import com.baeldung.partialupdate.service.CustomerService; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = PartialUpdateApplication.class) +public class PartialUpdateUnitTest { + + @Autowired + CustomerService service; + + @Test + public void givenCustomer_whenUpdate_thenSuccess() { + Customer myCustomer = service.addCustomer("John"); + myCustomer = service.updateCustomer(myCustomer.id, "+00"); + assertEquals("+00", myCustomer.phone); + } + + @Test + public void givenCustomer_whenUpdateWithQuery_thenSuccess() { + Customer myCustomer = service.addCustomer("John"); + service.updateCustomerWithCustomQuery(myCustomer.id, "+88"); + myCustomer = service.getCustomer(myCustomer.id); + assertEquals("+88", myCustomer.phone); + } + + @Test + public void givenCustomerDto_whenUpdateWithMapper_thenSuccess() { + CustomerDto dto = new CustomerDto(new Customer()); + dto.name = "Johnny"; + Customer entity = service.addCustomer(dto); + + CustomerDto dto2 = new CustomerDto(entity.id); + dto2.phone = "+44"; + entity = service.updateCustomer(dto2); + + assertEquals("Johnny", entity.name); + } + + @Test + public void givenCustomerStructured_whenUpdateCustomerPhone_thenSuccess() { + CustomerStructured myCustomer = service.addCustomerStructured("John"); + assertEquals(null, myCustomer.contactPhones); + + service.addCustomerPhone(myCustomer.id, "+44"); + myCustomer = service.updateCustomerStructured(myCustomer.id, "Mr. John"); + + assertNotEquals(null, myCustomer.contactPhones); + assertEquals(1, myCustomer.contactPhones.size()); + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java new file mode 100644 index 0000000000..e5ad2dd448 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java @@ -0,0 +1,35 @@ +package com.baeldung.util; + +import org.testcontainers.containers.PostgreSQLContainer; + +public class BaeldungPostgresqlContainer extends PostgreSQLContainer { + + private static final String IMAGE_VERSION = "postgres:11.1"; + + private static BaeldungPostgresqlContainer container; + + + private BaeldungPostgresqlContainer() { + super(IMAGE_VERSION); + } + + public static BaeldungPostgresqlContainer getInstance() { + if (container == null) { + container = new BaeldungPostgresqlContainer(); + } + return container; + } + + @Override + public void start() { + super.start(); + System.setProperty("DB_URL", container.getJdbcUrl()); + System.setProperty("DB_USERNAME", container.getUsername()); + System.setProperty("DB_PASSWORD", container.getPassword()); + } + + @Override + public void stop() { + //do nothing, JVM handles shut down + } +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/util/IDUtil.java b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/util/IDUtil.java new file mode 100644 index 0000000000..45e72e046d --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/java/com/baeldung/util/IDUtil.java @@ -0,0 +1,33 @@ +package com.baeldung.util; + +import java.util.Random; + +public final class IDUtil { + + private IDUtil() { + throw new AssertionError(); + } + + // API + + public static String randomPositiveLongAsString() { + return Long.toString(randomPositiveLong()); + } + + public static String randomNegativeLongAsString() { + return Long.toString(randomNegativeLong()); + } + + public static long randomPositiveLong() { + long id = new Random().nextLong() * 10000; + id = (id < 0) ? (-1 * id) : id; + return id; + } + + private static long randomNegativeLong() { + long id = new Random().nextLong() * 10000; + id = (id > 0) ? (-1 * id) : id; + return id; + } + +} diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/application-test.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/application-test.properties new file mode 100644 index 0000000000..e3d39fe1e2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/application-test.properties @@ -0,0 +1,3 @@ +spring.jpa.hibernate.ddl-auto=update +spring.datasource.url=jdbc:h2:mem:baeldung + diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties new file mode 100644 index 0000000000..04b29de41f --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:postgresql://localhost:5432/quoted-lower-case-strategy +spring.datasource.username=postgres +spring.datasource.password=root + +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.QuotedLowerCaseNamingStrategy +#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties new file mode 100644 index 0000000000..6643c12c8a --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:h2:mem:quoted-lower-case-strategy +spring.datasource.username=sa +spring.datasource.password= + +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.QuotedLowerCaseNamingStrategy +#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties new file mode 100644 index 0000000000..36898d5b4f --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:postgresql://localhost:5432/quoted-upper-case-strategy +spring.datasource.username=postgres +spring.datasource.password=root + +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.QuotedUpperCaseNamingStrategy +#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties new file mode 100644 index 0000000000..6d56d58749 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:h2:mem:quoted-upper-case-strategy +spring.datasource.username=sa +spring.datasource.password= + +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.QuotedUpperCaseNamingStrategy +#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties new file mode 100644 index 0000000000..706b12b1b6 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:postgresql://localhost:5432/spring-strategy +spring.datasource.username=postgres +spring.datasource.password=root + +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy +#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=default-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties new file mode 100644 index 0000000000..c9a0c6f24c --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:h2:mem:spring-strategy +spring.datasource.username=sa +spring.datasource.password= + +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy +#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=default-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties new file mode 100644 index 0000000000..b22472bd8f --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:postgresql://localhost:5432/unquoted-lower-case-strategy +spring.datasource.username=postgres +spring.datasource.password=root + +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.UnquotedLowerCaseNamingStrategy +#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties new file mode 100644 index 0000000000..8083515b4b --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:h2:mem:unquoted-lower-case-strategy +spring.datasource.username=sa +spring.datasource.password= + +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.UnquotedLowerCaseNamingStrategy +#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties new file mode 100644 index 0000000000..da03a0d7b5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:postgresql://localhost:5432/unquoted-upper-case-strategy +spring.datasource.username=postgres +spring.datasource.password=root + +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.UnquotedUpperCaseNamingStrategy +#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties new file mode 100644 index 0000000000..d1b63e008c --- /dev/null +++ b/persistence-modules/spring-data-jpa-enterprise/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties @@ -0,0 +1,9 @@ +spring.datasource.url=jdbc:h2:mem:unquoted-upper-case-strategy +spring.datasource.username=sa +spring.datasource.password= + +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.UnquotedUpperCaseNamingStrategy +#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata +#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create +#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file From 7a86d7de495ebc36a6fae9be9d1ad9c5e888eb4a Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 19 Jul 2020 14:30:43 +0530 Subject: [PATCH 074/309] JAVA-66: New module spring-data-jpa-filtering --- .../spring-data-jpa-filtering/README.md | 19 +++++ .../spring-data-jpa-filtering/pom.xml | 77 +++++++++++++++++ .../main/java/com/baeldung/Application.java | 13 +++ .../com/baeldung/config/StudentJpaConfig.java | 68 +++++++++++++++ .../java/com/baeldung/entity/Customer.java | 37 ++++++++ .../dao/ManyStudentRepository.java | 10 +++ .../persistence/dao/ManyTagRepository.java | 7 ++ .../persistence/dao/StudentRepository.java | 24 ++++++ .../inmemory/persistence/model/KVTag.java | 34 ++++++++ .../persistence/model/LocationTag.java | 40 +++++++++ .../persistence/model/ManyStudent.java | 33 ++++++++ .../inmemory/persistence/model/ManyTag.java | 40 +++++++++ .../inmemory/persistence/model/SkillTag.java | 30 +++++++ .../inmemory/persistence/model/Student.java | 74 ++++++++++++++++ .../baeldung/projection/model/Address.java | 57 +++++++++++++ .../com/baeldung/projection/model/Person.java | 47 +++++++++++ .../repository/AddressRepository.java | 11 +++ .../repository/PersonRepository.java | 14 ++++ .../baeldung/projection/view/AddressView.java | 7 ++ .../baeldung/projection/view/PersonDto.java | 34 ++++++++ .../baeldung/projection/view/PersonView.java | 12 +++ .../repository/CustomerRepository.java | 19 +++++ .../resources/persistence-student.properties | 11 +++ .../AdvancedTaggingIntegrationTest.java | 83 ++++++++++++++++++ .../repository/InMemoryDBIntegrationTest.java | 84 +++++++++++++++++++ .../JpaProjectionIntegrationTest.java | 63 ++++++++++++++ .../CustomerRepositoryIntegrationTest.java | 64 ++++++++++++++ .../resources/persistence-student.properties | 9 ++ .../resources/projection-clean-up-data.sql | 2 + .../test/resources/projection-insert-data.sql | 2 + 30 files changed, 1025 insertions(+) create mode 100644 persistence-modules/spring-data-jpa-filtering/README.md create mode 100644 persistence-modules/spring-data-jpa-filtering/pom.xml create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/Application.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/config/StudentJpaConfig.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/entity/Customer.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/ManyStudentRepository.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/ManyTagRepository.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/StudentRepository.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/KVTag.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/LocationTag.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/ManyStudent.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/ManyTag.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/SkillTag.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/Student.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/model/Address.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/model/Person.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/repository/AddressRepository.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/repository/PersonRepository.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/AddressView.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/PersonDto.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/PersonView.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/repository/CustomerRepository.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/main/resources/persistence-student.properties create mode 100644 persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/persistence/repository/AdvancedTaggingIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/persistence/repository/InMemoryDBIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-filtering/src/test/resources/persistence-student.properties create mode 100644 persistence-modules/spring-data-jpa-filtering/src/test/resources/projection-clean-up-data.sql create mode 100644 persistence-modules/spring-data-jpa-filtering/src/test/resources/projection-insert-data.sql diff --git a/persistence-modules/spring-data-jpa-filtering/README.md b/persistence-modules/spring-data-jpa-filtering/README.md new file mode 100644 index 0000000000..fe2f181154 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/README.md @@ -0,0 +1,19 @@ +## Spring Data JPA - Filtering + +This module contains articles about filtering data using Spring Data JPA + +### Relevant Articles: +- [An Advanced Tagging Implementation with JPA](https://www.baeldung.com/jpa-tagging-advanced) +- [A Simple Tagging Implementation with JPA](https://www.baeldung.com/jpa-tagging) +- [Spring Data JPA and Null Parameters](https://www.baeldung.com/spring-data-jpa-null-parameters) +- [Spring Data JPA Projections](https://www.baeldung.com/spring-data-jpa-projections) + +### Eclipse Config +After importing the project into Eclipse, you may see the following error: +"No persistence xml file found in project" + +This can be ignored: +- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" +Or: +- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator + diff --git a/persistence-modules/spring-data-jpa-filtering/pom.xml b/persistence-modules/spring-data-jpa-filtering/pom.xml new file mode 100644 index 0000000000..2039ef1a37 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + spring-data-jpa-filtering + spring-data-jpa-filtering + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.hibernate + hibernate-ehcache + + + org.hibernate + hibernate-envers + + + + com.h2database + h2 + + + + + org.testcontainers + postgresql + ${testcontainers.postgresql.version} + test + + + + org.postgresql + postgresql + + + + + org.springframework.security + spring-security-test + test + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.google.guava + guava + ${guava.version} + + + + + com.baeldung.boot.Application + 1.10.6 + 42.2.5 + 21.0 + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..3ea3d113da --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/Application.java @@ -0,0 +1,13 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/config/StudentJpaConfig.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/config/StudentJpaConfig.java new file mode 100644 index 0000000000..08f37ea806 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/config/StudentJpaConfig.java @@ -0,0 +1,68 @@ +package com.baeldung.config; + +import java.util.Properties; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@EnableJpaRepositories(basePackages = "com.baeldung.inmemory.persistence.dao") +@PropertySource("persistence-student.properties") +@EnableTransactionManagement +public class StudentJpaConfig { + + @Autowired + private Environment env; + + @Bean + public DataSource dataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName")); + dataSource.setUrl(env.getProperty("jdbc.url")); + dataSource.setUsername(env.getProperty("jdbc.user")); + dataSource.setPassword(env.getProperty("jdbc.pass")); + + return dataSource; + } + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(dataSource()); + em.setPackagesToScan(new String[] { "com.baeldung.inmemory.persistence.model" }); + em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + em.setJpaProperties(additionalProperties()); + return em; + } + + @Bean + JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { + JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(entityManagerFactory); + return transactionManager; + } + + final Properties additionalProperties() { + final Properties hibernateProperties = new Properties(); + + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + hibernateProperties.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql")); + hibernateProperties.setProperty("hibernate.cache.use_second_level_cache", env.getProperty("hibernate.cache.use_second_level_cache")); + hibernateProperties.setProperty("hibernate.cache.use_query_cache", env.getProperty("hibernate.cache.use_query_cache")); + + return hibernateProperties; + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/entity/Customer.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/entity/Customer.java new file mode 100644 index 0000000000..efcae73853 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/entity/Customer.java @@ -0,0 +1,37 @@ +package com.baeldung.entity; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Customer { + + @Id + @GeneratedValue + private long id; + private String name; + private String email; + + public Customer(String name, String email) { + this.name = name; + this.email = email; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/ManyStudentRepository.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/ManyStudentRepository.java new file mode 100644 index 0000000000..a2aa0c5780 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/ManyStudentRepository.java @@ -0,0 +1,10 @@ +package com.baeldung.inmemory.persistence.dao; + +import com.baeldung.inmemory.persistence.model.ManyStudent; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface ManyStudentRepository extends JpaRepository { + List findByManyTags_Name(String name); +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/ManyTagRepository.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/ManyTagRepository.java new file mode 100644 index 0000000000..63337f3cb9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/ManyTagRepository.java @@ -0,0 +1,7 @@ +package com.baeldung.inmemory.persistence.dao; + +import com.baeldung.inmemory.persistence.model.ManyTag; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ManyTagRepository extends JpaRepository { +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/StudentRepository.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/StudentRepository.java new file mode 100644 index 0000000000..8ac91fbf0c --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/dao/StudentRepository.java @@ -0,0 +1,24 @@ +package com.baeldung.inmemory.persistence.dao; + +import com.baeldung.inmemory.persistence.model.Student; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +public interface StudentRepository extends JpaRepository { + + @Query("SELECT s FROM Student s JOIN s.tags t WHERE t = LOWER(:tag)") + List retrieveByTag(@Param("tag") String tag); + + @Query("SELECT s FROM Student s JOIN s.tags t WHERE s.name = LOWER(:name) AND t = LOWER(:tag)") + List retrieveByNameFilterByTag(@Param("name") String name, @Param("tag") String tag); + + @Query("SELECT s FROM Student s JOIN s.skillTags t WHERE t.name = LOWER(:tagName) AND t.value > :tagValue") + List retrieveByNameFilterByMinimumSkillTag(@Param("tagName") String tagName, @Param("tagValue") int tagValue); + + @Query("SELECT s FROM Student s JOIN s.kvTags t WHERE t.key = LOWER(:key)") + List retrieveByKeyTag(@Param("key") String key); + +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/KVTag.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/KVTag.java new file mode 100644 index 0000000000..1fc186f4ce --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/KVTag.java @@ -0,0 +1,34 @@ +package com.baeldung.inmemory.persistence.model; + +import javax.persistence.Embeddable; + +@Embeddable +public class KVTag { + private String key; + private String value; + + public KVTag() { + } + + public KVTag(String key, String value) { + super(); + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/LocationTag.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/LocationTag.java new file mode 100644 index 0000000000..b12ad9fbd1 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/LocationTag.java @@ -0,0 +1,40 @@ +package com.baeldung.inmemory.persistence.model; + +import javax.persistence.Embeddable; + +@Embeddable +public class LocationTag { + private String name; + private int xPos; + private int yPos; + + public LocationTag() { + } + + public LocationTag(String name, int xPos, int yPos) { + super(); + this.name = name; + this.xPos = xPos; + this.yPos = yPos; + } + + public String getName() { + return name; + } + + public int getxPos() { + return xPos; + } + + public void setxPos(int xPos) { + this.xPos = xPos; + } + + public int getyPos() { + return yPos; + } + + public void setyPos(int yPos) { + this.yPos = yPos; + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/ManyStudent.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/ManyStudent.java new file mode 100644 index 0000000000..190740d582 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/ManyStudent.java @@ -0,0 +1,33 @@ +package com.baeldung.inmemory.persistence.model; + +import javax.persistence.*; +import java.util.HashSet; +import java.util.Set; + +@Entity +public class ManyStudent { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + private String name; + + @ManyToMany(cascade = CascadeType.ALL) + @JoinTable(name = "manystudent_manytags", joinColumns = @JoinColumn(name = "manystudent_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "manytag_id", referencedColumnName = "id")) + private Set manyTags = new HashSet<>(); + + public ManyStudent() { + } + + public ManyStudent(String name) { + this.name = name; + } + + public Set getManyTags() { + return manyTags; + } + + public void setManyTags(Set manyTags) { + this.manyTags.addAll(manyTags); + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/ManyTag.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/ManyTag.java new file mode 100644 index 0000000000..5af898f7df --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/ManyTag.java @@ -0,0 +1,40 @@ +package com.baeldung.inmemory.persistence.model; + +import javax.persistence.*; +import java.util.HashSet; +import java.util.Set; + +@Entity +public class ManyTag { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + private String name; + + @ManyToMany(mappedBy = "manyTags") + private Set students = new HashSet<>(); + + public ManyTag() { + } + + public ManyTag(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getStudents() { + return students; + } + + public void setStudents(Set students) { + this.students.addAll(students); + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/SkillTag.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/SkillTag.java new file mode 100644 index 0000000000..738b5d0b36 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/SkillTag.java @@ -0,0 +1,30 @@ +package com.baeldung.inmemory.persistence.model; + +import javax.persistence.Embeddable; + +@Embeddable +public class SkillTag { + private String name; + private int value; + + public SkillTag() { + } + + public SkillTag(String name, int value) { + super(); + this.name = name; + this.value = value; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public String getName() { + return name; + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/Student.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/Student.java new file mode 100644 index 0000000000..f0e824e165 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/inmemory/persistence/model/Student.java @@ -0,0 +1,74 @@ +package com.baeldung.inmemory.persistence.model; + +import java.util.ArrayList; +import java.util.List; +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Student { + + @Id + private long id; + private String name; + + @ElementCollection + private List tags = new ArrayList<>(); + + @ElementCollection + private List skillTags = new ArrayList<>(); + + @ElementCollection + private List kvTags = new ArrayList<>(); + + public Student() { + } + + public Student(long id, String name) { + super(); + this.id = id; + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags.addAll(tags); + } + + public List getSkillTags() { + return skillTags; + } + + public void setSkillTags(List skillTags) { + this.skillTags.addAll(skillTags); + } + + public List getKVTags() { + return this.kvTags; + } + + public void setKVTags(List kvTags) { + this.kvTags.addAll(kvTags); + } + +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/model/Address.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/model/Address.java new file mode 100644 index 0000000000..0c5a3eac60 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/model/Address.java @@ -0,0 +1,57 @@ +package com.baeldung.projection.model; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; + +@Entity +public class Address { + @Id + private Long id; + @OneToOne + private Person person; + private String state; + private String city; + private String street; + private String zipCode; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getZipCode() { + return zipCode; + } + + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/model/Person.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/model/Person.java new file mode 100644 index 0000000000..d18bd1c72d --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/model/Person.java @@ -0,0 +1,47 @@ +package com.baeldung.projection.model; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToOne; + +@Entity +public class Person { + @Id + private Long id; + private String firstName; + private String lastName; + @OneToOne(mappedBy = "person") + private Address address; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/repository/AddressRepository.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/repository/AddressRepository.java new file mode 100644 index 0000000000..c1053f4867 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/repository/AddressRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.projection.repository; + +import com.baeldung.projection.view.AddressView; +import com.baeldung.projection.model.Address; +import org.springframework.data.repository.Repository; + +import java.util.List; + +public interface AddressRepository extends Repository { + List getAddressByState(String state); +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/repository/PersonRepository.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/repository/PersonRepository.java new file mode 100644 index 0000000000..64bc7471e6 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/repository/PersonRepository.java @@ -0,0 +1,14 @@ +package com.baeldung.projection.repository; + +import com.baeldung.projection.model.Person; +import com.baeldung.projection.view.PersonDto; +import com.baeldung.projection.view.PersonView; +import org.springframework.data.repository.Repository; + +public interface PersonRepository extends Repository { + PersonView findByLastName(String lastName); + + PersonDto findByFirstName(String firstName); + + T findByLastName(String lastName, Class type); +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/AddressView.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/AddressView.java new file mode 100644 index 0000000000..7a24a1e9b9 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/AddressView.java @@ -0,0 +1,7 @@ +package com.baeldung.projection.view; + +public interface AddressView { + String getZipCode(); + + PersonView getPerson(); +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/PersonDto.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/PersonDto.java new file mode 100644 index 0000000000..1fd924450b --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/PersonDto.java @@ -0,0 +1,34 @@ +package com.baeldung.projection.view; + +import java.util.Objects; + +public class PersonDto { + private final String firstName; + private final String lastName; + + public PersonDto(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PersonDto personDto = (PersonDto) o; + return Objects.equals(firstName, personDto.firstName) && Objects.equals(lastName, personDto.lastName); + } + + @Override + public int hashCode() { + return Objects.hash(firstName, lastName); + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/PersonView.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/PersonView.java new file mode 100644 index 0000000000..36777ec26f --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/projection/view/PersonView.java @@ -0,0 +1,12 @@ +package com.baeldung.projection.view; + +import org.springframework.beans.factory.annotation.Value; + +public interface PersonView { + String getFirstName(); + + String getLastName(); + + @Value("#{target.firstName + ' ' + target.lastName}") + String getFullName(); +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/repository/CustomerRepository.java b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/repository/CustomerRepository.java new file mode 100644 index 0000000000..65b22bbd84 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/java/com/baeldung/repository/CustomerRepository.java @@ -0,0 +1,19 @@ +package com.baeldung.repository; + +import com.baeldung.entity.Customer; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +public interface CustomerRepository extends JpaRepository { + + List findByName(String name); + + List findByNameAndEmail(String name, String email); + + @Query("SELECT c FROM Customer c WHERE (:name is null or c.name = :name) and (:email is null or c.email = :email)") + List findCustomerByNameAndEmail(@Param("name") String name, @Param("email") String email); + +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/main/resources/persistence-student.properties b/persistence-modules/spring-data-jpa-filtering/src/main/resources/persistence-student.properties new file mode 100644 index 0000000000..d4c82420de --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/main/resources/persistence-student.properties @@ -0,0 +1,11 @@ +jdbc.driverClassName=com.mysql.cj.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/myDb +jdbc.user=tutorialuser +jdbc.pass=tutorialpass + +hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + +hibernate.cache.use_second_level_cache=false +hibernate.cache.use_query_cache=false \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/persistence/repository/AdvancedTaggingIntegrationTest.java b/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/persistence/repository/AdvancedTaggingIntegrationTest.java new file mode 100644 index 0000000000..e98c1fa4a6 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/persistence/repository/AdvancedTaggingIntegrationTest.java @@ -0,0 +1,83 @@ +package com.baeldung.persistence.repository; + +import com.baeldung.config.StudentJpaConfig; +import com.baeldung.inmemory.persistence.dao.ManyStudentRepository; +import com.baeldung.inmemory.persistence.dao.ManyTagRepository; +import com.baeldung.inmemory.persistence.dao.StudentRepository; +import com.baeldung.inmemory.persistence.model.ManyStudent; +import com.baeldung.inmemory.persistence.model.ManyTag; +import com.baeldung.inmemory.persistence.model.SkillTag; +import com.baeldung.inmemory.persistence.model.Student; +import com.baeldung.inmemory.persistence.model.KVTag; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { StudentJpaConfig.class }, loader = AnnotationConfigContextLoader.class) +@Transactional +@DirtiesContext +public class AdvancedTaggingIntegrationTest { + @Resource + private StudentRepository studentRepository; + + @Resource + private ManyStudentRepository manyStudentRepository; + + @Resource + private ManyTagRepository manyTagRepository; + + @Test + public void givenStudentWithSkillTags_whenSave_thenGetByNameAndSkillTag() { + Student student = new Student(1, "Will"); + SkillTag skill1 = new SkillTag("java", 5); + student.setSkillTags(Arrays.asList(skill1)); + studentRepository.save(student); + + Student student2 = new Student(2, "Joe"); + SkillTag skill2 = new SkillTag("java", 1); + student2.setSkillTags(Arrays.asList(skill2)); + studentRepository.save(student2); + + List students = studentRepository.retrieveByNameFilterByMinimumSkillTag("java", 3); + assertEquals("size incorrect", 1, students.size()); + } + + @Test + public void givenStudentWithKVTags_whenSave_thenGetByTagOk() { + Student student = new Student(0, "John"); + student.setKVTags(Arrays.asList(new KVTag("department", "computer science"))); + studentRepository.save(student); + + Student student2 = new Student(1, "James"); + student2.setKVTags(Arrays.asList(new KVTag("department", "humanities"))); + studentRepository.save(student2); + + List students = studentRepository.retrieveByKeyTag("department"); + assertEquals("size incorrect", 2, students.size()); + } + + @Test + public void givenStudentWithManyTags_whenSave_theyGetByTagOk() { + ManyTag tag = new ManyTag("full time"); + manyTagRepository.save(tag); + + ManyStudent student = new ManyStudent("John"); + student.setManyTags(Collections.singleton(tag)); + manyStudentRepository.save(student); + + List students = manyStudentRepository.findByManyTags_Name("full time"); + assertEquals("size incorrect", 1, students.size()); + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/persistence/repository/InMemoryDBIntegrationTest.java b/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/persistence/repository/InMemoryDBIntegrationTest.java new file mode 100644 index 0000000000..d8d867792e --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/persistence/repository/InMemoryDBIntegrationTest.java @@ -0,0 +1,84 @@ +package com.baeldung.persistence.repository; + +import com.baeldung.config.StudentJpaConfig; +import com.baeldung.inmemory.persistence.dao.StudentRepository; +import com.baeldung.inmemory.persistence.model.Student; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { StudentJpaConfig.class }, loader = AnnotationConfigContextLoader.class) +@Transactional +@DirtiesContext +public class InMemoryDBIntegrationTest { + + @Resource + private StudentRepository studentRepository; + + private static final long ID = 1; + private static final String NAME = "john"; + + @Test + public void givenStudent_whenSave_thenGetOk() { + Student student = new Student(ID, NAME); + studentRepository.save(student); + + Student student2 = studentRepository.findById(ID).get(); + assertEquals("name incorrect", NAME, student2.getName()); + } + + @Test + public void givenStudentWithTags_whenSave_thenGetByTagOk() { + Student student = new Student(ID, NAME); + student.setTags(Arrays.asList("full time", "computer science")); + studentRepository.save(student); + + Student student2 = studentRepository.retrieveByTag("full time").get(0); + assertEquals("name incorrect", NAME, student2.getName()); + } + + @Test + public void givenMultipleStudentsWithTags_whenSave_thenGetByTagReturnsCorrectCount() { + Student student = new Student(0, "Larry"); + student.setTags(Arrays.asList("full time", "computer science")); + studentRepository.save(student); + + Student student2 = new Student(1, "Curly"); + student2.setTags(Arrays.asList("part time", "rocket science")); + studentRepository.save(student2); + + Student student3 = new Student(2, "Moe"); + student3.setTags(Arrays.asList("full time", "philosophy")); + studentRepository.save(student3); + + Student student4 = new Student(3, "Shemp"); + student4.setTags(Arrays.asList("part time", "mathematics")); + studentRepository.save(student4); + + List students = studentRepository.retrieveByTag("full time"); + assertEquals("size incorrect", 2, students.size()); + } + + @Test + public void givenStudentWithTags_whenSave_thenGetByNameAndTagOk() { + Student student = new Student(ID, NAME); + student.setTags(Arrays.asList("full time", "computer science")); + studentRepository.save(student); + + Student student2 = studentRepository.retrieveByNameFilterByTag("John", "full time").get(0); + assertEquals("name incorrect", NAME, student2.getName()); + } + +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java b/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java new file mode 100644 index 0000000000..96eaf4ed07 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java @@ -0,0 +1,63 @@ +package com.baeldung.projection; + +import com.baeldung.projection.model.Person; +import com.baeldung.projection.repository.AddressRepository; +import com.baeldung.projection.repository.PersonRepository; +import com.baeldung.projection.view.AddressView; +import com.baeldung.projection.view.PersonDto; +import com.baeldung.projection.view.PersonView; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; + +@DataJpaTest +@RunWith(SpringRunner.class) +@Sql(scripts = "/projection-insert-data.sql") +@Sql(scripts = "/projection-clean-up-data.sql", executionPhase = AFTER_TEST_METHOD) +public class JpaProjectionIntegrationTest { + @Autowired + private AddressRepository addressRepository; + + @Autowired + private PersonRepository personRepository; + + @Test + public void whenUsingClosedProjections_thenViewWithRequiredPropertiesIsReturned() { + AddressView addressView = addressRepository.getAddressByState("CA").get(0); + assertThat(addressView.getZipCode()).isEqualTo("90001"); + + PersonView personView = addressView.getPerson(); + assertThat(personView.getFirstName()).isEqualTo("John"); + assertThat(personView.getLastName()).isEqualTo("Doe"); + } + + @Test + public void whenUsingOpenProjections_thenViewWithRequiredPropertiesIsReturned() { + PersonView personView = personRepository.findByLastName("Doe"); + assertThat(personView.getFullName()).isEqualTo("John Doe"); + } + + @Test + public void whenUsingClassBasedProjections_thenDtoWithRequiredPropertiesIsReturned() { + PersonDto personDto = personRepository.findByFirstName("John"); + assertThat(personDto.getFirstName()).isEqualTo("John"); + assertThat(personDto.getLastName()).isEqualTo("Doe"); + } + + @Test + public void whenUsingDynamicProjections_thenObjectWithRequiredPropertiesIsReturned() { + Person person = personRepository.findByLastName("Doe", Person.class); + PersonView personView = personRepository.findByLastName("Doe", PersonView.class); + PersonDto personDto = personRepository.findByLastName("Doe", PersonDto.class); + + assertThat(person.getFirstName()).isEqualTo("John"); + assertThat(personView.getFirstName()).isEqualTo("John"); + assertThat(personDto.getFirstName()).isEqualTo("John"); + } +} diff --git a/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java new file mode 100644 index 0000000000..5d6457ce30 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java @@ -0,0 +1,64 @@ +package com.baeldung.repository; + +import com.baeldung.entity.Customer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@DataJpaTest +@RunWith(SpringRunner.class) +public class CustomerRepositoryIntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + @Autowired + private CustomerRepository repository; + + @Before + public void before() { + entityManager.persist(new Customer("A", "A@example.com")); + entityManager.persist(new Customer("D", null)); + entityManager.persist(new Customer("D", "D@example.com")); + } + + @Test + public void givenQueryMethod_whenEmailIsNull_thenFoundByNullEmail() { + List customers = repository.findByNameAndEmail("D", null); + + assertEquals(1, customers.size()); + Customer actual = customers.get(0); + + assertEquals(null, actual.getEmail()); + assertEquals("D", actual.getName()); + } + + @Test + public void givenQueryMethod_whenEmailIsAbsent_thenIgnoreEmail() { + List customers = repository.findByName("D"); + + assertEquals(2, customers.size()); + } + + @Test + public void givenQueryAnnotation_whenEmailIsNull_thenIgnoreEmail() { + List customers = repository.findCustomerByNameAndEmail("D", null); + + assertEquals(2, customers.size()); + } + + @After + public void cleanUp() { + repository.deleteAll(); + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-filtering/src/test/resources/persistence-student.properties b/persistence-modules/spring-data-jpa-filtering/src/test/resources/persistence-student.properties new file mode 100644 index 0000000000..3b6b580630 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/test/resources/persistence-student.properties @@ -0,0 +1,9 @@ +jdbc.driverClassName=org.h2.Driver +jdbc.url=jdbc:h2:mem:myDb;DB_CLOSE_DELAY=-1 + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create + +hibernate.cache.use_second_level_cache=false +hibernate.cache.use_query_cache=false \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-filtering/src/test/resources/projection-clean-up-data.sql b/persistence-modules/spring-data-jpa-filtering/src/test/resources/projection-clean-up-data.sql new file mode 100644 index 0000000000..d34f6f0636 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/test/resources/projection-clean-up-data.sql @@ -0,0 +1,2 @@ +DELETE FROM address; +DELETE FROM person; \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-filtering/src/test/resources/projection-insert-data.sql b/persistence-modules/spring-data-jpa-filtering/src/test/resources/projection-insert-data.sql new file mode 100644 index 0000000000..544dcc4b88 --- /dev/null +++ b/persistence-modules/spring-data-jpa-filtering/src/test/resources/projection-insert-data.sql @@ -0,0 +1,2 @@ +INSERT INTO person(id,first_name,last_name) VALUES (1,'John','Doe'); +INSERT INTO address(id,person_id,state,city,street,zip_code) VALUES (1,1,'CA', 'Los Angeles', 'Standford Ave', '90001'); \ No newline at end of file From 52da4c8ee8d39c0bd419d0ed2834fc13e6dac8f7 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 19 Jul 2020 14:31:01 +0530 Subject: [PATCH 075/309] JAVA-66: New module spring-data-jpa-query --- .../spring-data-jpa-query/README.md | 22 ++ .../spring-data-jpa-query/pom.xml | 48 +++++ .../main/java/com/baeldung/Application.java | 13 ++ .../baeldung/aggregation/model/Comment.java | 85 ++++++++ .../com/baeldung/aggregation/model/Post.java | 75 +++++++ .../model/custom/CommentCount.java | 27 +++ .../model/custom/ICommentCount.java | 8 + .../repository/CommentRepository.java | 27 +++ .../baeldung/boot/daos/ArticleRepository.java | 23 +++ .../com/baeldung/boot/domain/Article.java | 23 +++ .../passenger/CustomPassengerRepository.java | 8 + .../baeldung/boot/passenger/Passenger.java | 82 ++++++++ .../boot/passenger/PassengerRepository.java | 22 ++ .../passenger/PassengerRepositoryImpl.java | 20 ++ .../entitygraph/model/Characteristic.java | 43 ++++ .../com/baeldung/entitygraph/model/Item.java | 48 +++++ .../repository/CharacteristicsRepository.java | 13 ++ .../repository/ItemRepository.java | 13 ++ .../main/java/com/baeldung/exists/Car.java | 48 +++++ .../com/baeldung/exists/CarRepository.java | 24 +++ .../com/baeldung/joins/model/Department.java | 45 +++++ .../com/baeldung/joins/model/Employee.java | 69 +++++++ .../java/com/baeldung/joins/model/Phone.java | 44 ++++ .../src/main/resources/apple-fruit-data.xml | 7 + .../resources/application-joins.properties | 1 + .../src/main/resources/application.properties | 1 + .../src/main/resources/db/import_joins.sql | 13 ++ .../src/main/resources/fruit-data.json | 14 ++ .../src/main/resources/guava-fruit-data.xml | 7 + .../src/main/resources/import_entities.sql | 3 + .../SpringDataAggregateIntegrationTest.java | 107 ++++++++++ .../ArticleRepositoryIntegrationTest.java | 67 ++++++ .../PassengerRepositoryIntegrationTest.java | 190 ++++++++++++++++++ .../EntityGraphIntegrationTest.java | 39 ++++ .../exists/CarRepositoryIntegrationTest.java | 87 ++++++++ .../joins/JpaJoinsIntegrationTest.java | 142 +++++++++++++ .../src/test/resources/entitygraph-data.sql | 7 + .../resources/projection-clean-up-data.sql | 2 + .../test/resources/projection-insert-data.sql | 2 + .../test/resources/test-aggregation-data.sql | 7 + .../src/test/resources/test-fruit-data.sql | 6 + 41 files changed, 1532 insertions(+) create mode 100644 persistence-modules/spring-data-jpa-query/README.md create mode 100644 persistence-modules/spring-data-jpa-query/pom.xml create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/Application.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/Comment.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/Post.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/custom/CommentCount.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/custom/ICommentCount.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/repository/CommentRepository.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/daos/ArticleRepository.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/domain/Article.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/Passenger.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/model/Characteristic.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/model/Item.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/exists/Car.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/exists/CarRepository.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Department.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Employee.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Phone.java create mode 100644 persistence-modules/spring-data-jpa-query/src/main/resources/apple-fruit-data.xml create mode 100644 persistence-modules/spring-data-jpa-query/src/main/resources/application-joins.properties create mode 100644 persistence-modules/spring-data-jpa-query/src/main/resources/application.properties create mode 100644 persistence-modules/spring-data-jpa-query/src/main/resources/db/import_joins.sql create mode 100644 persistence-modules/spring-data-jpa-query/src/main/resources/fruit-data.json create mode 100644 persistence-modules/spring-data-jpa-query/src/main/resources/guava-fruit-data.xml create mode 100644 persistence-modules/spring-data-jpa-query/src/main/resources/import_entities.sql create mode 100644 persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/aggregation/SpringDataAggregateIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-query/src/test/resources/entitygraph-data.sql create mode 100644 persistence-modules/spring-data-jpa-query/src/test/resources/projection-clean-up-data.sql create mode 100644 persistence-modules/spring-data-jpa-query/src/test/resources/projection-insert-data.sql create mode 100644 persistence-modules/spring-data-jpa-query/src/test/resources/test-aggregation-data.sql create mode 100644 persistence-modules/spring-data-jpa-query/src/test/resources/test-fruit-data.sql diff --git a/persistence-modules/spring-data-jpa-query/README.md b/persistence-modules/spring-data-jpa-query/README.md new file mode 100644 index 0000000000..bfff3c0ef3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/README.md @@ -0,0 +1,22 @@ +## Spring Data JPA - Query + +This module contains articles about querying data using Spring Data JPA + +### Relevant Articles: +- [Query Entities by Dates and Times with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-query-by-date) +- [The Exists Query in Spring Data](https://www.baeldung.com/spring-data-exists-query) +- [Customizing the Result of JPA Queries with Aggregation Functions](https://www.baeldung.com/jpa-queries-custom-result-with-aggregation-functions) +- [Limiting Query Results with JPA and Spring Data JPA](https://www.baeldung.com/jpa-limit-query-results) +- [Sorting Query Results with Spring Data](https://www.baeldung.com/spring-data-sorting) +- [Spring Data JPA Query by Example](https://www.baeldung.com/spring-data-query-by-example) +- [JPA Join Types](https://www.baeldung.com/jpa-join-types) +- [Spring Data JPA and Named Entity Graphs](https://www.baeldung.com/spring-data-jpa-named-entity-graphs) + +### Eclipse Config +After importing the project into Eclipse, you may see the following error: +"No persistence xml file found in project" + +This can be ignored: +- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" +Or: +- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator diff --git a/persistence-modules/spring-data-jpa-query/pom.xml b/persistence-modules/spring-data-jpa-query/pom.xml new file mode 100644 index 0000000000..71498143c3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + spring-data-jpa-query + spring-data-jpa-query + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + com.h2database + h2 + + + + net.ttddyy + datasource-proxy + ${datasource-proxy.version} + + + + com.fasterxml.jackson.core + jackson-databind + + + + org.springframework + spring-oxm + + + + + 1.4.1 + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..3ea3d113da --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/Application.java @@ -0,0 +1,13 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/Comment.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/Comment.java new file mode 100644 index 0000000000..26c2373cbe --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/Comment.java @@ -0,0 +1,85 @@ +package com.baeldung.aggregation.model; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import java.util.Objects; + +@Entity +public class Comment { + @Id + private Integer id; + private Integer year; + private boolean approved; + private String content; + @ManyToOne + private Post post; + + public Comment() { + } + + public Comment(int id, int year, boolean approved, String content, Post post) { + this.id = id; + this.year = year; + this.approved = approved; + this.content = content; + this.post = post; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } + + public boolean isApproved() { + return approved; + } + + public void setApproved(boolean approved) { + this.approved = approved; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Post getPost() { + return post; + } + + public void setPost(Post post) { + this.post = post; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Comment)) { + return false; + } + Comment comment = (Comment) o; + return getId().equals(comment.getId()); + } + + @Override + public int hashCode() { + return Objects.hash(getId()); + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/Post.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/Post.java new file mode 100644 index 0000000000..f396e080ae --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/Post.java @@ -0,0 +1,75 @@ +package com.baeldung.aggregation.model; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import java.util.List; +import java.util.Objects; + +@Entity +public class Post { + @Id + private Integer id; + private String title; + private String content; + @OneToMany(mappedBy = "post") + private List comments; + + public Post() { + } + + public Post(Integer id, String title, String content) { + this.id = id; + this.title = title; + this.content = content; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public List getComments() { + return comments; + } + + public void setComments(List comments) { + this.comments = comments; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Post)) { + return false; + } + Post post = (Post) o; + return getId().equals(post.getId()); + } + + @Override + public int hashCode() { + return Objects.hash(getId()); + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/custom/CommentCount.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/custom/CommentCount.java new file mode 100644 index 0000000000..510b52a47c --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/custom/CommentCount.java @@ -0,0 +1,27 @@ +package com.baeldung.aggregation.model.custom; + +public class CommentCount { + private Integer year; + private Long total; + + public CommentCount(Integer year, Long total) { + this.year = year; + this.total = total; + } + + public Integer getYear() { + return year; + } + + public void setYear(Integer year) { + this.year = year; + } + + public Long getTotal() { + return total; + } + + public void setTotal(Long total) { + this.total = total; + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/custom/ICommentCount.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/custom/ICommentCount.java new file mode 100644 index 0000000000..acb25cfd49 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/model/custom/ICommentCount.java @@ -0,0 +1,8 @@ +package com.baeldung.aggregation.model.custom; + +public interface ICommentCount { + + Integer getYearComment(); + + Long getTotalComment(); +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/repository/CommentRepository.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/repository/CommentRepository.java new file mode 100644 index 0000000000..89e9345e94 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/aggregation/repository/CommentRepository.java @@ -0,0 +1,27 @@ +package com.baeldung.aggregation.repository; + +import com.baeldung.aggregation.model.Comment; +import com.baeldung.aggregation.model.custom.CommentCount; +import com.baeldung.aggregation.model.custom.ICommentCount; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface CommentRepository extends JpaRepository { + + @Query("SELECT c.year, COUNT(c.year) FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC") + List countTotalCommentsByYear(); + + @Query("SELECT new com.baeldung.aggregation.model.custom.CommentCount(c.year, COUNT(c.year)) FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC") + List countTotalCommentsByYearClass(); + + @Query("SELECT c.year AS yearComment, COUNT(c.year) AS totalComment FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC") + List countTotalCommentsByYearInterface(); + + @Query(value = "SELECT c.year AS yearComment, COUNT(c.*) AS totalComment FROM comment AS c GROUP BY c.year ORDER BY c.year DESC", nativeQuery = true) + List countTotalCommentsByYearNative(); + +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/daos/ArticleRepository.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/daos/ArticleRepository.java new file mode 100644 index 0000000000..73397ad42e --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/daos/ArticleRepository.java @@ -0,0 +1,23 @@ +package com.baeldung.boot.daos; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import com.baeldung.boot.domain.Article; + +import java.util.Date; +import java.util.List; + +public interface ArticleRepository extends JpaRepository { + + List

findAllByPublicationDate(Date publicationDate); + + List
findAllByPublicationTimeBetween(Date publicationTimeStart, + Date publicationTimeEnd); + + @Query("select a from Article a where a.creationDateTime <= :creationDateTime") + List
findAllWithCreationDateTimeBefore( + @Param("creationDateTime") Date creationDateTime); + +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/domain/Article.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/domain/Article.java new file mode 100644 index 0000000000..de4dbed1a0 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/domain/Article.java @@ -0,0 +1,23 @@ +package com.baeldung.boot.domain; + +import javax.persistence.*; +import java.util.Date; + +@Entity +public class Article { + + @Id + @GeneratedValue + private Integer id; + @Temporal(TemporalType.DATE) + private Date publicationDate; + @Temporal(TemporalType.TIME) + private Date publicationTime; + @Temporal(TemporalType.TIMESTAMP) + private Date creationDateTime; + + public Integer getId() { + return id; + } + +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java new file mode 100644 index 0000000000..7152286c83 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.boot.passenger; + +import java.util.List; + +interface CustomPassengerRepository { + + List findOrderedBySeatNumberLimitedTo(int limit); +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/Passenger.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/Passenger.java new file mode 100644 index 0000000000..c75107a783 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/Passenger.java @@ -0,0 +1,82 @@ +package com.baeldung.boot.passenger; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import java.util.Objects; + +@Entity +class Passenger { + + @Id + @GeneratedValue + @Column(nullable = false) + private Long id; + + @Basic(optional = false) + @Column(nullable = false) + private String firstName; + + @Basic(optional = false) + @Column(nullable = false) + private String lastName; + + @Basic(optional = false) + @Column(nullable = false) + private Integer seatNumber; + + private Passenger(String firstName, String lastName, Integer seatNumber) { + this.firstName = firstName; + this.lastName = lastName; + this.seatNumber = seatNumber; + } + + static Passenger from(String firstName, String lastName, Integer seatNumber) { + return new Passenger(firstName, lastName, seatNumber); + } + + @Override + public boolean equals(Object object) { + if (this == object) + return true; + if (object == null || getClass() != object.getClass()) + return false; + Passenger passenger = (Passenger) object; + return getSeatNumber() == passenger.getSeatNumber() && Objects.equals(getFirstName(), passenger.getFirstName()) + && Objects.equals(getLastName(), passenger.getLastName()); + } + + @Override + public int hashCode() { + return Objects.hash(getFirstName(), getLastName(), getSeatNumber()); + } + + @Override + public String toString() { + final StringBuilder toStringBuilder = new StringBuilder(getClass().getSimpleName()); + toStringBuilder.append("{ id=").append(id); + toStringBuilder.append(", firstName='").append(firstName).append('\''); + toStringBuilder.append(", lastName='").append(lastName).append('\''); + toStringBuilder.append(", seatNumber=").append(seatNumber); + toStringBuilder.append('}'); + return toStringBuilder.toString(); + } + + Long getId() { + return id; + } + + String getFirstName() { + return firstName; + } + + String getLastName() { + return lastName; + } + + Integer getSeatNumber() { + return seatNumber; + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java new file mode 100644 index 0000000000..14d5403cb5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java @@ -0,0 +1,22 @@ +package com.baeldung.boot.passenger; + +import java.util.List; + +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.repository.JpaRepository; + +interface PassengerRepository extends JpaRepository, CustomPassengerRepository { + + Passenger findFirstByOrderBySeatNumberAsc(); + + Passenger findTopByOrderBySeatNumberAsc(); + + List findByOrderBySeatNumberAsc(); + + List findByFirstNameIgnoreCase(String firstName); + + List findByLastNameOrderBySeatNumberAsc(String lastName); + + List findByLastName(String lastName, Sort sort); + +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java new file mode 100644 index 0000000000..508c669066 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java @@ -0,0 +1,20 @@ +package com.baeldung.boot.passenger; + +import org.springframework.stereotype.Repository; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import java.util.List; + +@Repository +class PassengerRepositoryImpl implements CustomPassengerRepository { + + @PersistenceContext + private EntityManager entityManager; + + @Override + public List findOrderedBySeatNumberLimitedTo(int limit) { + return entityManager.createQuery("SELECT p FROM Passenger p ORDER BY p.seatNumber", + Passenger.class).setMaxResults(limit).getResultList(); + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/model/Characteristic.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/model/Characteristic.java new file mode 100644 index 0000000000..ae20375572 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/model/Characteristic.java @@ -0,0 +1,43 @@ +package com.baeldung.entitygraph.model; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +@Entity +public class Characteristic { + + @Id + private Long id; + private String type; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private Item item; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Item getItem() { + return item; + } + + public void setItem(Item item) { + this.item = item; + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/model/Item.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/model/Item.java new file mode 100644 index 0000000000..e90a22ef62 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/model/Item.java @@ -0,0 +1,48 @@ +package com.baeldung.entitygraph.model; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.NamedAttributeNode; +import javax.persistence.NamedEntityGraph; +import javax.persistence.OneToMany; + +@Entity +@NamedEntityGraph(name = "Item.characteristics", + attributeNodes = @NamedAttributeNode("characteristics") +) +public class Item { + + @Id + private Long id; + private String name; + + @OneToMany(mappedBy = "item") + private List characteristics = new ArrayList<>(); + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getCharacteristics() { + return characteristics; + } + + public void setCharacteristics(List characteristics) { + this.characteristics = characteristics; + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java new file mode 100644 index 0000000000..9f923ab241 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java @@ -0,0 +1,13 @@ +package com.baeldung.entitygraph.repository; + +import org.springframework.data.jpa.repository.EntityGraph; +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.entitygraph.model.Characteristic; + +public interface CharacteristicsRepository extends JpaRepository { + + @EntityGraph(attributePaths = {"item"}) + Characteristic findByType(String type); + +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java new file mode 100644 index 0000000000..b2a5f223b3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java @@ -0,0 +1,13 @@ +package com.baeldung.entitygraph.repository; + +import org.springframework.data.jpa.repository.EntityGraph; +import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType; +import org.springframework.data.jpa.repository.JpaRepository; + +import com.baeldung.entitygraph.model.Item; + +public interface ItemRepository extends JpaRepository { + + @EntityGraph(value = "Item.characteristics", type = EntityGraphType.FETCH) + Item findByName(String name); +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/exists/Car.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/exists/Car.java new file mode 100644 index 0000000000..bf09caf6ff --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/exists/Car.java @@ -0,0 +1,48 @@ +package com.baeldung.exists; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +/** + * @author paullatzelsperger + * @since 2019-03-20 + */ +@Entity +public class Car { + + @Id + @GeneratedValue + private int id; + private Integer power; + private String model; + + Car() { + + } + + public Car(int power, String model) { + this.power = power; + this.model = model; + } + + public Integer getPower() { + return power; + } + + public void setPower(Integer power) { + this.power = power; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public int getId() { + return id; + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/exists/CarRepository.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/exists/CarRepository.java new file mode 100644 index 0000000000..a54f19f4cd --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/exists/CarRepository.java @@ -0,0 +1,24 @@ +package com.baeldung.exists; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +/** + * @author paullatzelsperger + * @since 2019-03-20 + */ +@Repository +public interface CarRepository extends JpaRepository { + + boolean existsCarByPower(int power); + + boolean existsCarByModel(String model); + + @Query("select case when count(c)> 0 then true else false end from Car c where c.model = :model") + boolean existsCarExactCustomQuery(@Param("model") String model); + + @Query("select case when count(c)> 0 then true else false end from Car c where lower(c.model) like lower(:model)") + boolean existsCarLikeCustomQuery(@Param("model") String model); +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Department.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Department.java new file mode 100644 index 0000000000..439f7532f5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Department.java @@ -0,0 +1,45 @@ +package com.baeldung.joins.model; + +import java.util.List; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +@Entity +public class Department { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + private String name; + + @OneToMany(mappedBy = "department") + private List employees; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getEmployees() { + return employees; + } + + public void setEmployees(List employees) { + this.employees = employees; + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Employee.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Employee.java new file mode 100644 index 0000000000..277274e61c --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Employee.java @@ -0,0 +1,69 @@ +package com.baeldung.joins.model; + +import java.util.List; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "joins_employee") +public class Employee { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private String name; + + private int age; + + @ManyToOne + private Department department; + + @OneToMany(mappedBy = "employee") + private List phones; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public Department getDepartment() { + return department; + } + + public void setDepartment(Department department) { + this.department = department; + } + + public List getPhones() { + return phones; + } + + public void setPhones(List phones) { + this.phones = phones; + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Phone.java b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Phone.java new file mode 100644 index 0000000000..41382915b1 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/java/com/baeldung/joins/model/Phone.java @@ -0,0 +1,44 @@ +package com.baeldung.joins.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class Phone { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + private String number; + + @ManyToOne + private Employee employee; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + + public Employee getEmployee() { + return employee; + } + + public void setEmployee(Employee employee) { + this.employee = employee; + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/main/resources/apple-fruit-data.xml b/persistence-modules/spring-data-jpa-query/src/main/resources/apple-fruit-data.xml new file mode 100644 index 0000000000..d87ae28f1e --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/resources/apple-fruit-data.xml @@ -0,0 +1,7 @@ + + + + 1 + apple + red + diff --git a/persistence-modules/spring-data-jpa-query/src/main/resources/application-joins.properties b/persistence-modules/spring-data-jpa-query/src/main/resources/application-joins.properties new file mode 100644 index 0000000000..fe2270293b --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/resources/application-joins.properties @@ -0,0 +1 @@ +spring.datasource.data=classpath:db/import_joins.sql diff --git a/persistence-modules/spring-data-jpa-query/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-query/src/main/resources/application.properties new file mode 100644 index 0000000000..72fc330767 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.jpa.show-sql=true \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query/src/main/resources/db/import_joins.sql b/persistence-modules/spring-data-jpa-query/src/main/resources/db/import_joins.sql new file mode 100644 index 0000000000..e4772d6ff2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/resources/db/import_joins.sql @@ -0,0 +1,13 @@ +INSERT INTO department (id, name) VALUES (1, 'Infra'); +INSERT INTO department (id, name) VALUES (2, 'Accounting'); +INSERT INTO department (id, name) VALUES (3, 'Management'); + +INSERT INTO joins_employee (id, name, age, department_id) VALUES (1, 'Baeldung', '35', 1); +INSERT INTO joins_employee (id, name, age, department_id) VALUES (2, 'John', '35', 2); +INSERT INTO joins_employee (id, name, age, department_id) VALUES (3, 'Jane', '35', 2); + +INSERT INTO phone (id, number, employee_id) VALUES (1, '111', 1); +INSERT INTO phone (id, number, employee_id) VALUES (2, '222', 1); +INSERT INTO phone (id, number, employee_id) VALUES (3, '333', 1); + +COMMIT; diff --git a/persistence-modules/spring-data-jpa-query/src/main/resources/fruit-data.json b/persistence-modules/spring-data-jpa-query/src/main/resources/fruit-data.json new file mode 100644 index 0000000000..6dc44e2586 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/resources/fruit-data.json @@ -0,0 +1,14 @@ +[ + { + "_class": "com.baeldung.entity.Fruit", + "name": "apple", + "color": "red", + "id": 1 + }, + { + "_class": "com.baeldung.entity.Fruit", + "name": "guava", + "color": "green", + "id": 2 + } +] \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query/src/main/resources/guava-fruit-data.xml b/persistence-modules/spring-data-jpa-query/src/main/resources/guava-fruit-data.xml new file mode 100644 index 0000000000..ffd75bb4bb --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/resources/guava-fruit-data.xml @@ -0,0 +1,7 @@ + + + + 2 + guava + green + diff --git a/persistence-modules/spring-data-jpa-query/src/main/resources/import_entities.sql b/persistence-modules/spring-data-jpa-query/src/main/resources/import_entities.sql new file mode 100644 index 0000000000..4fe18bf4aa --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/main/resources/import_entities.sql @@ -0,0 +1,3 @@ +insert into Article(id, publication_date, publication_time, creation_date_time) values(1, TO_DATE('01/01/2018', 'DD/MM/YYYY'), TO_DATE('15:00', 'HH24:MI'), TO_DATE('31/12/2017 07:30', 'DD/MM/YYYY HH24:MI')); +insert into Article(id, publication_date, publication_time, creation_date_time) values(2, TO_DATE('01/01/2018', 'DD/MM/YYYY'), TO_DATE('15:30', 'HH24:MI'), TO_DATE('15/12/2017 08:00', 'DD/MM/YYYY HH24:MI')); +insert into Article(id, publication_date, publication_time, creation_date_time) values(3, TO_DATE('15/12/2017', 'DD/MM/YYYY'), TO_DATE('16:00', 'HH24:MI'), TO_DATE('01/12/2017 13:45', 'DD/MM/YYYY HH24:MI')); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/aggregation/SpringDataAggregateIntegrationTest.java b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/aggregation/SpringDataAggregateIntegrationTest.java new file mode 100644 index 0000000000..779ade7a3f --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/aggregation/SpringDataAggregateIntegrationTest.java @@ -0,0 +1,107 @@ +package com.baeldung.aggregation; + +import com.baeldung.aggregation.model.custom.CommentCount; +import com.baeldung.aggregation.model.custom.ICommentCount; +import com.baeldung.aggregation.repository.CommentRepository; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +@RunWith(SpringRunner.class) +@DataJpaTest + +@Sql(scripts = "/test-aggregation-data.sql") +public class SpringDataAggregateIntegrationTest { + + @Autowired + private CommentRepository commentRepository; + + @Test + public void whenQueryWithAggregation_thenReturnResult() { + List commentCountsByYear = commentRepository.countTotalCommentsByYear(); + + Object[] countYear2019 = commentCountsByYear.get(0); + + assertThat(countYear2019[0], is(Integer.valueOf(2019))); + assertThat(countYear2019[1], is(1l)); + + Object[] countYear2018 = commentCountsByYear.get(1); + + assertThat(countYear2018[0], is(Integer.valueOf(2018))); + assertThat(countYear2018[1], is(2l)); + + Object[] countYear2017 = commentCountsByYear.get(2); + + assertThat(countYear2017[0], is(Integer.valueOf(2017))); + assertThat(countYear2017[1], is(1l)); + } + + @Test + public void whenQueryWithAggregation_thenReturnCustomResult() { + List commentCountsByYear = commentRepository.countTotalCommentsByYearClass(); + + CommentCount countYear2019 = commentCountsByYear.get(0); + + assertThat(countYear2019.getYear(), is(Integer.valueOf(2019))); + assertThat(countYear2019.getTotal(), is(1l)); + + CommentCount countYear2018 = commentCountsByYear.get(1); + + assertThat(countYear2018.getYear(), is(Integer.valueOf(2018))); + assertThat(countYear2018.getTotal(), is(2l)); + + CommentCount countYear2017 = commentCountsByYear.get(2); + + assertThat(countYear2017.getYear(), is(Integer.valueOf(2017))); + assertThat(countYear2017.getTotal(), is(1l)); + } + + @Test + public void whenQueryWithAggregation_thenReturnInterfaceResult() { + List commentCountsByYear = commentRepository.countTotalCommentsByYearInterface(); + + ICommentCount countYear2019 = commentCountsByYear.get(0); + + assertThat(countYear2019.getYearComment(), is(Integer.valueOf(2019))); + assertThat(countYear2019.getTotalComment(), is(1l)); + + ICommentCount countYear2018 = commentCountsByYear.get(1); + + assertThat(countYear2018.getYearComment(), is(Integer.valueOf(2018))); + assertThat(countYear2018.getTotalComment(), is(2l)); + + ICommentCount countYear2017 = commentCountsByYear.get(2); + + assertThat(countYear2017.getYearComment(), is(Integer.valueOf(2017))); + assertThat(countYear2017.getTotalComment(), is(1l)); + } + + @Test + public void whenNativeQueryWithAggregation_thenReturnInterfaceResult() { + List commentCountsByYear = commentRepository.countTotalCommentsByYearNative(); + + ICommentCount countYear2019 = commentCountsByYear.get(0); + + assertThat(countYear2019.getYearComment(), is(Integer.valueOf(2019))); + assertThat(countYear2019.getTotalComment(), is(1l)); + + ICommentCount countYear2018 = commentCountsByYear.get(1); + + assertThat(countYear2018.getYearComment(), is(Integer.valueOf(2018))); + assertThat(countYear2018.getTotalComment(), is(2l)); + + ICommentCount countYear2017 = commentCountsByYear.get(2); + + assertThat(countYear2017.getYearComment(), is(Integer.valueOf(2017))); + assertThat(countYear2017.getTotalComment(), is(1l)); + } + +} diff --git a/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java new file mode 100644 index 0000000000..20fc3cbeaf --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java @@ -0,0 +1,67 @@ +package com.baeldung.boot.daos; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.domain.Article; + +@RunWith(SpringRunner.class) +@DataJpaTest(properties="spring.datasource.data=classpath:import_entities.sql") +public class ArticleRepositoryIntegrationTest { + + @Autowired + private ArticleRepository repository; + + @Test + public void givenImportedArticlesWhenFindAllByPublicationDateThenArticles1And2Returned() + throws Exception { + List
result = repository.findAllByPublicationDate( + new SimpleDateFormat("yyyy-MM-dd").parse("2018-01-01") + ); + + assertEquals(2, result.size()); + assertTrue(result.stream() + .map(Article::getId) + .allMatch(id -> Arrays.asList(1, 2).contains(id)) + ); + } + + @Test + public void givenImportedArticlesWhenFindAllByPublicationTimeBetweenThenArticles2And3Returned() + throws Exception { + List
result = repository.findAllByPublicationTimeBetween( + new SimpleDateFormat("HH:mm").parse("15:15"), + new SimpleDateFormat("HH:mm").parse("16:30") + ); + + assertEquals(2, result.size()); + assertTrue(result.stream() + .map(Article::getId) + .allMatch(id -> Arrays.asList(2, 3).contains(id)) + ); + } + + @Test + public void givenImportedArticlesWhenFindAllWithCreationDateTimeBeforeThenArticles2And3Returned() throws Exception { + List
result = repository.findAllWithCreationDateTimeBefore( + new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2017-12-15 10:00") + ); + + assertEquals(2, result.size()); + assertTrue(result.stream() + .map(Article::getId) + .allMatch(id -> Arrays.asList(2, 3).contains(id)) + ); + } + +} diff --git a/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java new file mode 100644 index 0000000000..f082350019 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java @@ -0,0 +1,190 @@ +package com.baeldung.boot.passenger; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.passenger.Passenger; +import com.baeldung.boot.passenger.PassengerRepository; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import java.util.List; +import java.util.Optional; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.core.IsNot.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +@DataJpaTest +@RunWith(SpringRunner.class) +public class PassengerRepositoryIntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + @Autowired + private PassengerRepository repository; + + @Before + public void before() { + entityManager.persist(Passenger.from("Jill", "Smith", 50)); + entityManager.persist(Passenger.from("Eve", "Jackson", 95)); + entityManager.persist(Passenger.from("Fred", "Bloggs", 22)); + entityManager.persist(Passenger.from("Ricki", "Bobbie", 36)); + entityManager.persist(Passenger.from("Siya", "Kolisi", 85)); + } + + @Test + public void givenSeveralPassengersWhenOrderedBySeatNumberLimitedToThenThePassengerInTheFirstFilledSeatIsReturned() { + Passenger expected = Passenger.from("Fred", "Bloggs", 22); + + List passengers = repository.findOrderedBySeatNumberLimitedTo(1); + + assertEquals(1, passengers.size()); + + Passenger actual = passengers.get(0); + assertEquals(expected, actual); + } + + @Test + public void givenSeveralPassengersWhenFindFirstByOrderBySeatNumberAscThenThePassengerInTheFirstFilledSeatIsReturned() { + Passenger expected = Passenger.from("Fred", "Bloggs", 22); + + Passenger actual = repository.findFirstByOrderBySeatNumberAsc(); + + assertEquals(expected, actual); + } + + @Test + public void givenSeveralPassengersWhenFindPageSortedByThenThePassengerInTheFirstFilledSeatIsReturned() { + Passenger expected = Passenger.from("Fred", "Bloggs", 22); + + Page page = repository.findAll(PageRequest.of(0, 1, + Sort.by(Sort.Direction.ASC, "seatNumber"))); + + assertEquals(1, page.getContent().size()); + + Passenger actual = page.getContent().get(0); + assertEquals(expected, actual); + } + + @Test + public void givenPassengers_whenOrderedBySeatNumberAsc_thenCorrectOrder() { + Passenger fred = Passenger.from("Fred", "Bloggs", 22); + Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); + Passenger jill = Passenger.from("Jill", "Smith", 50); + Passenger siya = Passenger.from("Siya", "Kolisi", 85); + Passenger eve = Passenger.from("Eve", "Jackson", 95); + + List passengers = repository.findByOrderBySeatNumberAsc(); + + assertThat(passengers, contains(fred, ricki, jill, siya, eve)); + } + + @Test + public void givenPassengers_whenFindAllWithSortBySeatNumberAsc_thenCorrectOrder() { + Passenger fred = Passenger.from("Fred", "Bloggs", 22); + Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); + Passenger jill = Passenger.from("Jill", "Smith", 50); + Passenger siya = Passenger.from("Siya", "Kolisi", 85); + Passenger eve = Passenger.from("Eve", "Jackson", 95); + + List passengers = repository.findAll(Sort.by(Sort.Direction.ASC, "seatNumber")); + + assertThat(passengers, contains(fred, ricki, jill, siya, eve)); + } + + @Test + public void givenPassengers_whenFindByExampleDefaultMatcher_thenExpectedReturned() { + Example example = Example.of(Passenger.from("Fred", "Bloggs", null)); + + Optional actual = repository.findOne(example); + + assertTrue(actual.isPresent()); + assertEquals(Passenger.from("Fred", "Bloggs", 22), actual.get()); + } + + @Test + public void givenPassengers_whenFindByExampleCaseInsensitiveMatcher_thenExpectedReturned() { + ExampleMatcher caseInsensitiveExampleMatcher = ExampleMatcher.matchingAll().withIgnoreCase(); + Example example = Example.of(Passenger.from("fred", "bloggs", null), + caseInsensitiveExampleMatcher); + + Optional actual = repository.findOne(example); + + assertTrue(actual.isPresent()); + assertEquals(Passenger.from("Fred", "Bloggs", 22), actual.get()); + } + + @Test + public void givenPassengers_whenFindByExampleCustomMatcher_thenExpectedReturned() { + Passenger jill = Passenger.from("Jill", "Smith", 50); + Passenger eve = Passenger.from("Eve", "Jackson", 95); + Passenger fred = Passenger.from("Fred", "Bloggs", 22); + Passenger siya = Passenger.from("Siya", "Kolisi", 85); + Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); + + ExampleMatcher customExampleMatcher = ExampleMatcher.matchingAny().withMatcher("firstName", + ExampleMatcher.GenericPropertyMatchers.contains().ignoreCase()).withMatcher("lastName", + ExampleMatcher.GenericPropertyMatchers.contains().ignoreCase()); + + Example example = Example.of(Passenger.from("e", "s", null), + customExampleMatcher); + + List passengers = repository.findAll(example); + + assertThat(passengers, contains(jill, eve, fred, siya)); + assertThat(passengers, not(contains(ricki))); + } + + @Test + public void givenPassengers_whenFindByIgnoringMatcher_thenExpectedReturned() { + Passenger jill = Passenger.from("Jill", "Smith", 50); + Passenger eve = Passenger.from("Eve", "Jackson", 95); + Passenger fred = Passenger.from("Fred", "Bloggs", 22); + Passenger siya = Passenger.from("Siya", "Kolisi", 85); + Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); + + ExampleMatcher ignoringExampleMatcher = ExampleMatcher.matchingAny().withMatcher("lastName", + ExampleMatcher.GenericPropertyMatchers.startsWith().ignoreCase()).withIgnorePaths("firstName", "seatNumber"); + + Example example = Example.of(Passenger.from(null, "b", null), + ignoringExampleMatcher); + + List passengers = repository.findAll(example); + + assertThat(passengers, contains(fred, ricki)); + assertThat(passengers, not(contains(jill))); + assertThat(passengers, not(contains(eve))); + assertThat(passengers, not(contains(siya))); + } + + @Test + public void givenPassengers_whenMatchingIgnoreCase_thenExpectedReturned() { + Passenger jill = Passenger.from("Jill", "Smith", 50); + Passenger eve = Passenger.from("Eve", "Jackson", 95); + Passenger fred = Passenger.from("Fred", "Bloggs", 22); + Passenger siya = Passenger.from("Siya", "Kolisi", 85); + Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); + + List passengers = repository.findByFirstNameIgnoreCase("FRED"); + + assertThat(passengers, contains(fred)); + assertThat(passengers, not(contains(eve))); + assertThat(passengers, not(contains(siya))); + assertThat(passengers, not(contains(jill))); + assertThat(passengers, not(contains(ricki))); + + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java new file mode 100644 index 0000000000..24880a5dff --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java @@ -0,0 +1,39 @@ +package com.baeldung.entitygraph; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.entitygraph.model.Characteristic; +import com.baeldung.entitygraph.model.Item; +import com.baeldung.entitygraph.repository.CharacteristicsRepository; +import com.baeldung.entitygraph.repository.ItemRepository; + +@DataJpaTest +@RunWith(SpringRunner.class) +@Sql(scripts = "/entitygraph-data.sql") +public class EntityGraphIntegrationTest { + + @Autowired + private ItemRepository itemRepo; + + @Autowired + private CharacteristicsRepository characteristicsRepo; + + @Test + public void givenEntityGraph_whenCalled_shouldRetrunDefinedFields() { + Item item = itemRepo.findByName("Table"); + assertThat(item.getId()).isEqualTo(1L); + } + + @Test + public void givenAdhocEntityGraph_whenCalled_shouldRetrunDefinedFields() { + Characteristic characteristic = characteristicsRepo.findByType("Rigid"); + assertThat(characteristic.getId()).isEqualTo(1L); + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java new file mode 100644 index 0000000000..d99f6671a3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java @@ -0,0 +1,87 @@ +package com.baeldung.exists; + +import com.baeldung.Application; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Arrays; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.ignoreCase; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Application.class}) +public class CarRepositoryIntegrationTest { + + @Autowired + private CarRepository repository; + private int searchId; + + @Before + public void setup() { + List cars = repository.saveAll(Arrays.asList(new Car(200, "BMW"), new Car(300, "Audi"))); + searchId = cars.get(0).getId(); + } + + @After + public void teardown() { + repository.deleteAll(); + } + + @Test + public void whenIdIsCorrect_thenExistsShouldReturnTrue() { + assertThat(repository.existsById(searchId)).isTrue(); + } + + @Test + public void givenExample_whenExists_thenIsTrue() { + ExampleMatcher modelMatcher = ExampleMatcher.matching() + .withIgnorePaths("id") // must explicitly ignore -> PK + .withMatcher("model", ignoreCase()); + Car probe = new Car(); + probe.setModel("bmw"); + + Example example = Example.of(probe, modelMatcher); + + assertThat(repository.exists(example)).isTrue(); + } + + @Test + public void givenPower_whenExists_thenIsFalse() { + assertThat(repository.existsCarByPower(200)).isTrue(); + assertThat(repository.existsCarByPower(800)).isFalse(); + } + + @Test + public void existsByDerivedQuery_byModel() { + assertThat(repository.existsCarByModel("Audi")).isTrue(); + assertThat(repository.existsCarByModel("audi")).isFalse(); + assertThat(repository.existsCarByModel("AUDI")).isFalse(); + assertThat(repository.existsCarByModel("")).isFalse(); + } + + @Test + public void givenModelName_whenExistsExact_thenIsTrue() { + assertThat(repository.existsCarExactCustomQuery("BMW")).isTrue(); + assertThat(repository.existsCarExactCustomQuery("Bmw")).isFalse(); + assertThat(repository.existsCarExactCustomQuery("bmw")).isFalse(); + assertThat(repository.existsCarExactCustomQuery("")).isFalse(); + } + + @Test + public void givenModelName_whenExistsLike_thenIsTrue() { + assertThat(repository.existsCarLikeCustomQuery("BMW")).isTrue(); + assertThat(repository.existsCarLikeCustomQuery("Bmw")).isTrue(); + assertThat(repository.existsCarLikeCustomQuery("bmw")).isTrue(); + assertThat(repository.existsCarLikeCustomQuery("")).isFalse(); + } + +} diff --git a/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java new file mode 100644 index 0000000000..9b0d23f3e4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java @@ -0,0 +1,142 @@ +package com.baeldung.joins; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.baeldung.joins.model.Department; +import com.baeldung.joins.model.Phone; +import java.util.Collection; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@DataJpaTest +@ActiveProfiles("joins") +public class JpaJoinsIntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + @Test + public void whenPathExpressionIsUsedForSingleValuedAssociation_thenCreatesImplicitInnerJoin() { + TypedQuery query = entityManager.createQuery("SELECT e.department FROM Employee e", Department.class); + + List resultList = query.getResultList(); + + assertThat(resultList).hasSize(3); + assertThat(resultList).extracting("name") + .containsOnly("Infra", "Accounting", "Accounting"); + } + + @Test + public void whenJoinKeywordIsUsed_thenCreatesExplicitInnerJoin() { + TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e JOIN e.department d", Department.class); + + List resultList = query.getResultList(); + + assertThat(resultList).hasSize(3); + assertThat(resultList).extracting("name") + .containsOnly("Infra", "Accounting", "Accounting"); + } + + @Test + public void whenInnerJoinKeywordIsUsed_thenCreatesExplicitInnerJoin() { + TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e INNER JOIN e.department d", Department.class); + + List resultList = query.getResultList(); + + assertThat(resultList).hasSize(3); + assertThat(resultList).extracting("name") + .containsOnly("Infra", "Accounting", "Accounting"); + } + + @Test + public void whenEntitiesAreListedInFromAndMatchedInWhere_ThenCreatesJoin() { + TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e, Department d WHERE e.department = d", Department.class); + + List resultList = query.getResultList(); + + assertThat(resultList).hasSize(3); + assertThat(resultList).extracting("name") + .containsOnly("Infra", "Accounting", "Accounting"); + } + + @Test + public void whenEntitiesAreListedInFrom_ThenCreatesCartesianProduct() { + TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e, Department d", Department.class); + + List resultList = query.getResultList(); + + assertThat(resultList).hasSize(9); + assertThat(resultList).extracting("name") + .containsOnly("Infra", "Accounting", "Management", "Infra", "Accounting", "Management", "Infra", "Accounting", "Management"); + } + + @Test + public void whenCollectionValuedAssociationIsJoined_ThenCanSelect() { + TypedQuery query = entityManager.createQuery("SELECT ph FROM Employee e JOIN e.phones ph WHERE ph LIKE '1%'", Phone.class); + + List resultList = query.getResultList(); + + assertThat(resultList).hasSize(1); + } + + @Test + public void whenMultipleEntitiesAreListedWithJoin_ThenCreatesMultipleJoins() { + TypedQuery query = entityManager.createQuery("SELECT ph FROM Employee e JOIN e.department d JOIN e.phones ph WHERE d.name IS NOT NULL", Phone.class); + + List resultList = query.getResultList(); + + assertThat(resultList).hasSize(3); + assertThat(resultList).extracting("number") + .containsOnly("111", "222", "333"); + } + + @Test + public void whenLeftKeywordIsSpecified_thenCreatesOuterJoinAndIncludesNonMatched() { + TypedQuery query = entityManager.createQuery("SELECT DISTINCT d FROM Department d LEFT JOIN d.employees e", Department.class); + + List resultList = query.getResultList(); + + assertThat(resultList).hasSize(3); + assertThat(resultList).extracting("name") + .containsOnly("Infra", "Accounting", "Management"); + } + + @Test + public void whenFetchKeywordIsSpecified_ThenCreatesFetchJoin() { + TypedQuery query = entityManager.createQuery("SELECT d FROM Department d JOIN FETCH d.employees", Department.class); + + List resultList = query.getResultList(); + + assertThat(resultList).hasSize(3); + assertThat(resultList).extracting("name") + .containsOnly("Infra", "Accounting", "Accounting"); + } + + @Test + public void whenLeftAndFetchKeywordsAreSpecified_ThenCreatesOuterFetchJoin() { + TypedQuery query = entityManager.createQuery("SELECT d FROM Department d LEFT JOIN FETCH d.employees", Department.class); + + List resultList = query.getResultList(); + + assertThat(resultList).hasSize(4); + assertThat(resultList).extracting("name") + .containsOnly("Infra", "Accounting", "Accounting", "Management"); + } + + @Test + public void whenCollectionValuedAssociationIsSpecifiedInSelect_ThenReturnsCollections() { + TypedQuery query = entityManager.createQuery("SELECT e.phones FROM Employee e", Collection.class); + + List resultList = query.getResultList(); + + assertThat(resultList).extracting("number").containsOnly("111", "222", "333"); + } +} diff --git a/persistence-modules/spring-data-jpa-query/src/test/resources/entitygraph-data.sql b/persistence-modules/spring-data-jpa-query/src/test/resources/entitygraph-data.sql new file mode 100644 index 0000000000..685ec2c605 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/resources/entitygraph-data.sql @@ -0,0 +1,7 @@ +INSERT INTO Item(id,name) VALUES (1,'Table'); +INSERT INTO Item(id,name) VALUES (2,'Bottle'); + +INSERT INTO Characteristic(id,item_id, type) VALUES (1,1,'Rigid'); +INSERT INTO Characteristic(id,item_id,type) VALUES (2,1,'Big'); +INSERT INTO Characteristic(id,item_id,type) VALUES (3,2,'Fragile'); +INSERT INTO Characteristic(id,item_id,type) VALUES (4,2,'Small'); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query/src/test/resources/projection-clean-up-data.sql b/persistence-modules/spring-data-jpa-query/src/test/resources/projection-clean-up-data.sql new file mode 100644 index 0000000000..d34f6f0636 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/resources/projection-clean-up-data.sql @@ -0,0 +1,2 @@ +DELETE FROM address; +DELETE FROM person; \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query/src/test/resources/projection-insert-data.sql b/persistence-modules/spring-data-jpa-query/src/test/resources/projection-insert-data.sql new file mode 100644 index 0000000000..544dcc4b88 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/resources/projection-insert-data.sql @@ -0,0 +1,2 @@ +INSERT INTO person(id,first_name,last_name) VALUES (1,'John','Doe'); +INSERT INTO address(id,person_id,state,city,street,zip_code) VALUES (1,1,'CA', 'Los Angeles', 'Standford Ave', '90001'); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query/src/test/resources/test-aggregation-data.sql b/persistence-modules/spring-data-jpa-query/src/test/resources/test-aggregation-data.sql new file mode 100644 index 0000000000..12409a124e --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/resources/test-aggregation-data.sql @@ -0,0 +1,7 @@ +INSERT INTO post (id, title, content) VALUES (1, 'Comment 1', 'Content 1'); +INSERT INTO post (id, title, content) VALUES (2, 'Comment 2', 'Content 2'); +INSERT INTO post (id, title, content) VALUES (3, 'Comment 3', 'Content 3'); +INSERT INTO comment (id, year, approved, content, post_id) VALUES (1, 2019, false, 'Comment 1', 1); +INSERT INTO comment (id, year, approved, content, post_id) VALUES (2, 2018, true, 'Comment 2', 1); +INSERT INTO comment (id, year, approved, content, post_id) VALUES (3, 2018, true, 'Comment 3', 2); +INSERT INTO comment (id, year, approved, content, post_id) VALUES (4, 2017, false, 'Comment 4', 3); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query/src/test/resources/test-fruit-data.sql b/persistence-modules/spring-data-jpa-query/src/test/resources/test-fruit-data.sql new file mode 100644 index 0000000000..d99f42e5a7 --- /dev/null +++ b/persistence-modules/spring-data-jpa-query/src/test/resources/test-fruit-data.sql @@ -0,0 +1,6 @@ +truncate table fruit; + +insert into fruit(id,name,color) values (1,'apple','red'); +insert into fruit(id,name,color) values (2,'custard apple','green'); +insert into fruit(id,name,color) values (3,'mango','yellow'); +insert into fruit(id,name,color) values (4,'guava','green'); \ No newline at end of file From 733d901d46437653a81771f4023620b507ea011d Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 19 Jul 2020 14:31:28 +0530 Subject: [PATCH 076/309] JAVA-66: New module spring-data-jpa-repo --- .../spring-data-jpa-repo/README.md | 22 +++ .../spring-data-jpa-repo/pom.xml | 52 ++++++ .../main/java/com/baeldung/Application.java | 17 ++ .../boot/daos/CustomItemRepository.java | 16 ++ .../boot/daos/CustomItemTypeRepository.java | 13 ++ .../boot/daos/ExtendedRepository.java | 14 ++ .../boot/daos/ExtendedStudentRepository.java | 6 + .../boot/daos/InventoryRepository.java | 8 + .../boot/daos/ItemTypeRepository.java | 10 + .../boot/daos/LocationRepository.java | 10 + .../boot/daos/ReadOnlyLocationRepository.java | 15 ++ .../baeldung/boot/daos/StoreRepository.java | 13 ++ .../daos/impl/CustomItemRepositoryImpl.java | 33 ++++ .../impl/CustomItemTypeRepositoryImpl.java | 27 +++ .../daos/impl/ExtendedRepositoryImpl.java | 37 ++++ .../java/com/baeldung/boot/domain/Item.java | 81 +++++++++ .../com/baeldung/boot/domain/ItemType.java | 46 +++++ .../java/com/baeldung/boot/domain/KVTag.java | 34 ++++ .../com/baeldung/boot/domain/Location.java | 55 ++++++ .../boot/domain/MerchandiseEntity.java | 66 +++++++ .../com/baeldung/boot/domain/SkillTag.java | 30 +++ .../java/com/baeldung/boot/domain/Store.java | 76 ++++++++ .../com/baeldung/boot/domain/Student.java | 74 ++++++++ .../com/baeldung/config/JpaPopulators.java | 35 ++++ .../derivedquery/QueryApplication.java | 13 ++ .../baeldung/derivedquery/entity/User.java | 70 +++++++ .../repository/UserRepository.java | 60 ++++++ .../main/java/com/baeldung/entity/Fruit.java | 40 ++++ .../java/com/baeldung/entity/Passenger.java | 78 ++++++++ .../main/java/com/baeldung/entity/Song.java | 75 ++++++++ .../com/baeldung/like/LikeApplication.java | 13 ++ .../java/com/baeldung/like/model/Movie.java | 58 ++++++ .../like/repository/MovieRepository.java | 41 +++++ .../baeldung/repository/FruitRepository.java | 27 +++ .../repository/PassengerRepository.java | 14 ++ .../baeldung/repository/SongRepository.java | 22 +++ .../StoredProcedureApplication.java | 13 ++ .../controller/CarController.java | 47 +++++ .../baeldung/storedprocedure/entity/Car.java | 41 +++++ .../repository/CarRepository.java | 34 ++++ .../storedprocedure/service/CarService.java | 39 ++++ .../src/main/resources/apple-fruit-data.xml | 7 + .../src/main/resources/application.properties | 5 + .../src/main/resources/car-mysql.sql | 27 +++ .../src/main/resources/fruit-data.json | 14 ++ .../src/main/resources/guava-fruit-data.xml | 7 + .../src/main/resources/import_entities.sql | 17 ++ ...endedStudentRepositoryIntegrationTest.java | 41 +++++ .../InventoryRepositoryIntegrationTest.java | 61 +++++++ .../daos/JpaRepositoriesIntegrationTest.java | 93 ++++++++++ .../UserRepositoryIntegrationTest.java | 172 ++++++++++++++++++ .../like/MovieRepositoryIntegrationTest.java | 87 +++++++++ .../FruitPopulatorIntegrationTest.java | 38 ++++ .../PassengerRepositoryIntegrationTest.java | 56 ++++++ .../SongRepositoryIntegrationTest.java | 59 ++++++ .../resources/application-test.properties | 2 + .../src/test/resources/test-movie-cleanup.sql | 1 + .../src/test/resources/test-movie-data.sql | 7 + .../src/test/resources/test-song-data.sql | 8 + 59 files changed, 2177 insertions(+) create mode 100644 persistence-modules/spring-data-jpa-repo/README.md create mode 100644 persistence-modules/spring-data-jpa-repo/pom.xml create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/Application.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/InventoryRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/LocationRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/StoreRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Item.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/ItemType.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/KVTag.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Location.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/SkillTag.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Store.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Student.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/config/JpaPopulators.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/QueryApplication.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/entity/User.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/repository/UserRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Fruit.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Passenger.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Song.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/LikeApplication.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/model/Movie.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/repository/MovieRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/FruitRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/PassengerRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/SongRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/StoredProcedureApplication.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/controller/CarController.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/entity/Car.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/repository/CarRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/service/CarService.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/resources/apple-fruit-data.xml create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/resources/application.properties create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/resources/car-mysql.sql create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/resources/fruit-data.json create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/resources/guava-fruit-data.xml create mode 100644 persistence-modules/spring-data-jpa-repo/src/main/resources/import_entities.sql create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/FruitPopulatorIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/SongRepositoryIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/resources/application-test.properties create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-cleanup.sql create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-data.sql create mode 100644 persistence-modules/spring-data-jpa-repo/src/test/resources/test-song-data.sql diff --git a/persistence-modules/spring-data-jpa-repo/README.md b/persistence-modules/spring-data-jpa-repo/README.md new file mode 100644 index 0000000000..284a7ac2b5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/README.md @@ -0,0 +1,22 @@ +## Spring Data JPA - Repo + +This module contains articles about repositories in Spring Data JPA + +### Relevant Articles: +- [Case Insensitive Queries with Spring Data Repository](https://www.baeldung.com/spring-data-case-insensitive-queries) +- [Derived Query Methods in Spring Data JPA Repositories](https://www.baeldung.com/spring-data-derived-queries) +- [LIKE Queries in Spring JPA Repositories](https://www.baeldung.com/spring-jpa-like-queries) +- [Spring Data – CrudRepository save() Method](https://www.baeldung.com/spring-data-crud-repository-save) +- [Spring Data JPA – Adding a Method in All Repositories](https://www.baeldung.com/spring-data-jpa-method-in-all-repositories) +- [Spring Data Composable Repositories](https://www.baeldung.com/spring-data-composable-repositories) +- [Spring Data JPA Repository Populators](https://www.baeldung.com/spring-data-jpa-repository-populators) +- [Calling Stored Procedures from Spring Data JPA Repositories](https://www.baeldung.com/spring-data-jpa-stored-procedures) + +### Eclipse Config +After importing the project into Eclipse, you may see the following error: +"No persistence xml file found in project" + +This can be ignored: +- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" +Or: +- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator diff --git a/persistence-modules/spring-data-jpa-repo/pom.xml b/persistence-modules/spring-data-jpa-repo/pom.xml new file mode 100644 index 0000000000..984bc1bdff --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + spring-data-jpa-repo + spring-data-jpa-repo + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + + mysql + mysql-connector-java + + + + org.postgresql + postgresql + + + + com.h2database + h2 + + + + org.springframework + spring-oxm + + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..47a18b557f --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/Application.java @@ -0,0 +1,17 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +import com.baeldung.boot.daos.impl.ExtendedRepositoryImpl; + +@SpringBootApplication +@EnableJpaRepositories(repositoryBaseClass = ExtendedRepositoryImpl.class) +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java new file mode 100644 index 0000000000..0aebe34921 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java @@ -0,0 +1,16 @@ +package com.baeldung.boot.daos; + +import org.springframework.stereotype.Repository; + +import com.baeldung.boot.domain.Item; + +@Repository +public interface CustomItemRepository { + + void deleteCustom(Item entity); + + Item findItemById(Long id); + + void findThenDelete(Long id); + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java new file mode 100644 index 0000000000..832d61408c --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java @@ -0,0 +1,13 @@ +package com.baeldung.boot.daos; + +import org.springframework.stereotype.Repository; + +import com.baeldung.boot.domain.ItemType; + +@Repository +public interface CustomItemTypeRepository { + + void deleteCustom(ItemType entity); + + void findThenDelete(Long id); +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java new file mode 100644 index 0000000000..adb2af4320 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java @@ -0,0 +1,14 @@ +package com.baeldung.boot.daos; + +import java.io.Serializable; +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.NoRepositoryBean; + +@NoRepositoryBean +public interface ExtendedRepository extends JpaRepository { + + List findByAttributeContainsText(String attributeName, String text); + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java new file mode 100644 index 0000000000..c9b0192536 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java @@ -0,0 +1,6 @@ +package com.baeldung.boot.daos; + +import com.baeldung.boot.domain.Student; + +public interface ExtendedStudentRepository extends ExtendedRepository { +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/InventoryRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/InventoryRepository.java new file mode 100644 index 0000000000..606f3993d5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/InventoryRepository.java @@ -0,0 +1,8 @@ +package com.baeldung.boot.daos; + +import org.springframework.data.repository.CrudRepository; + +import com.baeldung.boot.domain.MerchandiseEntity; + +public interface InventoryRepository extends CrudRepository { +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java new file mode 100644 index 0000000000..413c09e968 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java @@ -0,0 +1,10 @@ +package com.baeldung.boot.daos; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.boot.domain.ItemType; + +@Repository +public interface ItemTypeRepository extends JpaRepository, CustomItemTypeRepository, CustomItemRepository { +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/LocationRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/LocationRepository.java new file mode 100644 index 0000000000..697ce295d0 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/LocationRepository.java @@ -0,0 +1,10 @@ +package com.baeldung.boot.daos; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.boot.domain.Location; + +@Repository +public interface LocationRepository extends JpaRepository { +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java new file mode 100644 index 0000000000..3a2ea3cda5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java @@ -0,0 +1,15 @@ +package com.baeldung.boot.daos; + +import java.util.Optional; + +import org.springframework.data.repository.Repository; + +import com.baeldung.boot.domain.Location; + +@org.springframework.stereotype.Repository +public interface ReadOnlyLocationRepository extends Repository { + + Optional findById(Long id); + + Location save(Location location); +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/StoreRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/StoreRepository.java new file mode 100644 index 0000000000..ae13f75f66 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/StoreRepository.java @@ -0,0 +1,13 @@ +package com.baeldung.boot.daos; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.boot.domain.Store; + +@Repository +public interface StoreRepository extends JpaRepository { + List findStoreByLocationId(Long locationId); +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java new file mode 100644 index 0000000000..820a2cdd41 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java @@ -0,0 +1,33 @@ +package com.baeldung.boot.daos.impl; + +import javax.persistence.EntityManager; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import com.baeldung.boot.daos.CustomItemRepository; +import com.baeldung.boot.domain.Item; + +@Repository +public class CustomItemRepositoryImpl implements CustomItemRepository { + + @Autowired + private EntityManager entityManager; + + @Override + public void deleteCustom(Item item) { + entityManager.remove(item); + } + + @Override + public Item findItemById(Long id) { + return entityManager.find(Item.class, id); + } + + @Override + public void findThenDelete(Long id) { + final Item item = entityManager.find(Item.class, id); + entityManager.remove(item); + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java new file mode 100644 index 0000000000..e057f36b26 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java @@ -0,0 +1,27 @@ +package com.baeldung.boot.daos.impl; + +import javax.persistence.EntityManager; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + +import com.baeldung.boot.daos.CustomItemTypeRepository; +import com.baeldung.boot.domain.ItemType; + +@Repository +public class CustomItemTypeRepositoryImpl implements CustomItemTypeRepository { + + @Autowired + private EntityManager entityManager; + + @Override + public void deleteCustom(ItemType itemType) { + entityManager.remove(itemType); + } + + @Override + public void findThenDelete(Long id) { + ItemType itemTypeToDelete = entityManager.find(ItemType.class, id); + entityManager.remove(itemTypeToDelete); + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java new file mode 100644 index 0000000000..fbe6695844 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java @@ -0,0 +1,37 @@ +package com.baeldung.boot.daos.impl; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import javax.transaction.Transactional; + +import org.springframework.data.jpa.repository.support.JpaEntityInformation; +import org.springframework.data.jpa.repository.support.SimpleJpaRepository; + +import com.baeldung.boot.daos.ExtendedRepository; + +public class ExtendedRepositoryImpl extends SimpleJpaRepository implements ExtendedRepository { + + private EntityManager entityManager; + + public ExtendedRepositoryImpl(JpaEntityInformation entityInformation, EntityManager entityManager) { + super(entityInformation, entityManager); + this.entityManager = entityManager; + } + + @Transactional + public List findByAttributeContainsText(String attributeName, String text) { + CriteriaBuilder builder = entityManager.getCriteriaBuilder(); + CriteriaQuery query = builder.createQuery(getDomainClass()); + Root root = query.from(getDomainClass()); + query.select(root).where(builder.like(root. get(attributeName), "%" + text + "%")); + TypedQuery q = entityManager.createQuery(query); + return q.getResultList(); + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Item.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Item.java new file mode 100644 index 0000000000..8ac06af15a --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Item.java @@ -0,0 +1,81 @@ +package com.baeldung.boot.domain; + +import java.math.BigDecimal; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class Item { + + private String color; + private String grade; + + @Id + private Long id; + + @ManyToOne + private ItemType itemType; + + private String name; + private BigDecimal price; + @ManyToOne + private Store store; + + public String getColor() { + return color; + } + + public String getGrade() { + return grade; + } + + public Long getId() { + return id; + } + + public ItemType getItemType() { + return itemType; + } + + public String getName() { + return name; + } + + public BigDecimal getPrice() { + return price; + } + + public Store getStore() { + return store; + } + + public void setColor(String color) { + this.color = color; + } + + public void setGrade(String grade) { + this.grade = grade; + } + + public void setId(Long id) { + this.id = id; + } + + public void setItemType(ItemType itemType) { + this.itemType = itemType; + } + + public void setName(String name) { + this.name = name; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public void setStore(Store store) { + this.store = store; + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/ItemType.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/ItemType.java new file mode 100644 index 0000000000..8a52a9847c --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/ItemType.java @@ -0,0 +1,46 @@ +package com.baeldung.boot.domain; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; + +@Entity +public class ItemType { + + @Id + private Long id; + @OneToMany(cascade = CascadeType.ALL) + @JoinColumn(name = "ITEM_TYPE_ID") + private List items = new ArrayList<>(); + + private String name; + + public Long getId() { + return id; + } + + public List getItems() { + return items; + } + + public String getName() { + return name; + } + + public void setId(Long id) { + this.id = id; + } + + public void setItems(List items) { + this.items = items; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/KVTag.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/KVTag.java new file mode 100644 index 0000000000..1901f43c0a --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/KVTag.java @@ -0,0 +1,34 @@ +package com.baeldung.boot.domain; + +import javax.persistence.Embeddable; + +@Embeddable +public class KVTag { + private String key; + private String value; + + public KVTag() { + } + + public KVTag(String key, String value) { + super(); + this.key = key; + this.value = value; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Location.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Location.java new file mode 100644 index 0000000000..9c1b93d551 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Location.java @@ -0,0 +1,55 @@ +package com.baeldung.boot.domain; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; + +@Entity +public class Location { + + private String city; + private String country; + @Id + private Long id; + + @OneToMany(cascade = CascadeType.ALL) + @JoinColumn(name = "LOCATION_ID") + private List stores = new ArrayList<>(); + + public String getCity() { + return city; + } + + public String getCountry() { + return country; + } + + public Long getId() { + return id; + } + + public List getStores() { + return stores; + } + + public void setCity(String city) { + this.city = city; + } + + public void setCountry(String country) { + this.country = country; + } + + public void setId(Long id) { + this.id = id; + } + + public void setStores(List stores) { + this.stores = stores; + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java new file mode 100644 index 0000000000..e94c23de86 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java @@ -0,0 +1,66 @@ +package com.baeldung.boot.domain; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.math.BigDecimal; + +@Entity +public class MerchandiseEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String title; + + private BigDecimal price; + + private String brand; + + public MerchandiseEntity() { + } + + public MerchandiseEntity(String title, BigDecimal price) { + this.title = title; + this.price = price; + } + + public Long getId() { + return id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + @Override + public String toString() { + return "MerchandiseEntity{" + + "id=" + id + + ", title='" + title + '\'' + + ", price=" + price + + ", brand='" + brand + '\'' + + '}'; + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/SkillTag.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/SkillTag.java new file mode 100644 index 0000000000..0933a3e6af --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/SkillTag.java @@ -0,0 +1,30 @@ +package com.baeldung.boot.domain; + +import javax.persistence.Embeddable; + +@Embeddable +public class SkillTag { + private String name; + private int value; + + public SkillTag() { + } + + public SkillTag(String name, int value) { + super(); + this.name = name; + this.value = value; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public String getName() { + return name; + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Store.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Store.java new file mode 100644 index 0000000000..5b4b831cc7 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Store.java @@ -0,0 +1,76 @@ +package com.baeldung.boot.domain; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; + +@Entity +public class Store { + + private Boolean active; + @Id + private Long id; + @OneToMany(cascade = CascadeType.ALL) + @JoinColumn(name = "STORE_ID") + private List items = new ArrayList<>(); + private Long itemsSold; + + @ManyToOne + private Location location; + + private String name; + + public Boolean getActive() { + return active; + } + + public Long getId() { + return id; + } + + public List getItems() { + return items; + } + + public Long getItemsSold() { + return itemsSold; + } + + public Location getLocation() { + return location; + } + + public String getName() { + return name; + } + + public void setActive(Boolean active) { + this.active = active; + } + + public void setId(Long id) { + this.id = id; + } + + public void setItems(List items) { + this.items = items; + } + + public void setItemsSold(Long itemsSold) { + this.itemsSold = itemsSold; + } + + public void setLocation(Location location) { + this.location = location; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Student.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Student.java new file mode 100644 index 0000000000..1003167cc7 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/boot/domain/Student.java @@ -0,0 +1,74 @@ +package com.baeldung.boot.domain; + +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.Id; +import java.util.ArrayList; +import java.util.List; + +@Entity +public class Student { + + @Id + private long id; + private String name; + + @ElementCollection + private List tags = new ArrayList<>(); + + @ElementCollection + private List skillTags = new ArrayList<>(); + + @ElementCollection + private List kvTags = new ArrayList<>(); + + public Student() { + } + + public Student(long id, String name) { + super(); + this.id = id; + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags.addAll(tags); + } + + public List getSkillTags() { + return skillTags; + } + + public void setSkillTags(List skillTags) { + this.skillTags.addAll(skillTags); + } + + public List getKVTags() { + return this.kvTags; + } + + public void setKVTags(List kvTags) { + this.kvTags.addAll(kvTags); + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/config/JpaPopulators.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/config/JpaPopulators.java new file mode 100644 index 0000000000..24348d31c5 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/config/JpaPopulators.java @@ -0,0 +1,35 @@ +package com.baeldung.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.data.repository.init.Jackson2RepositoryPopulatorFactoryBean; +import org.springframework.data.repository.init.UnmarshallerRepositoryPopulatorFactoryBean; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; + +import com.baeldung.entity.Fruit; + +@Configuration +public class JpaPopulators { + + @Bean + public Jackson2RepositoryPopulatorFactoryBean getRespositoryPopulator() throws Exception { + Jackson2RepositoryPopulatorFactoryBean factory = new Jackson2RepositoryPopulatorFactoryBean(); + factory.setResources(new Resource[] { new ClassPathResource("fruit-data.json") }); + return factory; + } + + @Bean + public UnmarshallerRepositoryPopulatorFactoryBean repositoryPopulator() { + + Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller(); + unmarshaller.setClassesToBeBound(Fruit.class); + + UnmarshallerRepositoryPopulatorFactoryBean factory = new UnmarshallerRepositoryPopulatorFactoryBean(); + factory.setUnmarshaller(unmarshaller); + factory.setResources(new Resource[] { new ClassPathResource("apple-fruit-data.xml"), new ClassPathResource("guava-fruit-data.xml") }); + return factory; + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/QueryApplication.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/QueryApplication.java new file mode 100644 index 0000000000..d7a1950305 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/QueryApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.derivedquery; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class QueryApplication { + + public static void main(String[] args) { + SpringApplication.run(QueryApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/entity/User.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/entity/User.java new file mode 100644 index 0000000000..49e824f09f --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/entity/User.java @@ -0,0 +1,70 @@ +package com.baeldung.derivedquery.entity; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import java.time.ZonedDateTime; + +@Table(name = "users") +@Entity +public class User { + + @Id + @GeneratedValue + private Integer id; + private String name; + private Integer age; + private ZonedDateTime birthDate; + private Boolean active; + + public User() { + } + + public User(String name, Integer age, ZonedDateTime birthDate, Boolean active) { + this.name = name; + this.age = age; + this.birthDate = birthDate; + this.active = active; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public ZonedDateTime getBirthDate() { + return birthDate; + } + + public void setBirthDate(ZonedDateTime birthDate) { + this.birthDate = birthDate; + } + + public Boolean getActive() { + return active; + } + + public void setActive(Boolean active) { + this.active = active; + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/repository/UserRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/repository/UserRepository.java new file mode 100644 index 0000000000..e613ee1531 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/derivedquery/repository/UserRepository.java @@ -0,0 +1,60 @@ +package com.baeldung.derivedquery.repository; + +import com.baeldung.derivedquery.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.time.ZonedDateTime; +import java.util.Collection; +import java.util.List; + +public interface UserRepository extends JpaRepository { + + List findByName(String name); + + List findByNameIs(String name); + + List findByNameEquals(String name); + + List findByNameIsNull(); + + List findByNameNot(String name); + + List findByNameIsNot(String name); + + List findByNameStartingWith(String name); + + List findByNameEndingWith(String name); + + List findByNameContaining(String name); + + List findByNameLike(String name); + + List findByAgeLessThan(Integer age); + + List findByAgeLessThanEqual(Integer age); + + List findByAgeGreaterThan(Integer age); + + List findByAgeGreaterThanEqual(Integer age); + + List findByAgeBetween(Integer startAge, Integer endAge); + + List findByBirthDateAfter(ZonedDateTime birthDate); + + List findByBirthDateBefore(ZonedDateTime birthDate); + + List findByActiveTrue(); + + List findByActiveFalse(); + + List findByAgeIn(Collection ages); + + List findByNameOrBirthDate(String name, ZonedDateTime birthDate); + + List findByNameOrBirthDateAndActive(String name, ZonedDateTime birthDate, Boolean active); + + List findByNameOrderByName(String name); + + List findByNameOrderByNameDesc(String name); + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Fruit.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Fruit.java new file mode 100644 index 0000000000..d45ac33db8 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Fruit.java @@ -0,0 +1,40 @@ +package com.baeldung.entity; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@Entity +public class Fruit { + + @Id + private long id; + private String name; + private String color; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Passenger.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Passenger.java new file mode 100644 index 0000000000..3aafbe9afa --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Passenger.java @@ -0,0 +1,78 @@ +package com.baeldung.entity; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import java.util.Objects; + +@Entity +public class Passenger { + + @Id + @GeneratedValue + @Column(nullable = false) + private Long id; + + @Basic(optional = false) + @Column(nullable = false) + private String firstName; + + @Basic(optional = false) + @Column(nullable = false) + private String lastName; + + private Passenger(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public static Passenger from(String firstName, String lastName) { + return new Passenger(firstName, lastName); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public String toString() { + return "Passenger{" + "id=" + id + ", firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Passenger passenger = (Passenger) o; + return Objects.equals(firstName, passenger.firstName) && Objects.equals(lastName, passenger.lastName); + } + + @Override + public int hashCode() { + return Objects.hash(firstName, lastName); + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Song.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Song.java new file mode 100644 index 0000000000..395527c1eb --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/entity/Song.java @@ -0,0 +1,75 @@ +package com.baeldung.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import java.time.LocalDateTime; + +@Entity +public class Song { + + @Id private long id; + private String name; + @Column(name = "length_in_seconds") + private int lengthInSeconds; + private String compositor; + private String singer; + private LocalDateTime released; + private String genre; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getLengthInSeconds() { + return lengthInSeconds; + } + + public void setLengthInSeconds(int lengthInSeconds) { + this.lengthInSeconds = lengthInSeconds; + } + + public String getCompositor() { + return compositor; + } + + public void setCompositor(String compositor) { + this.compositor = compositor; + } + + public String getSinger() { + return singer; + } + + public void setSinger(String singer) { + this.singer = singer; + } + + public LocalDateTime getReleased() { + return released; + } + + public void setReleased(LocalDateTime released) { + this.released = released; + } + + public String getGenre() { + return genre; + } + + public void setGenre(String genre) { + this.genre = genre; + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/LikeApplication.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/LikeApplication.java new file mode 100644 index 0000000000..311aea3001 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/LikeApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.like; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class LikeApplication { + + public static void main(String[] args) { + SpringApplication.run(LikeApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/model/Movie.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/model/Movie.java new file mode 100644 index 0000000000..bba8bd35c4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/model/Movie.java @@ -0,0 +1,58 @@ +package com.baeldung.like.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Movie { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private Long id; + private String title; + private String director; + private String rating; + private int duration; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDirector() { + return director; + } + + public void setDirector(String director) { + this.director = director; + } + + public String getRating() { + return rating; + } + + public void setRating(String rating) { + this.rating = rating; + } + + public int getDuration() { + return duration; + } + + public void setDuration(int duration) { + this.duration = duration; + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/repository/MovieRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/repository/MovieRepository.java new file mode 100644 index 0000000000..241bdd3306 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/like/repository/MovieRepository.java @@ -0,0 +1,41 @@ +package com.baeldung.like.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; + +import com.baeldung.like.model.Movie; + +public interface MovieRepository extends CrudRepository { + + List findByTitleContaining(String title); + + List findByTitleLike(String title); + + List findByTitleContains(String title); + + List findByTitleIsContaining(String title); + + List findByRatingStartsWith(String rating); + + List findByDirectorEndsWith(String director); + + List findByTitleContainingIgnoreCase(String title); + + List findByRatingNotContaining(String rating); + + List findByDirectorNotLike(String director); + + @Query("SELECT m FROM Movie m WHERE m.title LIKE %:title%") + List searchByTitleLike(@Param("title") String title); + + @Query("SELECT m FROM Movie m WHERE m.rating LIKE ?1%") + List searchByRatingStartsWith(String rating); + + //Escaping works in SpringBoot >= 2.4.1 + //@Query("SELECT m FROM Movie m WHERE m.director LIKE %?#{escape([0])} escape ?#{escapeCharacter()}") + @Query("SELECT m FROM Movie m WHERE m.director LIKE %:#{[0]}") + List searchByDirectorEndsWith(String director); +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/FruitRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/FruitRepository.java new file mode 100644 index 0000000000..5055252adf --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/FruitRepository.java @@ -0,0 +1,27 @@ +package com.baeldung.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import com.baeldung.entity.Fruit; + +@Repository +public interface FruitRepository extends JpaRepository { + + Long deleteByName(String name); + + List deleteByColor(String color); + + Long removeByName(String name); + + List removeByColor(String color); + + @Modifying + @Query("delete from Fruit f where f.name=:name or f.color=:color") + int deleteFruits(@Param("name") String name, @Param("color") String color); +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/PassengerRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/PassengerRepository.java new file mode 100644 index 0000000000..a295a74f1b --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/PassengerRepository.java @@ -0,0 +1,14 @@ +package com.baeldung.repository; + +import com.baeldung.entity.Passenger; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +interface PassengerRepository extends JpaRepository { + + List findByFirstNameIgnoreCase(String firstName); + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/SongRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/SongRepository.java new file mode 100644 index 0000000000..6faed411d3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/repository/SongRepository.java @@ -0,0 +1,22 @@ +package com.baeldung.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.entity.Song; + +@Repository +public interface SongRepository extends JpaRepository { + + List findByNameLike(String name); + + List findByNameNotLike(String name); + + List findByNameStartingWith(String startingWith); + + List findByNameEndingWith(String endingWith); + + List findBySingerContaining(String singer); +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/StoredProcedureApplication.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/StoredProcedureApplication.java new file mode 100644 index 0000000000..5f05764e21 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/StoredProcedureApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.storedprocedure; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class StoredProcedureApplication { + + public static void main(String[] args) { + SpringApplication.run(StoredProcedureApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/controller/CarController.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/controller/CarController.java new file mode 100644 index 0000000000..6aef600d01 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/controller/CarController.java @@ -0,0 +1,47 @@ +package com.baeldung.storedprocedure.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.storedprocedure.entity.Car; +import com.baeldung.storedprocedure.service.CarService; + +@RestController +public class CarController { + @Autowired + private CarService carService; + + @GetMapping(path = "/modelcount") + public long getTotalCarsByModel(@RequestParam("model") String model) { + return carService.getTotalCarsByModel(model); + } + + @GetMapping(path = "/modelcountP") + public long getTotalCarsByModelProcedureName(@RequestParam("model") String model) { + return carService.getTotalCarsByModelProcedureName(model); + } + + @GetMapping(path = "/modelcountV") + public long getTotalCarsByModelVaue(@RequestParam("model") String model) { + return carService.getTotalCarsByModelValue(model); + } + + @GetMapping(path = "/modelcountEx") + public long getTotalCarsByModelExplicit(@RequestParam("model") String model) { + return carService.getTotalCarsByModelExplicit(model); + } + + @GetMapping(path = "/modelcountEn") + public long getTotalCarsByModelEntity(@RequestParam("model") String model) { + return carService.getTotalCarsByModelEntity(model); + } + + @GetMapping(path = "/carsafteryear") + public List findCarsAfterYear(@RequestParam("year") Integer year) { + return carService.findCarsAfterYear(year); + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/entity/Car.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/entity/Car.java new file mode 100644 index 0000000000..2817c25ff7 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/entity/Car.java @@ -0,0 +1,41 @@ +package com.baeldung.storedprocedure.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedStoredProcedureQuery; +import javax.persistence.StoredProcedureParameter; +import javax.persistence.ParameterMode; + +@Entity +@NamedStoredProcedureQuery(name = "Car.getTotalCardsbyModelEntity", procedureName = "GET_TOTAL_CARS_BY_MODEL", parameters = { + @StoredProcedureParameter(mode = ParameterMode.IN, name = "model_in", type = String.class), + @StoredProcedureParameter(mode = ParameterMode.OUT, name = "count_out", type = Integer.class) }) + +public class Car { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column + private long id; + + @Column + private String model; + + @Column + private Integer year; + + public long getId() { + return id; + } + + public String getModel() { + return model; + } + + public Integer getYear() { + return year; + } + +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/repository/CarRepository.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/repository/CarRepository.java new file mode 100644 index 0000000000..3d9428628e --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/repository/CarRepository.java @@ -0,0 +1,34 @@ +package com.baeldung.storedprocedure.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.jpa.repository.query.Procedure; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import com.baeldung.storedprocedure.entity.Car; + +@Repository +public interface CarRepository extends JpaRepository { + + @Procedure + int GET_TOTAL_CARS_BY_MODEL(String model); + + @Procedure("GET_TOTAL_CARS_BY_MODEL") + int getTotalCarsByModel(String model); + + @Procedure(procedureName = "GET_TOTAL_CARS_BY_MODEL") + int getTotalCarsByModelProcedureName(String model); + + @Procedure(value = "GET_TOTAL_CARS_BY_MODEL") + int getTotalCarsByModelValue(String model); + + @Procedure(name = "Car.getTotalCardsbyModelEntity") + int getTotalCarsByModelEntiy(@Param("model_in") String model); + + @Query(value = "CALL FIND_CARS_AFTER_YEAR(:year_in);", nativeQuery = true) + List findCarsAfterYear(@Param("year_in") Integer year_in); + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/service/CarService.java b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/service/CarService.java new file mode 100644 index 0000000000..104f46e324 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/java/com/baeldung/storedprocedure/service/CarService.java @@ -0,0 +1,39 @@ +package com.baeldung.storedprocedure.service; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baeldung.storedprocedure.entity.Car; +import com.baeldung.storedprocedure.repository.CarRepository; + +@Service +public class CarService { + @Autowired + private CarRepository carRepository; + + public int getTotalCarsByModel(String model) { + return carRepository.getTotalCarsByModel(model); + } + + public int getTotalCarsByModelProcedureName(String model) { + return carRepository.getTotalCarsByModelProcedureName(model); + } + + public int getTotalCarsByModelValue(String model) { + return carRepository.getTotalCarsByModelValue(model); + } + + public int getTotalCarsByModelExplicit(String model) { + return carRepository.GET_TOTAL_CARS_BY_MODEL(model); + } + + public int getTotalCarsByModelEntity(String model) { + return carRepository.getTotalCarsByModelEntiy(model); + } + + public List findCarsAfterYear(Integer year) { + return carRepository.findCarsAfterYear(year); + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/main/resources/apple-fruit-data.xml b/persistence-modules/spring-data-jpa-repo/src/main/resources/apple-fruit-data.xml new file mode 100644 index 0000000000..d87ae28f1e --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/resources/apple-fruit-data.xml @@ -0,0 +1,7 @@ + + + + 1 + apple + red + diff --git a/persistence-modules/spring-data-jpa-repo/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-repo/src/main/resources/application.properties new file mode 100644 index 0000000000..65d7b0bf29 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.jpa.show-sql=true +#MySql +#spring.datasource.url=jdbc:mysql://localhost:3306/baeldung +#spring.datasource.username=baeldung +#spring.datasource.password=baeldung \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo/src/main/resources/car-mysql.sql b/persistence-modules/spring-data-jpa-repo/src/main/resources/car-mysql.sql new file mode 100644 index 0000000000..bb4ab2a86e --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/resources/car-mysql.sql @@ -0,0 +1,27 @@ +DROP TABLE IF EXISTS car; + +CREATE TABLE car (id int(10) NOT NULL AUTO_INCREMENT, + model varchar(50) NOT NULL, + year int(4) NOT NULL, + PRIMARY KEY (id)); + +INSERT INTO car (model, year) VALUES ('BMW', 2000); +INSERT INTO car (model, year) VALUES ('BENZ', 2010); +INSERT INTO car (model, year) VALUES ('PORCHE', 2005); +INSERT INTO car (model, year) VALUES ('PORCHE', 2004); + +DELIMITER $$ + +DROP PROCEDURE IF EXISTS FIND_CARS_AFTER_YEAR$$ +CREATE PROCEDURE FIND_CARS_AFTER_YEAR(IN year_in INT) +BEGIN + SELECT * FROM car WHERE year >= year_in ORDER BY year; +END$$ + +DROP PROCEDURE IF EXISTS GET_TOTAL_CARS_BY_MODEL$$ +CREATE PROCEDURE GET_TOTAL_CARS_BY_MODEL(IN model_in VARCHAR(50), OUT count_out INT) +BEGIN + SELECT COUNT(*) into count_out from car WHERE model = model_in; +END$$ + +DELIMITER ; diff --git a/persistence-modules/spring-data-jpa-repo/src/main/resources/fruit-data.json b/persistence-modules/spring-data-jpa-repo/src/main/resources/fruit-data.json new file mode 100644 index 0000000000..6dc44e2586 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/resources/fruit-data.json @@ -0,0 +1,14 @@ +[ + { + "_class": "com.baeldung.entity.Fruit", + "name": "apple", + "color": "red", + "id": 1 + }, + { + "_class": "com.baeldung.entity.Fruit", + "name": "guava", + "color": "green", + "id": 2 + } +] \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo/src/main/resources/guava-fruit-data.xml b/persistence-modules/spring-data-jpa-repo/src/main/resources/guava-fruit-data.xml new file mode 100644 index 0000000000..ffd75bb4bb --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/resources/guava-fruit-data.xml @@ -0,0 +1,7 @@ + + + + 2 + guava + green + diff --git a/persistence-modules/spring-data-jpa-repo/src/main/resources/import_entities.sql b/persistence-modules/spring-data-jpa-repo/src/main/resources/import_entities.sql new file mode 100644 index 0000000000..6282fd1481 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/main/resources/import_entities.sql @@ -0,0 +1,17 @@ +insert into location (id, country, city) values (1, 'Country X', 'City One'); +insert into location (id, country, city) values (2, 'Country X', 'City Two'); +insert into location (id, country, city) values (3, 'Country X', 'City Three'); + +insert into store (id, name, location_id, items_sold, active) values (1, 'Store One', 3, 130000, true); +insert into store (id, name, location_id, items_sold, active) values (2, 'Store Two', 1, 170000, false); + +insert into item_type (id, name) values (1, 'Food'); +insert into item_type (id, name) values (2, 'Furniture'); +insert into item_type (id, name) values (3, 'Electronics'); + +insert into item (id, name, store_id, item_type_id, price, grade, color) values (1, 'Food Item One', 1, 1, 100, 'A', 'Color x'); +insert into item (id, name, store_id, item_type_id, price, grade, color) values (2, 'Furniture Item One', 1, 2, 2500, 'B', 'Color y'); +insert into item (id, name, store_id, item_type_id, price, grade, color) values (3, 'Food Item Two', 1, 1, 35, 'A', 'Color z'); +insert into item (id, name, store_id, item_type_id, price, grade, color) values (5, 'Furniture Item Two', 2, 2, 1600, 'A', 'Color w'); +insert into item (id, name, store_id, item_type_id, price, grade, color) values (6, 'Food Item Three', 2, 1, 5, 'B', 'Color a'); +insert into item (id, name, store_id, item_type_id, price, grade, color) values (7, 'Electronics Item One', 2, 3, 999, 'B', 'Color b'); diff --git a/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java new file mode 100644 index 0000000000..b367b5fdca --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java @@ -0,0 +1,41 @@ +package com.baeldung.boot.daos; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import javax.annotation.Resource; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.Application; +import com.baeldung.boot.domain.Student; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = {Application.class}) +@DirtiesContext +public class ExtendedStudentRepositoryIntegrationTest { + @Resource + private ExtendedStudentRepository extendedStudentRepository; + + @Before + public void setup() { + Student student = new Student(1, "john"); + extendedStudentRepository.save(student); + Student student2 = new Student(2, "johnson"); + extendedStudentRepository.save(student2); + Student student3 = new Student(3, "tom"); + extendedStudentRepository.save(student3); + } + + @Test + public void givenStudents_whenFindByName_thenGetOk() { + List students = extendedStudentRepository.findByAttributeContainsText("name", "john"); + assertThat(students.size()).isEqualTo(2); + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java new file mode 100644 index 0000000000..22e2c81739 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java @@ -0,0 +1,61 @@ +package com.baeldung.boot.daos; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.math.BigDecimal; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.Application; +import com.baeldung.boot.domain.MerchandiseEntity; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes=Application.class) +public class InventoryRepositoryIntegrationTest { + + private static final String ORIGINAL_TITLE = "Pair of Pants"; + private static final String UPDATED_TITLE = "Branded Luxury Pants"; + private static final String UPDATED_BRAND = "Armani"; + private static final String ORIGINAL_SHORTS_TITLE = "Pair of Shorts"; + + @Autowired + private InventoryRepository repository; + + @Test + public void shouldCreateNewEntryInDB() { + MerchandiseEntity pants = new MerchandiseEntity(ORIGINAL_TITLE, BigDecimal.ONE); + pants = repository.save(pants); + + MerchandiseEntity shorts = new MerchandiseEntity(ORIGINAL_SHORTS_TITLE, new BigDecimal(3)); + shorts = repository.save(shorts); + + assertNotNull(pants.getId()); + assertNotNull(shorts.getId()); + assertNotEquals(pants.getId(), shorts.getId()); + } + + @Test + public void shouldUpdateExistingEntryInDB() { + MerchandiseEntity pants = new MerchandiseEntity(ORIGINAL_TITLE, BigDecimal.ONE); + pants = repository.save(pants); + + Long originalId = pants.getId(); + + pants.setTitle(UPDATED_TITLE); + pants.setPrice(BigDecimal.TEN); + pants.setBrand(UPDATED_BRAND); + + MerchandiseEntity result = repository.save(pants); + + assertEquals(originalId, result.getId()); + assertEquals(UPDATED_TITLE, result.getTitle()); + assertEquals(BigDecimal.TEN, result.getPrice()); + assertEquals(UPDATED_BRAND, result.getBrand()); + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java new file mode 100644 index 0000000000..9e4b78dce3 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java @@ -0,0 +1,93 @@ +package com.baeldung.boot.daos; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertFalse; +import static junit.framework.TestCase.assertNotNull; +import static junit.framework.TestCase.assertNull; +import static junit.framework.TestCase.assertTrue; + +import java.util.List; +import java.util.Optional; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.domain.Item; +import com.baeldung.boot.domain.ItemType; +import com.baeldung.boot.domain.Location; +import com.baeldung.boot.domain.Store; + +@RunWith(SpringRunner.class) +@DataJpaTest(properties="spring.datasource.data=classpath:import_entities.sql") +public class JpaRepositoriesIntegrationTest { + @Autowired + private LocationRepository locationRepository; + @Autowired + private StoreRepository storeRepository; + @Autowired + private ItemTypeRepository compositeRepository; + @Autowired + private ReadOnlyLocationRepository readOnlyRepository; + + @Test + public void whenSaveLocation_ThenGetSameLocation() { + Location location = new Location(); + location.setId(100L); + location.setCountry("Country H"); + location.setCity("City Hundred"); + location = locationRepository.saveAndFlush(location); + + Location otherLocation = locationRepository.getOne(location.getId()); + assertEquals("Country H", otherLocation.getCountry()); + assertEquals("City Hundred", otherLocation.getCity()); + + locationRepository.delete(otherLocation); + } + + @Test + public void givenLocationId_whenFindStores_thenGetStores() { + List stores = storeRepository.findStoreByLocationId(1L); + assertEquals(1, stores.size()); + } + + @Test + public void givenItemTypeId_whenDeleted_ThenItemTypeDeleted() { + Optional itemType = compositeRepository.findById(1L); + assertTrue(itemType.isPresent()); + compositeRepository.deleteCustom(itemType.get()); + itemType = compositeRepository.findById(1L); + assertFalse(itemType.isPresent()); + } + + @Test + public void givenItemId_whenUsingCustomRepo_ThenDeleteAppropriateEntity() { + Item item = compositeRepository.findItemById(1L); + assertNotNull(item); + compositeRepository.deleteCustom(item); + item = compositeRepository.findItemById(1L); + assertNull(item); + } + + @Test + public void givenItemAndItemType_WhenAmbiguousDeleteCalled_ThenItemTypeDeletedAndNotItem() { + Optional itemType = compositeRepository.findById(1L); + assertTrue(itemType.isPresent()); + Item item = compositeRepository.findItemById(2L); + assertNotNull(item); + + compositeRepository.findThenDelete(1L); + Optional sameItemType = compositeRepository.findById(1L); + assertFalse(sameItemType.isPresent()); + Item sameItem = compositeRepository.findItemById(2L); + assertNotNull(sameItem); + } + + @Test + public void whenCreatingReadOnlyRepo_thenHaveOnlyReadOnlyOperationsAvailable() { + Optional location = readOnlyRepository.findById(1L); + assertNotNull(location); + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java new file mode 100644 index 0000000000..2a6e166b88 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java @@ -0,0 +1,172 @@ +package com.baeldung.derivedquery.repository; + +import com.baeldung.derivedquery.QueryApplication; +import com.baeldung.derivedquery.entity.User; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.time.ZonedDateTime; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = QueryApplication.class) +public class UserRepositoryIntegrationTest { + + private static final String USER_NAME_ADAM = "Adam"; + private static final String USER_NAME_EVE = "Eve"; + private static final ZonedDateTime BIRTHDATE = ZonedDateTime.now(); + + @Autowired + private UserRepository userRepository; + + @Before + public void setUp() { + + User user1 = new User(USER_NAME_ADAM, 25, BIRTHDATE, true); + User user2 = new User(USER_NAME_ADAM, 20, BIRTHDATE, false); + User user3 = new User(USER_NAME_EVE, 20, BIRTHDATE, true); + User user4 = new User(null, 30, BIRTHDATE, false); + + userRepository.saveAll(Arrays.asList(user1, user2, user3, user4)); + } + + @After + public void tearDown() { + + userRepository.deleteAll(); + } + + @Test + public void whenFindByName_thenReturnsCorrectResult() { + + assertEquals(2, userRepository.findByName(USER_NAME_ADAM).size()); + } + + @Test + public void whenFindByNameIsNull_thenReturnsCorrectResult() { + + assertEquals(1, userRepository.findByNameIsNull().size()); + } + + @Test + public void whenFindByNameNot_thenReturnsCorrectResult() { + + assertEquals(USER_NAME_EVE, userRepository.findByNameNot(USER_NAME_ADAM).get(0).getName()); + } + + @Test + public void whenFindByNameStartingWith_thenReturnsCorrectResult() { + + assertEquals(2, userRepository.findByNameStartingWith("A").size()); + } + + @Test + public void whenFindByNameEndingWith_thenReturnsCorrectResult() { + + assertEquals(1, userRepository.findByNameEndingWith("e").size()); + } + + @Test + public void whenByNameContaining_thenReturnsCorrectResult() { + + assertEquals(1, userRepository.findByNameContaining("v").size()); + } + + + @Test + public void whenByNameLike_thenReturnsCorrectResult() { + + assertEquals(2, userRepository.findByNameEndingWith("m").size()); + } + + @Test + public void whenByAgeLessThan_thenReturnsCorrectResult() { + + assertEquals(2, userRepository.findByAgeLessThan(25).size()); + } + + + @Test + public void whenByAgeLessThanEqual_thenReturnsCorrectResult() { + + assertEquals(3, userRepository.findByAgeLessThanEqual(25).size()); + } + + @Test + public void whenByAgeGreaterThan_thenReturnsCorrectResult() { + + assertEquals(1, userRepository.findByAgeGreaterThan(25).size()); + } + + @Test + public void whenByAgeGreaterThanEqual_thenReturnsCorrectResult() { + + assertEquals(2, userRepository.findByAgeGreaterThanEqual(25).size()); + } + + @Test + public void whenByAgeBetween_thenReturnsCorrectResult() { + + assertEquals(4, userRepository.findByAgeBetween(20, 30).size()); + } + + @Test + public void whenByBirthDateAfter_thenReturnsCorrectResult() { + + final ZonedDateTime yesterday = BIRTHDATE.minusDays(1); + assertEquals(4, userRepository.findByBirthDateAfter(yesterday).size()); + } + + @Test + public void whenByBirthDateBefore_thenReturnsCorrectResult() { + + final ZonedDateTime yesterday = BIRTHDATE.minusDays(1); + assertEquals(0, userRepository.findByBirthDateBefore(yesterday).size()); + } + + @Test + public void whenByActiveTrue_thenReturnsCorrectResult() { + + assertEquals(2, userRepository.findByActiveTrue().size()); + } + + @Test + public void whenByActiveFalse_thenReturnsCorrectResult() { + + assertEquals(2, userRepository.findByActiveFalse().size()); + } + + + @Test + public void whenByAgeIn_thenReturnsCorrectResult() { + + final List ages = Arrays.asList(20, 25); + assertEquals(3, userRepository.findByAgeIn(ages).size()); + } + + @Test + public void whenByNameOrBirthDate() { + + assertEquals(4, userRepository.findByNameOrBirthDate(USER_NAME_ADAM, BIRTHDATE).size()); + } + + @Test + public void whenByNameOrBirthDateAndActive() { + + assertEquals(3, userRepository.findByNameOrBirthDateAndActive(USER_NAME_ADAM, BIRTHDATE, false).size()); + } + + @Test + public void whenByNameOrderByName() { + + assertEquals(2, userRepository.findByNameOrderByName(USER_NAME_ADAM).size()); + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java new file mode 100644 index 0000000000..cc96b638ab --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java @@ -0,0 +1,87 @@ +package com.baeldung.like; + +import com.baeldung.like.model.Movie; +import com.baeldung.like.repository.MovieRepository; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; + +@RunWith(SpringRunner.class) +@Sql(scripts = { "/test-movie-data.sql" }) +@SpringBootTest(classes = LikeApplication.class) +@Sql(scripts = "/test-movie-cleanup.sql", executionPhase = AFTER_TEST_METHOD) +public class MovieRepositoryIntegrationTest { + @Autowired + private MovieRepository movieRepository; + + @Test + public void givenPartialTitle_WhenFindByTitleContaining_ThenMoviesShouldReturn() { + List results = movieRepository.findByTitleContaining("in"); + assertEquals(3, results.size()); + + results = movieRepository.findByTitleLike("%in%"); + assertEquals(3, results.size()); + + results = movieRepository.findByTitleIsContaining("in"); + assertEquals(3, results.size()); + + results = movieRepository.findByTitleContains("in"); + assertEquals(3, results.size()); + } + + @Test + public void givenStartOfRating_WhenFindByRatingStartsWith_ThenMoviesShouldReturn() { + List results = movieRepository.findByRatingStartsWith("PG"); + assertEquals(6, results.size()); + } + + @Test + public void givenLastName_WhenFindByDirectorEndsWith_ThenMoviesShouldReturn() { + List results = movieRepository.findByDirectorEndsWith("Burton"); + assertEquals(1, results.size()); + } + + @Test + public void givenPartialTitle_WhenFindByTitleContainingIgnoreCase_ThenMoviesShouldReturn() { + List results = movieRepository.findByTitleContainingIgnoreCase("the"); + assertEquals(2, results.size()); + } + + @Test + public void givenPartialTitle_WhenSearchByTitleLike_ThenMoviesShouldReturn() { + List results = movieRepository.searchByTitleLike("in"); + assertEquals(3, results.size()); + } + + @Test + public void givenStartOfRating_SearchFindByRatingStartsWith_ThenMoviesShouldReturn() { + List results = movieRepository.searchByRatingStartsWith("PG"); + assertEquals(6, results.size()); + } + + @Test + public void givenLastName_WhenSearchByDirectorEndsWith_ThenMoviesShouldReturn() { + List results = movieRepository.searchByDirectorEndsWith("Burton"); + assertEquals(1, results.size()); + } + + @Test + public void givenPartialRating_findByRatingNotContaining_ThenMoviesShouldReturn() { + List results = movieRepository.findByRatingNotContaining("PG"); + assertEquals(1, results.size()); + } + + @Test + public void givenPartialDirector_WhenFindByDirectorNotLike_ThenMoviesShouldReturn() { + List results = movieRepository.findByDirectorNotLike("An%"); + assertEquals(5, results.size()); + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/FruitPopulatorIntegrationTest.java b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/FruitPopulatorIntegrationTest.java new file mode 100644 index 0000000000..4d3661e717 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/FruitPopulatorIntegrationTest.java @@ -0,0 +1,38 @@ +package com.baeldung.repository; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.entity.Fruit; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class FruitPopulatorIntegrationTest { + + @Autowired + private FruitRepository fruitRepository; + + @Test + public void givenFruitJsonPopulatorThenShouldInsertRecordOnStart() { + + List fruits = fruitRepository.findAll(); + assertEquals("record count is not matching", 2, fruits.size()); + + fruits.forEach(fruit -> { + if (1 == fruit.getId()) { + assertEquals("apple", fruit.getName()); + assertEquals("red", fruit.getColor()); + } else if (2 == fruit.getId()) { + assertEquals("guava", fruit.getName()); + assertEquals("green", fruit.getColor()); + } + }); + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java new file mode 100644 index 0000000000..37fcef7dab --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java @@ -0,0 +1,56 @@ +package com.baeldung.repository; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.core.IsNot.not; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.entity.Passenger; + +@DataJpaTest +@RunWith(SpringRunner.class) +public class PassengerRepositoryIntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + @Autowired + private PassengerRepository repository; + + @Before + public void before() { + entityManager.persist(Passenger.from("Jill", "Smith")); + entityManager.persist(Passenger.from("Eve", "Jackson")); + entityManager.persist(Passenger.from("Fred", "Bloggs")); + entityManager.persist(Passenger.from("Ricki", "Bobbie")); + entityManager.persist(Passenger.from("Siya", "Kolisi")); + } + + @Test + public void givenPassengers_whenMatchingIgnoreCase_thenExpectedReturned() { + Passenger jill = Passenger.from("Jill", "Smith"); + Passenger eve = Passenger.from("Eve", "Jackson"); + Passenger fred = Passenger.from("Fred", "Bloggs"); + Passenger siya = Passenger.from("Siya", "Kolisi"); + Passenger ricki = Passenger.from("Ricki", "Bobbie"); + + List passengers = repository.findByFirstNameIgnoreCase("FRED"); + + assertThat(passengers, contains(fred)); + assertThat(passengers, not(contains(eve))); + assertThat(passengers, not(contains(siya))); + assertThat(passengers, not(contains(jill))); + assertThat(passengers, not(contains(ricki))); + + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/SongRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/SongRepositoryIntegrationTest.java new file mode 100644 index 0000000000..19362acd44 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/java/com/baeldung/repository/SongRepositoryIntegrationTest.java @@ -0,0 +1,59 @@ +package com.baeldung.repository; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import com.baeldung.entity.Song; +import com.baeldung.repository.SongRepository; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Sql(scripts = { "/test-song-data.sql" }) +public class SongRepositoryIntegrationTest { + + @Autowired private SongRepository songRepository; + + @Transactional + @Test + public void givenSong_WhenFindLikeByName_ThenShouldReturnOne() { + List songs = songRepository.findByNameLike("Despacito"); + assertEquals(1, songs.size()); + } + + @Transactional + @Test + public void givenSong_WhenFindByNameNotLike_thenShouldReturn3Songs() { + List songs = songRepository.findByNameNotLike("Despacito"); + assertEquals(5, songs.size()); + } + + @Transactional + @Test + public void givenSong_WhenFindByNameStartingWith_thenShouldReturn2Songs() { + List songs = songRepository.findByNameStartingWith("Co"); + assertEquals(2, songs.size()); + } + + @Transactional + @Test + public void givenSong_WhenFindByNameEndingWith_thenShouldReturn2Songs() { + List songs = songRepository.findByNameEndingWith("Life"); + assertEquals(2, songs.size()); + } + + @Transactional + @Test + public void givenSong_WhenFindBySingerContaining_thenShouldReturn2Songs() { + List songs = songRepository.findBySingerContaining("Luis"); + assertEquals(2, songs.size()); + } +} diff --git a/persistence-modules/spring-data-jpa-repo/src/test/resources/application-test.properties b/persistence-modules/spring-data-jpa-repo/src/test/resources/application-test.properties new file mode 100644 index 0000000000..f9497c8f37 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/resources/application-test.properties @@ -0,0 +1,2 @@ +spring.jpa.hibernate.ddl-auto=update +spring.datasource.url=jdbc:h2:mem:jpa3 \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-cleanup.sql b/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-cleanup.sql new file mode 100644 index 0000000000..90aa15307c --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-cleanup.sql @@ -0,0 +1 @@ +DELETE FROM Movie; \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-data.sql b/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-data.sql new file mode 100644 index 0000000000..37f8e4fe64 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/resources/test-movie-data.sql @@ -0,0 +1,7 @@ +INSERT INTO movie(id, title, director, rating, duration) VALUES(1, 'Godzilla: King of the Monsters', ' Michael Dougherty', 'PG-13', 132); +INSERT INTO movie(id, title, director, rating, duration) VALUES(2, 'Avengers: Endgame', 'Anthony Russo', 'PG-13', 181); +INSERT INTO movie(id, title, director, rating, duration) VALUES(3, 'Captain Marvel', 'Anna Boden', 'PG-13', 123); +INSERT INTO movie(id, title, director, rating, duration) VALUES(4, 'Dumbo', 'Tim Burton', 'PG', 112); +INSERT INTO movie(id, title, director, rating, duration) VALUES(5, 'Booksmart', 'Olivia Wilde', 'R', 102); +INSERT INTO movie(id, title, director, rating, duration) VALUES(6, 'Aladdin', 'Guy Ritchie', 'PG', 128); +INSERT INTO movie(id, title, director, rating, duration) VALUES(7, 'The Sun Is Also a Star', 'Ry Russo-Young', 'PG-13', 100); diff --git a/persistence-modules/spring-data-jpa-repo/src/test/resources/test-song-data.sql b/persistence-modules/spring-data-jpa-repo/src/test/resources/test-song-data.sql new file mode 100644 index 0000000000..5a2b1a5555 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo/src/test/resources/test-song-data.sql @@ -0,0 +1,8 @@ +INSERT INTO song(id,name,length_in_seconds,compositor,singer,released,genre) +VALUES +(1,'Despacito',209,'Luis Fonsi','Luis Fonsi, Daddy Yankee','2017-01-12','Reggaeton'), +(2,'Con calma',188,'Daddy Yankee','Daddy Yankee','2019-01-24','Reggaeton'), +(3,'It''s My Life',205,'Bon Jovi','Jon Bon Jovi','2000-05-23','Pop'), +(4,'Live is Life',242,'Opus','Opus','1985-01-01','Reggae'), +(5,'Countdown to Extinction',249,'Megadeth','Megadeth','1992-07-14','Heavy Metal'), +(6, 'Si nos dejan',139,'Luis Miguel','Luis Miguel','1995-10-17','Bolero'); \ No newline at end of file From 3bebbd4c0295740c95e6e75e17023154001bd2af Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 19 Jul 2020 14:32:35 +0530 Subject: [PATCH 077/309] JAVA-66: removed old modules spring-data-jpa-* --- .../spring-data-jpa-2/README.md | 12 - persistence-modules/spring-data-jpa-2/pom.xml | 48 -- .../main/java/com/baeldung/Application.java | 13 - .../baeldung/aggregation/model/Comment.java | 85 --- .../com/baeldung/aggregation/model/Post.java | 75 --- .../model/custom/CommentCount.java | 27 - .../model/custom/ICommentCount.java | 8 - .../repository/CommentRepository.java | 27 - .../com/baeldung/config/JpaPopulators.java | 35 -- .../baeldung/datajpadelete/entity/Book.java | 51 -- .../datajpadelete/entity/Category.java | 60 -- .../repository/BookRepository.java | 19 - .../repository/CategoryRepository.java | 9 - .../baeldung/embeddable/model/Company.java | 71 --- .../embeddable/model/ContactPerson.java | 38 -- .../repositories/CompanyRepository.java | 18 - .../java/com/baeldung/entity/Customer.java | 37 -- .../main/java/com/baeldung/entity/Fruit.java | 40 -- .../java/com/baeldung/entity/Passenger.java | 78 --- .../main/java/com/baeldung/entity/Song.java | 75 --- .../entitygraph/model/Characteristic.java | 43 -- .../com/baeldung/entitygraph/model/Item.java | 48 -- .../repository/CharacteristicsRepository.java | 13 - .../repository/ItemRepository.java | 13 - .../main/java/com/baeldung/exists/Car.java | 48 -- .../com/baeldung/exists/CarRepository.java | 24 - .../com/baeldung/joins/model/Department.java | 45 -- .../com/baeldung/joins/model/Employee.java | 69 --- .../java/com/baeldung/joins/model/Phone.java | 44 -- .../baeldung/projection/model/Address.java | 57 -- .../com/baeldung/projection/model/Person.java | 47 -- .../repository/AddressRepository.java | 11 - .../repository/PersonRepository.java | 14 - .../baeldung/projection/view/AddressView.java | 7 - .../baeldung/projection/view/PersonDto.java | 34 -- .../baeldung/projection/view/PersonView.java | 12 - .../repository/CustomerRepository.java | 19 - .../baeldung/repository/FruitRepository.java | 27 - .../repository/PassengerRepository.java | 14 - .../baeldung/repository/SongRepository.java | 21 - .../src/main/resources/apple-fruit-data.xml | 7 - .../resources/application-joins.properties | 1 - .../src/main/resources/application.properties | 1 - .../src/main/resources/db/import_joins.sql | 13 - .../src/main/resources/fruit-data.json | 14 - .../src/main/resources/guava-fruit-data.xml | 7 - .../SpringDataAggregateIntegrationTest.java | 107 ---- .../DeleteFromRepositoryUnitTest.java | 72 --- .../DeleteInRelationshipsUnitTest.java | 60 -- .../embeddable/EmbeddableIntegrationTest.java | 125 ---- .../EntityGraphIntegrationTest.java | 39 -- .../exists/CarRepositoryIntegrationTest.java | 87 --- .../joins/JpaJoinsIntegrationTest.java | 142 ----- .../JpaProjectionIntegrationTest.java | 63 -- .../CustomerRepositoryIntegrationTest.java | 64 -- .../FruitPopulatorIntegrationTest.java | 38 -- .../FruitRepositoryIntegrationTest.java | 75 --- .../PassengerRepositoryIntegrationTest.java | 54 -- .../SongRepositoryIntegrationTest.java | 58 -- .../src/test/resources/entitygraph-data.sql | 7 - .../resources/projection-clean-up-data.sql | 2 - .../test/resources/projection-insert-data.sql | 2 - .../test/resources/test-aggregation-data.sql | 7 - .../src/test/resources/test-fruit-data.sql | 6 - .../src/test/resources/test-song-data.sql | 8 - .../spring-data-jpa-3/README.md | 20 - persistence-modules/spring-data-jpa-3/pom.xml | 71 --- .../main/java/com/baeldung/Application.java | 14 - .../DatasourceProxyBeanPostProcessor.java | 53 -- .../baeldung/batchinserts/model/School.java | 45 -- .../baeldung/batchinserts/model/Student.java | 44 -- .../java/com/baeldung/boot/Application.java | 17 - .../boot/daos/CustomerRepository.java | 19 - .../daos/impl/PersonInsertRepository.java | 31 - .../boot/daos/user/UserRepository.java | 99 ---- .../boot/daos/user/UserRepositoryCustom.java | 14 - .../daos/user/UserRepositoryCustomImpl.java | 57 -- .../com/baeldung/boot/domain/Customer.java | 56 -- .../java/com/baeldung/boot/domain/Person.java | 47 -- .../com/baeldung/boot/domain/Possession.java | 83 --- .../java/com/baeldung/boot/domain/User.java | 132 ----- .../passenger/CustomPassengerRepository.java | 8 - .../baeldung/boot/passenger/Passenger.java | 82 --- .../boot/passenger/PassengerRepository.java | 22 - .../passenger/PassengerRepositoryImpl.java | 20 - .../web/controllers/CustomerController.java | 41 -- .../java/com/baeldung/entity/Employee.java | 36 -- .../java/com/baeldung/model/BasicUser.java | 42 -- .../multipledb/MultipleDbApplication.java | 14 - .../PersistenceProductConfiguration.java | 68 --- .../dao/product/ProductRepository.java | 13 - .../multipledb/model/product/Product.java | 67 --- .../repository/EmployeeRepository.java | 9 - .../baeldung/repository/UserRepository.java | 14 - .../src/main/resources/application.properties | 6 - .../src/main/resources/logback.xml | 13 - .../persistence-multiple-db.properties | 13 - .../java/com/baeldung/SpringContextTest.java | 17 - .../SpringJpaContextIntegrationTest.java | 19 - .../BatchInsertIntegrationTest.java | 40 -- .../JpaBatchInsertsIntegrationTest.java | 98 ---- .../JpaNoBatchInsertsIntegrationTest.java | 41 -- .../batchinserts/TestObjectHelper.java | 20 - ...PersonInsertRepositoryIntegrationTest.java | 82 --- .../boot/daos/UserRepositoryCommon.java | 545 ------------------ .../daos/UserRepositoryTCAutoLiveTest.java | 43 -- .../boot/daos/UserRepositoryTCLiveTest.java | 58 -- .../PassengerRepositoryIntegrationTest.java | 190 ------ .../ProductRepositoryIntegrationTest.java | 142 ----- .../EmployeeRepositoryIntegrationTest.java | 40 -- .../util/BaeldungPostgresqlContainer.java | 35 -- .../application-batchinserts.properties | 6 - .../resources/application-tc-auto.properties | 4 - .../test/resources/application-tc.properties | 4 - .../resources/application-test.properties | 2 - .../spring-data-jpa-4/README.md | 18 - .../spring-data-jpa-4/create.sql | 2 - persistence-modules/spring-data-jpa-4/pom.xml | 47 -- .../derivedquery/QueryApplication.java | 13 - .../baeldung/derivedquery/entity/User.java | 70 --- .../repository/UserRepository.java | 60 -- .../ElementCollectionApplication.java | 11 - .../elementcollection/model/Employee.java | 68 --- .../elementcollection/model/Phone.java | 62 -- .../repository/EmployeeRepository.java | 46 -- .../SpringBootLifecycleEventApplication.java | 11 - .../model/AuditTrailListener.java | 39 -- .../baeldung/lifecycleevents/model/User.java | 104 ---- .../repository/UserRepository.java | 9 - .../com/baeldung/like/LikeApplication.java | 13 - .../java/com/baeldung/like/model/Movie.java | 58 -- .../like/repository/MovieRepository.java | 41 -- .../com/baeldung/namingstrategy/Person.java | 35 -- .../namingstrategy/PersonRepository.java | 6 - .../QuotedLowerCaseNamingStrategy.java | 12 - .../QuotedUpperCaseNamingStrategy.java | 12 - ...ingDataJpaNamingConventionApplication.java | 7 - .../UnquotedLowerCaseNamingStrategy.java | 12 - .../UnquotedUpperCaseNamingStrategy.java | 12 - .../com/baeldung/osiv/OsivApplication.java | 13 - .../com/baeldung/osiv/model/BasicUser.java | 42 -- .../osiv/repository/BasicUserRepository.java | 19 - .../osiv/service/SimpleUserService.java | 25 - .../baeldung/osiv/service/UserService.java | 9 - .../baeldung/osiv/web/DetailedUserDto.java | 45 -- .../com/baeldung/osiv/web/UserController.java | 27 - .../StoredProcedureApplication.java | 13 - .../controller/CarController.java | 47 -- .../baeldung/storedprocedure/entity/Car.java | 41 -- .../repository/CarRepository.java | 34 -- .../storedprocedure/service/CarService.java | 39 -- .../java/com/baeldung/tx/TxApplication.java | 13 - .../java/com/baeldung/tx/model/Payment.java | 55 -- .../src/main/resources/application.properties | 5 - .../src/main/resources/car-mysql.sql | 27 - .../UserRepositoryIntegrationTest.java | 172 ------ .../ElementCollectionIntegrationTest.java | 64 -- .../like/MovieRepositoryIntegrationTest.java | 87 --- ...erCaseNamingStrategyH2IntegrationTest.java | 81 --- ...werCaseNamingStrategyPostgresLiveTest.java | 85 --- ...erCaseNamingStrategyH2IntegrationTest.java | 85 --- ...perCaseNamingStrategyPostgresLiveTest.java | 81 --- ...ysicalNamingStrategyH2IntegrationTest.java | 85 --- ...hysicalNamingStrategyPostgresLiveTest.java | 85 --- ...erCaseNamingStrategyH2IntegrationTest.java | 86 --- ...werCaseNamingStrategyPostgresLiveTest.java | 85 --- ...erCaseNamingStrategyH2IntegrationTest.java | 85 --- ...perCaseNamingStrategyPostgresLiveTest.java | 85 --- .../osiv/UserControllerIntegrationTest.java | 56 -- .../tx/ManualTransactionIntegrationTest.java | 152 ----- .../UserRepositoryIntegrationTest.java | 80 --- .../resources/application-test.properties | 2 - ...ase-naming-strategy-on-postgres.properties | 9 - ...oted-lower-case-naming-strategy.properties | 9 - ...ase-naming-strategy-on-postgres.properties | 9 - ...oted-upper-case-naming-strategy.properties | 9 - ...cal-naming-strategy-on-postgres.properties | 9 - ...spring-physical-naming-strategy.properties | 9 - ...ase-naming-strategy-on-postgres.properties | 9 - ...oted-lower-case-naming-strategy.properties | 9 - ...ase-naming-strategy-on-postgres.properties | 9 - ...oted-upper-case-naming-strategy.properties | 9 - .../src/test/resources/test-movie-cleanup.sql | 1 - .../src/test/resources/test-movie-data.sql | 7 - .../spring-data-jpa-5/README.md | 15 - persistence-modules/spring-data-jpa-5/pom.xml | 80 --- .../baeldung/composite/BookApplication.java | 12 - .../com/baeldung/composite/entity/Book.java | 47 -- .../com/baeldung/composite/entity/BookId.java | 51 -- .../composite/repository/BookRepository.java | 18 - .../PartialUpdateApplication.java | 12 - .../partialupdate/model/ContactPhone.java | 22 - .../partialupdate/model/Customer.java | 23 - .../partialupdate/model/CustomerDto.java | 31 - .../model/CustomerStructured.java | 27 - .../repository/ContactPhoneRepository.java | 12 - .../repository/CustomerRepository.java | 18 - .../CustomerStructuredRepository.java | 11 - .../service/CustomerService.java | 87 --- .../partialupdate/util/CustomerMapper.java | 15 - .../schemageneration/AccountApplication.java | 12 - .../schemageneration/HibernateUtil.java | 39 -- .../schemageneration/model/Account.java | 74 --- .../model/AccountSetting.java | 68 --- .../repository/AccountRepository.java | 8 - .../repository/AccountSettingRepository.java | 8 - .../src/main/resources/application.properties | 13 - .../BookRepositoryIntegrationTest.java | 64 -- .../partialupdate/PartialUpdateUnitTest.java | 63 -- .../AccountRepositoryIntegrationTest.java | 72 --- .../resources/application-test.properties | 3 - persistence-modules/spring-data-jpa/README.md | 25 - persistence-modules/spring-data-jpa/pom.xml | 77 --- .../java/com/baeldung/boot/Application.java | 17 - .../boot/config/PersistenceConfiguration.java | 23 - .../baeldung/boot/daos/ArticleRepository.java | 23 - .../boot/daos/CustomItemRepository.java | 16 - .../boot/daos/CustomItemTypeRepository.java | 13 - .../boot/daos/ExtendedRepository.java | 14 - .../boot/daos/ExtendedStudentRepository.java | 6 - .../boot/daos/IBarCrudRepository.java | 11 - .../java/com/baeldung/boot/daos/IFooDao.java | 13 - .../boot/daos/InventoryRepository.java | 8 - .../boot/daos/ItemTypeRepository.java | 10 - .../boot/daos/LocationRepository.java | 10 - .../boot/daos/ReadOnlyLocationRepository.java | 15 - .../baeldung/boot/daos/StoreRepository.java | 13 - .../daos/impl/CustomItemRepositoryImpl.java | 33 -- .../impl/CustomItemTypeRepositoryImpl.java | 27 - .../daos/impl/ExtendedRepositoryImpl.java | 37 -- .../boot/daos/user/PossessionRepository.java | 9 - .../boot/daos/user/UserRepository.java | 99 ---- .../boot/daos/user/UserRepositoryCustom.java | 14 - .../daos/user/UserRepositoryCustomImpl.java | 57 -- .../baeldung/boot/ddd/event/Aggregate.java | 46 -- .../baeldung/boot/ddd/event/Aggregate2.java | 44 -- .../boot/ddd/event/Aggregate2Repository.java | 10 - .../baeldung/boot/ddd/event/Aggregate3.java | 23 - .../boot/ddd/event/Aggregate3Repository.java | 14 - .../boot/ddd/event/AggregateRepository.java | 10 - .../baeldung/boot/ddd/event/DddConfig.java | 15 - .../baeldung/boot/ddd/event/DomainEvent.java | 8 - .../boot/ddd/event/DomainService.java | 31 - .../com/baeldung/boot/domain/Article.java | 23 - .../java/com/baeldung/boot/domain/Bar.java | 220 ------- .../java/com/baeldung/boot/domain/Foo.java | 94 --- .../java/com/baeldung/boot/domain/Item.java | 81 --- .../com/baeldung/boot/domain/ItemType.java | 46 -- .../java/com/baeldung/boot/domain/KVTag.java | 34 -- .../com/baeldung/boot/domain/Location.java | 55 -- .../boot/domain/MerchandiseEntity.java | 66 --- .../com/baeldung/boot/domain/Possession.java | 83 --- .../com/baeldung/boot/domain/SkillTag.java | 30 - .../java/com/baeldung/boot/domain/Store.java | 76 --- .../com/baeldung/boot/domain/Student.java | 74 --- .../java/com/baeldung/boot/domain/User.java | 132 ----- .../baeldung/boot/services/IBarService.java | 7 - .../baeldung/boot/services/IFooService.java | 14 - .../baeldung/boot/services/IOperations.java | 26 - .../boot/services/impl/AbstractService.java | 61 -- .../impl/AbstractSpringDataJpaService.java | 45 -- .../impl/BarSpringDataJpaService.java | 31 - .../boot/services/impl/FooService.java | 55 -- .../multipledb/MultipleDbApplication.java | 14 - .../PersistenceProductAutoConfiguration.java | 71 --- .../PersistenceProductConfiguration.java | 68 --- .../PersistenceUserAutoConfiguration.java | 75 --- .../PersistenceUserConfiguration.java | 69 --- .../dao/product/ProductRepository.java | 14 - .../dao/user/PossessionRepository.java | 9 - .../multipledb/dao/user/UserRepository.java | 8 - .../multipledb/model/product/Product.java | 67 --- .../model/user/PossessionMultipleDB.java | 82 --- .../multipledb/model/user/UserMultipleDB.java | 88 --- .../src/main/resources/application.properties | 6 - .../src/main/resources/ddd.properties | 1 - .../src/main/resources/import_entities.sql | 21 - .../src/main/resources/logback.xml | 13 - .../persistence-multiple-db-boot.properties | 11 - .../persistence-multiple-db.properties | 13 - .../src/main/resources/persistence.properties | 14 - .../java/com/baeldung/SpringContextTest.java | 17 - .../SpringJpaContextIntegrationTest.java | 25 - .../ArticleRepositoryIntegrationTest.java | 67 --- ...endedStudentRepositoryIntegrationTest.java | 41 -- .../InventoryRepositoryIntegrationTest.java | 61 -- .../daos/JpaRepositoriesIntegrationTest.java | 93 --- .../boot/daos/UserRepositoryCommon.java | 545 ------------------ .../daos/UserRepositoryIntegrationTest.java | 37 -- .../daos/UserRepositoryTCAutoLiveTest.java | 43 -- .../boot/daos/UserRepositoryTCLiveTest.java | 58 -- .../Aggregate2EventsIntegrationTest.java | 72 --- .../Aggregate3EventsIntegrationTest.java | 67 --- .../event/AggregateEventsIntegrationTest.java | 87 --- .../boot/ddd/event/TestEventHandler.java | 14 - ...ractServicePersistenceIntegrationTest.java | 252 -------- .../FooServicePersistenceIntegrationTest.java | 75 --- .../SpringDataJPABarAuditIntegrationTest.java | 75 --- .../JpaMultipleDBIntegrationTest.java | 96 --- .../ProductRepositoryIntegrationTest.java | 144 ----- .../util/BaeldungPostgresqlContainer.java | 35 -- .../test/java/com/baeldung/util/IDUtil.java | 33 -- .../resources/application-tc-auto.properties | 4 - .../test/resources/application-tc.properties | 4 - 304 files changed, 13445 deletions(-) delete mode 100644 persistence-modules/spring-data-jpa-2/README.md delete mode 100644 persistence-modules/spring-data-jpa-2/pom.xml delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/Application.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/Comment.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/Post.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/custom/CommentCount.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/custom/ICommentCount.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/repository/CommentRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/config/JpaPopulators.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Book.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Category.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/Company.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/ContactPerson.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Customer.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Fruit.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Passenger.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Song.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Characteristic.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Item.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/Car.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/CarRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Department.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Employee.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Phone.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Address.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Person.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/AddressRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/PersonRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/AddressView.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonDto.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonView.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/CustomerRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/FruitRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/PassengerRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/SongRepository.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/resources/apple-fruit-data.xml delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/resources/application-joins.properties delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/resources/application.properties delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/resources/db/import_joins.sql delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/resources/fruit-data.json delete mode 100644 persistence-modules/spring-data-jpa-2/src/main/resources/guava-fruit-data.xml delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/aggregation/SpringDataAggregateIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitPopulatorIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/SongRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/resources/entitygraph-data.sql delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/resources/projection-clean-up-data.sql delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/resources/projection-insert-data.sql delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/resources/test-aggregation-data.sql delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/resources/test-fruit-data.sql delete mode 100644 persistence-modules/spring-data-jpa-2/src/test/resources/test-song-data.sql delete mode 100644 persistence-modules/spring-data-jpa-3/README.md delete mode 100644 persistence-modules/spring-data-jpa-3/pom.xml delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/Application.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/model/School.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/model/Student.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/Application.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/CustomerRepository.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepository.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Customer.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Person.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Possession.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/User.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/Passenger.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/entity/Employee.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/model/BasicUser.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/model/product/Product.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/EmployeeRepository.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/UserRepository.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/resources/application.properties delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/resources/logback.xml delete mode 100644 persistence-modules/spring-data-jpa-3/src/main/resources/persistence-multiple-db.properties delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/SpringContextTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/resources/application-batchinserts.properties delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/resources/application-tc-auto.properties delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/resources/application-tc.properties delete mode 100644 persistence-modules/spring-data-jpa-3/src/test/resources/application-test.properties delete mode 100644 persistence-modules/spring-data-jpa-4/README.md delete mode 100644 persistence-modules/spring-data-jpa-4/create.sql delete mode 100644 persistence-modules/spring-data-jpa-4/pom.xml delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/QueryApplication.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/entity/User.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/repository/UserRepository.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/model/Employee.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/model/Phone.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/SpringBootLifecycleEventApplication.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/model/AuditTrailListener.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/model/User.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/repository/UserRepository.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/LikeApplication.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/model/Movie.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/repository/MovieRepository.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/Person.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/PersonRepository.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/OsivApplication.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/model/BasicUser.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/SimpleUserService.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/UserService.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/UserController.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/StoredProcedureApplication.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/controller/CarController.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/entity/Car.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/repository/CarRepository.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/service/CarService.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/TxApplication.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/model/Payment.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/resources/application.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/main/resources/car-mysql.sql delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/java/lifecycleevents/UserRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/application-test.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/test-movie-cleanup.sql delete mode 100644 persistence-modules/spring-data-jpa-4/src/test/resources/test-movie-data.sql delete mode 100644 persistence-modules/spring-data-jpa-5/README.md delete mode 100644 persistence-modules/spring-data-jpa-5/pom.xml delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/BookApplication.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/entity/Book.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/entity/BookId.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/repository/BookRepository.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/Customer.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/AccountApplication.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/HibernateUtil.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/Account.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/resources/application.properties delete mode 100644 persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/composite/repository/BookRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa-5/src/test/resources/application-test.properties delete mode 100644 persistence-modules/spring-data-jpa/README.md delete mode 100644 persistence-modules/spring-data-jpa/pom.xml delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/Application.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ArticleRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IFooDao.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/InventoryRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/LocationRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/StoreRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/PossessionRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainService.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Article.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Bar.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Foo.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Item.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/ItemType.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/KVTag.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Location.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Possession.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/SkillTag.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Store.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Student.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/User.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IBarService.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IFooService.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IOperations.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractService.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/FooService.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java delete mode 100755 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java delete mode 100755 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/product/Product.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java delete mode 100644 persistence-modules/spring-data-jpa/src/main/resources/application.properties delete mode 100644 persistence-modules/spring-data-jpa/src/main/resources/ddd.properties delete mode 100644 persistence-modules/spring-data-jpa/src/main/resources/import_entities.sql delete mode 100644 persistence-modules/spring-data-jpa/src/main/resources/logback.xml delete mode 100644 persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db-boot.properties delete mode 100644 persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db.properties delete mode 100644 persistence-modules/spring-data-jpa/src/main/resources/persistence.properties delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/SpringContextTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/java/com/baeldung/util/IDUtil.java delete mode 100644 persistence-modules/spring-data-jpa/src/test/resources/application-tc-auto.properties delete mode 100644 persistence-modules/spring-data-jpa/src/test/resources/application-tc.properties diff --git a/persistence-modules/spring-data-jpa-2/README.md b/persistence-modules/spring-data-jpa-2/README.md deleted file mode 100644 index e59aca7c69..0000000000 --- a/persistence-modules/spring-data-jpa-2/README.md +++ /dev/null @@ -1,12 +0,0 @@ -### Relevant Articles: -- [Spring Data JPA – Derived Delete Methods](https://www.baeldung.com/spring-data-jpa-deleteby) -- [JPA Join Types](https://www.baeldung.com/jpa-join-types) -- [Case Insensitive Queries with Spring Data Repository](https://www.baeldung.com/spring-data-case-insensitive-queries) -- [The Exists Query in Spring Data](https://www.baeldung.com/spring-data-exists-query) -- [Spring Data JPA Repository Populators](https://www.baeldung.com/spring-data-jpa-repository-populators) -- [Spring Data JPA and Null Parameters](https://www.baeldung.com/spring-data-jpa-null-parameters) -- [Spring Data JPA Projections](https://www.baeldung.com/spring-data-jpa-projections) -- [JPA @Embedded And @Embeddable](https://www.baeldung.com/jpa-embedded-embeddable) -- [Spring Data JPA Delete and Relationships](https://www.baeldung.com/spring-data-jpa-delete) -- [Spring Data JPA and Named Entity Graphs](https://www.baeldung.com/spring-data-jpa-named-entity-graphs) -- [Customizing the Result of JPA Queries with Aggregation Functions](https://www.baeldung.com/jpa-queries-custom-result-with-aggregation-functions) diff --git a/persistence-modules/spring-data-jpa-2/pom.xml b/persistence-modules/spring-data-jpa-2/pom.xml deleted file mode 100644 index 838327de89..0000000000 --- a/persistence-modules/spring-data-jpa-2/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - 4.0.0 - spring-data-jpa-2 - spring-data-jpa-2 - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - com.h2database - h2 - - - - net.ttddyy - datasource-proxy - ${datasource-proxy.version} - - - - com.fasterxml.jackson.core - jackson-databind - - - - org.springframework - spring-oxm - - - - - 1.4.1 - - - \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/Application.java deleted file mode 100644 index 3ea3d113da..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/Comment.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/Comment.java deleted file mode 100644 index 26c2373cbe..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/Comment.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.aggregation.model; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import java.util.Objects; - -@Entity -public class Comment { - @Id - private Integer id; - private Integer year; - private boolean approved; - private String content; - @ManyToOne - private Post post; - - public Comment() { - } - - public Comment(int id, int year, boolean approved, String content, Post post) { - this.id = id; - this.year = year; - this.approved = approved; - this.content = content; - this.post = post; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public Integer getYear() { - return year; - } - - public void setYear(Integer year) { - this.year = year; - } - - public boolean isApproved() { - return approved; - } - - public void setApproved(boolean approved) { - this.approved = approved; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public Post getPost() { - return post; - } - - public void setPost(Post post) { - this.post = post; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof Comment)) { - return false; - } - Comment comment = (Comment) o; - return getId().equals(comment.getId()); - } - - @Override - public int hashCode() { - return Objects.hash(getId()); - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/Post.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/Post.java deleted file mode 100644 index f396e080ae..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/Post.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.baeldung.aggregation.model; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import java.util.List; -import java.util.Objects; - -@Entity -public class Post { - @Id - private Integer id; - private String title; - private String content; - @OneToMany(mappedBy = "post") - private List comments; - - public Post() { - } - - public Post(Integer id, String title, String content) { - this.id = id; - this.title = title; - this.content = content; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public List getComments() { - return comments; - } - - public void setComments(List comments) { - this.comments = comments; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof Post)) { - return false; - } - Post post = (Post) o; - return getId().equals(post.getId()); - } - - @Override - public int hashCode() { - return Objects.hash(getId()); - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/custom/CommentCount.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/custom/CommentCount.java deleted file mode 100644 index 510b52a47c..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/custom/CommentCount.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.aggregation.model.custom; - -public class CommentCount { - private Integer year; - private Long total; - - public CommentCount(Integer year, Long total) { - this.year = year; - this.total = total; - } - - public Integer getYear() { - return year; - } - - public void setYear(Integer year) { - this.year = year; - } - - public Long getTotal() { - return total; - } - - public void setTotal(Long total) { - this.total = total; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/custom/ICommentCount.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/custom/ICommentCount.java deleted file mode 100644 index acb25cfd49..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/model/custom/ICommentCount.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.aggregation.model.custom; - -public interface ICommentCount { - - Integer getYearComment(); - - Long getTotalComment(); -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/repository/CommentRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/repository/CommentRepository.java deleted file mode 100644 index 89e9345e94..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/aggregation/repository/CommentRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.aggregation.repository; - -import com.baeldung.aggregation.model.Comment; -import com.baeldung.aggregation.model.custom.CommentCount; -import com.baeldung.aggregation.model.custom.ICommentCount; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface CommentRepository extends JpaRepository { - - @Query("SELECT c.year, COUNT(c.year) FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC") - List countTotalCommentsByYear(); - - @Query("SELECT new com.baeldung.aggregation.model.custom.CommentCount(c.year, COUNT(c.year)) FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC") - List countTotalCommentsByYearClass(); - - @Query("SELECT c.year AS yearComment, COUNT(c.year) AS totalComment FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC") - List countTotalCommentsByYearInterface(); - - @Query(value = "SELECT c.year AS yearComment, COUNT(c.*) AS totalComment FROM comment AS c GROUP BY c.year ORDER BY c.year DESC", nativeQuery = true) - List countTotalCommentsByYearNative(); - -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/config/JpaPopulators.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/config/JpaPopulators.java deleted file mode 100644 index 24348d31c5..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/config/JpaPopulators.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.data.repository.init.Jackson2RepositoryPopulatorFactoryBean; -import org.springframework.data.repository.init.UnmarshallerRepositoryPopulatorFactoryBean; -import org.springframework.oxm.jaxb.Jaxb2Marshaller; - -import com.baeldung.entity.Fruit; - -@Configuration -public class JpaPopulators { - - @Bean - public Jackson2RepositoryPopulatorFactoryBean getRespositoryPopulator() throws Exception { - Jackson2RepositoryPopulatorFactoryBean factory = new Jackson2RepositoryPopulatorFactoryBean(); - factory.setResources(new Resource[] { new ClassPathResource("fruit-data.json") }); - return factory; - } - - @Bean - public UnmarshallerRepositoryPopulatorFactoryBean repositoryPopulator() { - - Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller(); - unmarshaller.setClassesToBeBound(Fruit.class); - - UnmarshallerRepositoryPopulatorFactoryBean factory = new UnmarshallerRepositoryPopulatorFactoryBean(); - factory.setUnmarshaller(unmarshaller); - factory.setResources(new Resource[] { new ClassPathResource("apple-fruit-data.xml"), new ClassPathResource("guava-fruit-data.xml") }); - return factory; - } - -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Book.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Book.java deleted file mode 100644 index deac24548a..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Book.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung.datajpadelete.entity; - -import javax.persistence.*; - -@Entity -public class Book { - - @Id - @GeneratedValue - private Long id; - private String title; - - @ManyToOne - private Category category; - - public Book() { - } - - public Book(String title) { - this.title = title; - } - - public Book(String title, Category category) { - this.title = title; - this.category = category; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public Category getCategory() { - return category; - } - - public void setCategory(Category category) { - this.category = category; - } -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Category.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Category.java deleted file mode 100644 index 16f1a4157f..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/entity/Category.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.datajpadelete.entity; - -import javax.persistence.*; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -@Entity -public class Category { - - @Id - @GeneratedValue - private Long id; - private String name; - - @OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true) - private List books; - - public Category() { - } - - public Category(String name) { - this.name = name; - } - - public Category(String name, Book... books) { - this.name = name; - this.books = Stream.of(books).collect(Collectors.toList()); - this.books.forEach(x -> x.setCategory(this)); - } - - public Category(String name, List books) { - this.name = name; - this.books = books; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getBooks() { - return books; - } - - public void setBooks(List books) { - this.books = books; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java deleted file mode 100644 index 5d0f45f127..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/BookRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.datajpadelete.repository; - -import com.baeldung.datajpadelete.entity.Book; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; - -@Repository -public interface BookRepository extends CrudRepository { - - long deleteByTitle(String title); - - @Modifying - @Query("delete from Book b where b.title=:title") - void deleteBooks(@Param("title") String title); - -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java deleted file mode 100644 index 6fe7058a78..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/datajpadelete/repository/CategoryRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.datajpadelete.repository; - -import com.baeldung.datajpadelete.entity.Category; -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface CategoryRepository extends CrudRepository { -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/Company.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/Company.java deleted file mode 100644 index 203cff1e35..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/Company.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.baeldung.embeddable.model; - -import javax.persistence.AttributeOverride; -import javax.persistence.AttributeOverrides; -import javax.persistence.Column; -import javax.persistence.Embedded; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -public class Company { - - @Id - @GeneratedValue - private Integer id; - - private String name; - - private String address; - - private String phone; - - @Embedded - @AttributeOverrides(value = { - @AttributeOverride( name = "firstName", column = @Column(name = "contact_first_name")), - @AttributeOverride( name = "lastName", column = @Column(name = "contact_last_name")), - @AttributeOverride( name = "phone", column = @Column(name = "contact_phone")) - }) - private ContactPerson contactPerson; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - public ContactPerson getContactPerson() { - return contactPerson; - } - - public void setContactPerson(ContactPerson contactPerson) { - this.contactPerson = contactPerson; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/ContactPerson.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/ContactPerson.java deleted file mode 100644 index 561da80878..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/model/ContactPerson.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.embeddable.model; - -import javax.persistence.Embeddable; - -@Embeddable -public class ContactPerson { - - private String firstName; - - private String lastName; - - private String phone; - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java deleted file mode 100644 index f456b15652..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/embeddable/repositories/CompanyRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.embeddable.repositories; - -import com.baeldung.embeddable.model.Company; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; - -import java.util.List; - -public interface CompanyRepository extends JpaRepository { - - List findByContactPersonFirstName(String firstName); - - @Query("SELECT C FROM Company C WHERE C.contactPerson.firstName = ?1") - List findByContactPersonFirstNameWithJPQL(String firstName); - - @Query(value = "SELECT * FROM company WHERE contact_first_name = ?1", nativeQuery = true) - List findByContactPersonFirstNameWithNativeQuery(String firstName); -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Customer.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Customer.java deleted file mode 100644 index efcae73853..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Customer.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.entity; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity -public class Customer { - - @Id - @GeneratedValue - private long id; - private String name; - private String email; - - public Customer(String name, String email) { - this.name = name; - this.email = email; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Fruit.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Fruit.java deleted file mode 100644 index d45ac33db8..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Fruit.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.entity; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement -@Entity -public class Fruit { - - @Id - private long id; - private String name; - private String color; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getColor() { - return color; - } - - public void setColor(String color) { - this.color = color; - } - -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Passenger.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Passenger.java deleted file mode 100644 index 3aafbe9afa..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Passenger.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.baeldung.entity; - -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import java.util.Objects; - -@Entity -public class Passenger { - - @Id - @GeneratedValue - @Column(nullable = false) - private Long id; - - @Basic(optional = false) - @Column(nullable = false) - private String firstName; - - @Basic(optional = false) - @Column(nullable = false) - private String lastName; - - private Passenger(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - public static Passenger from(String firstName, String lastName) { - return new Passenger(firstName, lastName); - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - @Override - public String toString() { - return "Passenger{" + "id=" + id + ", firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - Passenger passenger = (Passenger) o; - return Objects.equals(firstName, passenger.firstName) && Objects.equals(lastName, passenger.lastName); - } - - @Override - public int hashCode() { - return Objects.hash(firstName, lastName); - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Song.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Song.java deleted file mode 100644 index 395527c1eb..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entity/Song.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.baeldung.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import java.time.LocalDateTime; - -@Entity -public class Song { - - @Id private long id; - private String name; - @Column(name = "length_in_seconds") - private int lengthInSeconds; - private String compositor; - private String singer; - private LocalDateTime released; - private String genre; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getLengthInSeconds() { - return lengthInSeconds; - } - - public void setLengthInSeconds(int lengthInSeconds) { - this.lengthInSeconds = lengthInSeconds; - } - - public String getCompositor() { - return compositor; - } - - public void setCompositor(String compositor) { - this.compositor = compositor; - } - - public String getSinger() { - return singer; - } - - public void setSinger(String singer) { - this.singer = singer; - } - - public LocalDateTime getReleased() { - return released; - } - - public void setReleased(LocalDateTime released) { - this.released = released; - } - - public String getGenre() { - return genre; - } - - public void setGenre(String genre) { - this.genre = genre; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Characteristic.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Characteristic.java deleted file mode 100644 index ae20375572..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Characteristic.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.entitygraph.model; - -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; - -@Entity -public class Characteristic { - - @Id - private Long id; - private String type; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn - private Item item; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Item getItem() { - return item; - } - - public void setItem(Item item) { - this.item = item; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Item.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Item.java deleted file mode 100644 index e90a22ef62..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/model/Item.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.entitygraph.model; - -import java.util.ArrayList; -import java.util.List; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.NamedAttributeNode; -import javax.persistence.NamedEntityGraph; -import javax.persistence.OneToMany; - -@Entity -@NamedEntityGraph(name = "Item.characteristics", - attributeNodes = @NamedAttributeNode("characteristics") -) -public class Item { - - @Id - private Long id; - private String name; - - @OneToMany(mappedBy = "item") - private List characteristics = new ArrayList<>(); - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getCharacteristics() { - return characteristics; - } - - public void setCharacteristics(List characteristics) { - this.characteristics = characteristics; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java deleted file mode 100644 index 9f923ab241..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/CharacteristicsRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.entitygraph.repository; - -import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; - -import com.baeldung.entitygraph.model.Characteristic; - -public interface CharacteristicsRepository extends JpaRepository { - - @EntityGraph(attributePaths = {"item"}) - Characteristic findByType(String type); - -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java deleted file mode 100644 index b2a5f223b3..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/entitygraph/repository/ItemRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.entitygraph.repository; - -import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType; -import org.springframework.data.jpa.repository.JpaRepository; - -import com.baeldung.entitygraph.model.Item; - -public interface ItemRepository extends JpaRepository { - - @EntityGraph(value = "Item.characteristics", type = EntityGraphType.FETCH) - Item findByName(String name); -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/Car.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/Car.java deleted file mode 100644 index bf09caf6ff..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/Car.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.exists; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -/** - * @author paullatzelsperger - * @since 2019-03-20 - */ -@Entity -public class Car { - - @Id - @GeneratedValue - private int id; - private Integer power; - private String model; - - Car() { - - } - - public Car(int power, String model) { - this.power = power; - this.model = model; - } - - public Integer getPower() { - return power; - } - - public void setPower(Integer power) { - this.power = power; - } - - public String getModel() { - return model; - } - - public void setModel(String model) { - this.model = model; - } - - public int getId() { - return id; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/CarRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/CarRepository.java deleted file mode 100644 index a54f19f4cd..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/exists/CarRepository.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.exists; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; - -/** - * @author paullatzelsperger - * @since 2019-03-20 - */ -@Repository -public interface CarRepository extends JpaRepository { - - boolean existsCarByPower(int power); - - boolean existsCarByModel(String model); - - @Query("select case when count(c)> 0 then true else false end from Car c where c.model = :model") - boolean existsCarExactCustomQuery(@Param("model") String model); - - @Query("select case when count(c)> 0 then true else false end from Car c where lower(c.model) like lower(:model)") - boolean existsCarLikeCustomQuery(@Param("model") String model); -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Department.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Department.java deleted file mode 100644 index 439f7532f5..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Department.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.joins.model; - -import java.util.List; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToMany; - -@Entity -public class Department { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private long id; - - private String name; - - @OneToMany(mappedBy = "department") - private List employees; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getEmployees() { - return employees; - } - - public void setEmployees(List employees) { - this.employees = employees; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Employee.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Employee.java deleted file mode 100644 index 277274e61c..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Employee.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.baeldung.joins.model; - -import java.util.List; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.Table; - -@Entity -@Table(name = "joins_employee") -public class Employee { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - private String name; - - private int age; - - @ManyToOne - private Department department; - - @OneToMany(mappedBy = "employee") - private List phones; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public Department getDepartment() { - return department; - } - - public void setDepartment(Department department) { - this.department = department; - } - - public List getPhones() { - return phones; - } - - public void setPhones(List phones) { - this.phones = phones; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Phone.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Phone.java deleted file mode 100644 index 41382915b1..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/joins/model/Phone.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.joins.model; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.ManyToOne; - -@Entity -public class Phone { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - private String number; - - @ManyToOne - private Employee employee; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getNumber() { - return number; - } - - public void setNumber(String number) { - this.number = number; - } - - public Employee getEmployee() { - return employee; - } - - public void setEmployee(Employee employee) { - this.employee = employee; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Address.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Address.java deleted file mode 100644 index 0c5a3eac60..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Address.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.baeldung.projection.model; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.OneToOne; - -@Entity -public class Address { - @Id - private Long id; - @OneToOne - private Person person; - private String state; - private String city; - private String street; - private String zipCode; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getStreet() { - return street; - } - - public void setStreet(String street) { - this.street = street; - } - - public String getZipCode() { - return zipCode; - } - - public void setZipCode(String zipCode) { - this.zipCode = zipCode; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Person.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Person.java deleted file mode 100644 index d18bd1c72d..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/model/Person.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.projection.model; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.OneToOne; - -@Entity -public class Person { - @Id - private Long id; - private String firstName; - private String lastName; - @OneToOne(mappedBy = "person") - private Address address; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public Address getAddress() { - return address; - } - - public void setAddress(Address address) { - this.address = address; - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/AddressRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/AddressRepository.java deleted file mode 100644 index c1053f4867..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/AddressRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.projection.repository; - -import com.baeldung.projection.view.AddressView; -import com.baeldung.projection.model.Address; -import org.springframework.data.repository.Repository; - -import java.util.List; - -public interface AddressRepository extends Repository { - List getAddressByState(String state); -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/PersonRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/PersonRepository.java deleted file mode 100644 index 64bc7471e6..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/repository/PersonRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.projection.repository; - -import com.baeldung.projection.model.Person; -import com.baeldung.projection.view.PersonDto; -import com.baeldung.projection.view.PersonView; -import org.springframework.data.repository.Repository; - -public interface PersonRepository extends Repository { - PersonView findByLastName(String lastName); - - PersonDto findByFirstName(String firstName); - - T findByLastName(String lastName, Class type); -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/AddressView.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/AddressView.java deleted file mode 100644 index 7a24a1e9b9..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/AddressView.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.projection.view; - -public interface AddressView { - String getZipCode(); - - PersonView getPerson(); -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonDto.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonDto.java deleted file mode 100644 index 1fd924450b..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonDto.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.projection.view; - -import java.util.Objects; - -public class PersonDto { - private final String firstName; - private final String lastName; - - public PersonDto(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - public String getFirstName() { - return firstName; - } - - public String getLastName() { - return lastName; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - PersonDto personDto = (PersonDto) o; - return Objects.equals(firstName, personDto.firstName) && Objects.equals(lastName, personDto.lastName); - } - - @Override - public int hashCode() { - return Objects.hash(firstName, lastName); - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonView.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonView.java deleted file mode 100644 index 36777ec26f..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/projection/view/PersonView.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.projection.view; - -import org.springframework.beans.factory.annotation.Value; - -public interface PersonView { - String getFirstName(); - - String getLastName(); - - @Value("#{target.firstName + ' ' + target.lastName}") - String getFullName(); -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/CustomerRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/CustomerRepository.java deleted file mode 100644 index 65b22bbd84..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/CustomerRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.repository; - -import com.baeldung.entity.Customer; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; - -public interface CustomerRepository extends JpaRepository { - - List findByName(String name); - - List findByNameAndEmail(String name, String email); - - @Query("SELECT c FROM Customer c WHERE (:name is null or c.name = :name) and (:email is null or c.email = :email)") - List findCustomerByNameAndEmail(@Param("name") String name, @Param("email") String email); - -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/FruitRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/FruitRepository.java deleted file mode 100644 index 5055252adf..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/FruitRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.repository; - -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; - -import com.baeldung.entity.Fruit; - -@Repository -public interface FruitRepository extends JpaRepository { - - Long deleteByName(String name); - - List deleteByColor(String color); - - Long removeByName(String name); - - List removeByColor(String color); - - @Modifying - @Query("delete from Fruit f where f.name=:name or f.color=:color") - int deleteFruits(@Param("name") String name, @Param("color") String color); -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/PassengerRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/PassengerRepository.java deleted file mode 100644 index a295a74f1b..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/PassengerRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.repository; - -import com.baeldung.entity.Passenger; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -interface PassengerRepository extends JpaRepository { - - List findByFirstNameIgnoreCase(String firstName); - -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/SongRepository.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/SongRepository.java deleted file mode 100644 index ad887fe680..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/repository/SongRepository.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.repository; - -import com.baeldung.entity.Song; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface SongRepository extends JpaRepository { - - List findByNameLike(String name); - - List findByNameNotLike(String name); - - List findByNameStartingWith(String startingWith); - - List findByNameEndingWith(String endingWith); - - List findBySingerContaining(String singer); -} diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/apple-fruit-data.xml b/persistence-modules/spring-data-jpa-2/src/main/resources/apple-fruit-data.xml deleted file mode 100644 index d87ae28f1e..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/resources/apple-fruit-data.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - 1 - apple - red - diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/application-joins.properties b/persistence-modules/spring-data-jpa-2/src/main/resources/application-joins.properties deleted file mode 100644 index fe2270293b..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/resources/application-joins.properties +++ /dev/null @@ -1 +0,0 @@ -spring.datasource.data=classpath:db/import_joins.sql diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-2/src/main/resources/application.properties deleted file mode 100644 index 72fc330767..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.jpa.show-sql=true \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/db/import_joins.sql b/persistence-modules/spring-data-jpa-2/src/main/resources/db/import_joins.sql deleted file mode 100644 index e4772d6ff2..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/resources/db/import_joins.sql +++ /dev/null @@ -1,13 +0,0 @@ -INSERT INTO department (id, name) VALUES (1, 'Infra'); -INSERT INTO department (id, name) VALUES (2, 'Accounting'); -INSERT INTO department (id, name) VALUES (3, 'Management'); - -INSERT INTO joins_employee (id, name, age, department_id) VALUES (1, 'Baeldung', '35', 1); -INSERT INTO joins_employee (id, name, age, department_id) VALUES (2, 'John', '35', 2); -INSERT INTO joins_employee (id, name, age, department_id) VALUES (3, 'Jane', '35', 2); - -INSERT INTO phone (id, number, employee_id) VALUES (1, '111', 1); -INSERT INTO phone (id, number, employee_id) VALUES (2, '222', 1); -INSERT INTO phone (id, number, employee_id) VALUES (3, '333', 1); - -COMMIT; diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/fruit-data.json b/persistence-modules/spring-data-jpa-2/src/main/resources/fruit-data.json deleted file mode 100644 index 6dc44e2586..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/resources/fruit-data.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "_class": "com.baeldung.entity.Fruit", - "name": "apple", - "color": "red", - "id": 1 - }, - { - "_class": "com.baeldung.entity.Fruit", - "name": "guava", - "color": "green", - "id": 2 - } -] \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/guava-fruit-data.xml b/persistence-modules/spring-data-jpa-2/src/main/resources/guava-fruit-data.xml deleted file mode 100644 index ffd75bb4bb..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/main/resources/guava-fruit-data.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - 2 - guava - green - diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/aggregation/SpringDataAggregateIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/aggregation/SpringDataAggregateIntegrationTest.java deleted file mode 100644 index 779ade7a3f..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/aggregation/SpringDataAggregateIntegrationTest.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.baeldung.aggregation; - -import com.baeldung.aggregation.model.custom.CommentCount; -import com.baeldung.aggregation.model.custom.ICommentCount; -import com.baeldung.aggregation.repository.CommentRepository; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.List; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -@RunWith(SpringRunner.class) -@DataJpaTest - -@Sql(scripts = "/test-aggregation-data.sql") -public class SpringDataAggregateIntegrationTest { - - @Autowired - private CommentRepository commentRepository; - - @Test - public void whenQueryWithAggregation_thenReturnResult() { - List commentCountsByYear = commentRepository.countTotalCommentsByYear(); - - Object[] countYear2019 = commentCountsByYear.get(0); - - assertThat(countYear2019[0], is(Integer.valueOf(2019))); - assertThat(countYear2019[1], is(1l)); - - Object[] countYear2018 = commentCountsByYear.get(1); - - assertThat(countYear2018[0], is(Integer.valueOf(2018))); - assertThat(countYear2018[1], is(2l)); - - Object[] countYear2017 = commentCountsByYear.get(2); - - assertThat(countYear2017[0], is(Integer.valueOf(2017))); - assertThat(countYear2017[1], is(1l)); - } - - @Test - public void whenQueryWithAggregation_thenReturnCustomResult() { - List commentCountsByYear = commentRepository.countTotalCommentsByYearClass(); - - CommentCount countYear2019 = commentCountsByYear.get(0); - - assertThat(countYear2019.getYear(), is(Integer.valueOf(2019))); - assertThat(countYear2019.getTotal(), is(1l)); - - CommentCount countYear2018 = commentCountsByYear.get(1); - - assertThat(countYear2018.getYear(), is(Integer.valueOf(2018))); - assertThat(countYear2018.getTotal(), is(2l)); - - CommentCount countYear2017 = commentCountsByYear.get(2); - - assertThat(countYear2017.getYear(), is(Integer.valueOf(2017))); - assertThat(countYear2017.getTotal(), is(1l)); - } - - @Test - public void whenQueryWithAggregation_thenReturnInterfaceResult() { - List commentCountsByYear = commentRepository.countTotalCommentsByYearInterface(); - - ICommentCount countYear2019 = commentCountsByYear.get(0); - - assertThat(countYear2019.getYearComment(), is(Integer.valueOf(2019))); - assertThat(countYear2019.getTotalComment(), is(1l)); - - ICommentCount countYear2018 = commentCountsByYear.get(1); - - assertThat(countYear2018.getYearComment(), is(Integer.valueOf(2018))); - assertThat(countYear2018.getTotalComment(), is(2l)); - - ICommentCount countYear2017 = commentCountsByYear.get(2); - - assertThat(countYear2017.getYearComment(), is(Integer.valueOf(2017))); - assertThat(countYear2017.getTotalComment(), is(1l)); - } - - @Test - public void whenNativeQueryWithAggregation_thenReturnInterfaceResult() { - List commentCountsByYear = commentRepository.countTotalCommentsByYearNative(); - - ICommentCount countYear2019 = commentCountsByYear.get(0); - - assertThat(countYear2019.getYearComment(), is(Integer.valueOf(2019))); - assertThat(countYear2019.getTotalComment(), is(1l)); - - ICommentCount countYear2018 = commentCountsByYear.get(1); - - assertThat(countYear2018.getYearComment(), is(Integer.valueOf(2018))); - assertThat(countYear2018.getTotalComment(), is(2l)); - - ICommentCount countYear2017 = commentCountsByYear.get(2); - - assertThat(countYear2017.getYearComment(), is(Integer.valueOf(2017))); - assertThat(countYear2017.getTotalComment(), is(1l)); - } - -} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java deleted file mode 100644 index 5f4a36bc0e..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteFromRepositoryUnitTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.baeldung.datajpadelete; - -import com.baeldung.Application; -import com.baeldung.datajpadelete.entity.Book; -import com.baeldung.datajpadelete.repository.BookRepository; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = {Application.class}) -public class DeleteFromRepositoryUnitTest { - - @Autowired - private BookRepository repository; - - Book book1; - Book book2; - - @Before - public void setup() { - book1 = new Book("The Hobbit"); - book2 = new Book("All Quiet on the Western Front"); - - repository.saveAll(Arrays.asList(book1, book2)); - } - - @After - public void teardown() { - repository.deleteAll(); - } - - @Test - public void whenDeleteByIdFromRepository_thenDeletingShouldBeSuccessful() { - repository.deleteById(book1.getId()); - - assertThat(repository.count()).isEqualTo(1); - } - - @Test - public void whenDeleteAllFromRepository_thenRepositoryShouldBeEmpty() { - repository.deleteAll(); - - assertThat(repository.count()).isEqualTo(0); - } - - @Test - @Transactional - public void whenDeleteFromDerivedQuery_thenDeletingShouldBeSuccessful() { - long deletedRecords = repository.deleteByTitle("The Hobbit"); - - assertThat(deletedRecords).isEqualTo(1); - } - - @Test - @Transactional - public void whenDeleteFromCustomQuery_thenDeletingShouldBeSuccessful() { - repository.deleteBooks("The Hobbit"); - - assertThat(repository.count()).isEqualTo(1); - } - -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java deleted file mode 100644 index 6275ace6e0..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/datajpadelete/DeleteInRelationshipsUnitTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.datajpadelete; - -import com.baeldung.Application; -import com.baeldung.datajpadelete.entity.Book; -import com.baeldung.datajpadelete.entity.Category; -import com.baeldung.datajpadelete.repository.BookRepository; -import com.baeldung.datajpadelete.repository.CategoryRepository; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = {Application.class}) -public class DeleteInRelationshipsUnitTest { - - @Autowired - private BookRepository bookRepository; - - @Autowired - private CategoryRepository categoryRepository; - - @Before - public void setup() { - Book book1 = new Book("The Hobbit"); - Category category1 = new Category("Cat1", book1); - categoryRepository.save(category1); - - Book book2 = new Book("All Quiet on the Western Front"); - Category category2 = new Category("Cat2", book2); - categoryRepository.save(category2); - } - - @After - public void teardown() { - bookRepository.deleteAll(); - categoryRepository.deleteAll(); - } - - @Test - public void whenDeletingCategories_thenBooksShouldAlsoBeDeleted() { - categoryRepository.deleteAll(); - - assertThat(bookRepository.count()).isEqualTo(0); - assertThat(categoryRepository.count()).isEqualTo(0); - } - - @Test - public void whenDeletingBooks_thenCategoriesShouldAlsoBeDeleted() { - bookRepository.deleteAll(); - - assertThat(bookRepository.count()).isEqualTo(0); - assertThat(categoryRepository.count()).isEqualTo(2); - } -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java deleted file mode 100644 index b4c365a2d9..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/embeddable/EmbeddableIntegrationTest.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.baeldung.embeddable; - -import com.baeldung.Application; -import com.baeldung.embeddable.model.Company; -import com.baeldung.embeddable.model.ContactPerson; -import com.baeldung.embeddable.repositories.CompanyRepository; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -import static org.junit.Assert.assertEquals; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = {Application.class}) -public class EmbeddableIntegrationTest { - - @Autowired - private CompanyRepository companyRepository; - - @Test - @Transactional - public void whenInsertingCompany_thenEmbeddedContactPersonDetailsAreMapped() { - ContactPerson contactPerson = new ContactPerson(); - contactPerson.setFirstName("First"); - contactPerson.setLastName("Last"); - contactPerson.setPhone("123-456-789"); - - Company company = new Company(); - company.setName("Company"); - company.setAddress("1st street"); - company.setPhone("987-654-321"); - company.setContactPerson(contactPerson); - - companyRepository.save(company); - - Company result = companyRepository.getOne(company.getId()); - - assertEquals("Company", result.getName()); - assertEquals("1st street", result.getAddress()); - assertEquals("987-654-321", result.getPhone()); - assertEquals("First", result.getContactPerson().getFirstName()); - assertEquals("Last", result.getContactPerson().getLastName()); - assertEquals("123-456-789", result.getContactPerson().getPhone()); - } - - @Test - @Transactional - public void whenFindingCompanyByContactPersonAttribute_thenCompanyIsReturnedProperly() { - ContactPerson contactPerson = new ContactPerson(); - contactPerson.setFirstName("Name"); - contactPerson.setLastName("Last"); - contactPerson.setPhone("123-456-789"); - - Company company = new Company(); - company.setName("Company"); - company.setAddress("1st street"); - company.setPhone("987-654-321"); - company.setContactPerson(contactPerson); - - companyRepository.save(company); - - List result = companyRepository.findByContactPersonFirstName("Name"); - - assertEquals(1, result.size()); - - result = companyRepository.findByContactPersonFirstName("FirstName"); - - assertEquals(0, result.size()); - } - - @Test - @Transactional - public void whenFindingCompanyByContactPersonAttributeWithJPQL_thenCompanyIsReturnedProperly() { - ContactPerson contactPerson = new ContactPerson(); - contactPerson.setFirstName("@QueryName"); - contactPerson.setLastName("Last"); - contactPerson.setPhone("123-456-789"); - - Company company = new Company(); - company.setName("Company"); - company.setAddress("1st street"); - company.setPhone("987-654-321"); - company.setContactPerson(contactPerson); - - companyRepository.save(company); - - List result = companyRepository.findByContactPersonFirstNameWithJPQL("@QueryName"); - - assertEquals(1, result.size()); - - result = companyRepository.findByContactPersonFirstNameWithJPQL("FirstName"); - - assertEquals(0, result.size()); - } - - @Test - @Transactional - public void whenFindingCompanyByContactPersonAttributeWithNativeQuery_thenCompanyIsReturnedProperly() { - ContactPerson contactPerson = new ContactPerson(); - contactPerson.setFirstName("NativeQueryName"); - contactPerson.setLastName("Last"); - contactPerson.setPhone("123-456-789"); - - Company company = new Company(); - company.setName("Company"); - company.setAddress("1st street"); - company.setPhone("987-654-321"); - company.setContactPerson(contactPerson); - - companyRepository.save(company); - - List result = companyRepository.findByContactPersonFirstNameWithNativeQuery("NativeQueryName"); - - assertEquals(1, result.size()); - - result = companyRepository.findByContactPersonFirstNameWithNativeQuery("FirstName"); - - assertEquals(0, result.size()); - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java deleted file mode 100644 index 24880a5dff..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/entitygraph/EntityGraphIntegrationTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.entitygraph; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.entitygraph.model.Characteristic; -import com.baeldung.entitygraph.model.Item; -import com.baeldung.entitygraph.repository.CharacteristicsRepository; -import com.baeldung.entitygraph.repository.ItemRepository; - -@DataJpaTest -@RunWith(SpringRunner.class) -@Sql(scripts = "/entitygraph-data.sql") -public class EntityGraphIntegrationTest { - - @Autowired - private ItemRepository itemRepo; - - @Autowired - private CharacteristicsRepository characteristicsRepo; - - @Test - public void givenEntityGraph_whenCalled_shouldRetrunDefinedFields() { - Item item = itemRepo.findByName("Table"); - assertThat(item.getId()).isEqualTo(1L); - } - - @Test - public void givenAdhocEntityGraph_whenCalled_shouldRetrunDefinedFields() { - Characteristic characteristic = characteristicsRepo.findByType("Rigid"); - assertThat(characteristic.getId()).isEqualTo(1L); - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java deleted file mode 100644 index d99f6671a3..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/exists/CarRepositoryIntegrationTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.baeldung.exists; - -import com.baeldung.Application; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Example; -import org.springframework.data.domain.ExampleMatcher; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Arrays; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.ignoreCase; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = {Application.class}) -public class CarRepositoryIntegrationTest { - - @Autowired - private CarRepository repository; - private int searchId; - - @Before - public void setup() { - List cars = repository.saveAll(Arrays.asList(new Car(200, "BMW"), new Car(300, "Audi"))); - searchId = cars.get(0).getId(); - } - - @After - public void teardown() { - repository.deleteAll(); - } - - @Test - public void whenIdIsCorrect_thenExistsShouldReturnTrue() { - assertThat(repository.existsById(searchId)).isTrue(); - } - - @Test - public void givenExample_whenExists_thenIsTrue() { - ExampleMatcher modelMatcher = ExampleMatcher.matching() - .withIgnorePaths("id") // must explicitly ignore -> PK - .withMatcher("model", ignoreCase()); - Car probe = new Car(); - probe.setModel("bmw"); - - Example example = Example.of(probe, modelMatcher); - - assertThat(repository.exists(example)).isTrue(); - } - - @Test - public void givenPower_whenExists_thenIsFalse() { - assertThat(repository.existsCarByPower(200)).isTrue(); - assertThat(repository.existsCarByPower(800)).isFalse(); - } - - @Test - public void existsByDerivedQuery_byModel() { - assertThat(repository.existsCarByModel("Audi")).isTrue(); - assertThat(repository.existsCarByModel("audi")).isFalse(); - assertThat(repository.existsCarByModel("AUDI")).isFalse(); - assertThat(repository.existsCarByModel("")).isFalse(); - } - - @Test - public void givenModelName_whenExistsExact_thenIsTrue() { - assertThat(repository.existsCarExactCustomQuery("BMW")).isTrue(); - assertThat(repository.existsCarExactCustomQuery("Bmw")).isFalse(); - assertThat(repository.existsCarExactCustomQuery("bmw")).isFalse(); - assertThat(repository.existsCarExactCustomQuery("")).isFalse(); - } - - @Test - public void givenModelName_whenExistsLike_thenIsTrue() { - assertThat(repository.existsCarLikeCustomQuery("BMW")).isTrue(); - assertThat(repository.existsCarLikeCustomQuery("Bmw")).isTrue(); - assertThat(repository.existsCarLikeCustomQuery("bmw")).isTrue(); - assertThat(repository.existsCarLikeCustomQuery("")).isFalse(); - } - -} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java deleted file mode 100644 index 9b0d23f3e4..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/joins/JpaJoinsIntegrationTest.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.baeldung.joins; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.baeldung.joins.model.Department; -import com.baeldung.joins.model.Phone; -import java.util.Collection; -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.TypedQuery; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@DataJpaTest -@ActiveProfiles("joins") -public class JpaJoinsIntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - - @Test - public void whenPathExpressionIsUsedForSingleValuedAssociation_thenCreatesImplicitInnerJoin() { - TypedQuery query = entityManager.createQuery("SELECT e.department FROM Employee e", Department.class); - - List resultList = query.getResultList(); - - assertThat(resultList).hasSize(3); - assertThat(resultList).extracting("name") - .containsOnly("Infra", "Accounting", "Accounting"); - } - - @Test - public void whenJoinKeywordIsUsed_thenCreatesExplicitInnerJoin() { - TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e JOIN e.department d", Department.class); - - List resultList = query.getResultList(); - - assertThat(resultList).hasSize(3); - assertThat(resultList).extracting("name") - .containsOnly("Infra", "Accounting", "Accounting"); - } - - @Test - public void whenInnerJoinKeywordIsUsed_thenCreatesExplicitInnerJoin() { - TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e INNER JOIN e.department d", Department.class); - - List resultList = query.getResultList(); - - assertThat(resultList).hasSize(3); - assertThat(resultList).extracting("name") - .containsOnly("Infra", "Accounting", "Accounting"); - } - - @Test - public void whenEntitiesAreListedInFromAndMatchedInWhere_ThenCreatesJoin() { - TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e, Department d WHERE e.department = d", Department.class); - - List resultList = query.getResultList(); - - assertThat(resultList).hasSize(3); - assertThat(resultList).extracting("name") - .containsOnly("Infra", "Accounting", "Accounting"); - } - - @Test - public void whenEntitiesAreListedInFrom_ThenCreatesCartesianProduct() { - TypedQuery query = entityManager.createQuery("SELECT d FROM Employee e, Department d", Department.class); - - List resultList = query.getResultList(); - - assertThat(resultList).hasSize(9); - assertThat(resultList).extracting("name") - .containsOnly("Infra", "Accounting", "Management", "Infra", "Accounting", "Management", "Infra", "Accounting", "Management"); - } - - @Test - public void whenCollectionValuedAssociationIsJoined_ThenCanSelect() { - TypedQuery query = entityManager.createQuery("SELECT ph FROM Employee e JOIN e.phones ph WHERE ph LIKE '1%'", Phone.class); - - List resultList = query.getResultList(); - - assertThat(resultList).hasSize(1); - } - - @Test - public void whenMultipleEntitiesAreListedWithJoin_ThenCreatesMultipleJoins() { - TypedQuery query = entityManager.createQuery("SELECT ph FROM Employee e JOIN e.department d JOIN e.phones ph WHERE d.name IS NOT NULL", Phone.class); - - List resultList = query.getResultList(); - - assertThat(resultList).hasSize(3); - assertThat(resultList).extracting("number") - .containsOnly("111", "222", "333"); - } - - @Test - public void whenLeftKeywordIsSpecified_thenCreatesOuterJoinAndIncludesNonMatched() { - TypedQuery query = entityManager.createQuery("SELECT DISTINCT d FROM Department d LEFT JOIN d.employees e", Department.class); - - List resultList = query.getResultList(); - - assertThat(resultList).hasSize(3); - assertThat(resultList).extracting("name") - .containsOnly("Infra", "Accounting", "Management"); - } - - @Test - public void whenFetchKeywordIsSpecified_ThenCreatesFetchJoin() { - TypedQuery query = entityManager.createQuery("SELECT d FROM Department d JOIN FETCH d.employees", Department.class); - - List resultList = query.getResultList(); - - assertThat(resultList).hasSize(3); - assertThat(resultList).extracting("name") - .containsOnly("Infra", "Accounting", "Accounting"); - } - - @Test - public void whenLeftAndFetchKeywordsAreSpecified_ThenCreatesOuterFetchJoin() { - TypedQuery query = entityManager.createQuery("SELECT d FROM Department d LEFT JOIN FETCH d.employees", Department.class); - - List resultList = query.getResultList(); - - assertThat(resultList).hasSize(4); - assertThat(resultList).extracting("name") - .containsOnly("Infra", "Accounting", "Accounting", "Management"); - } - - @Test - public void whenCollectionValuedAssociationIsSpecifiedInSelect_ThenReturnsCollections() { - TypedQuery query = entityManager.createQuery("SELECT e.phones FROM Employee e", Collection.class); - - List resultList = query.getResultList(); - - assertThat(resultList).extracting("number").containsOnly("111", "222", "333"); - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java deleted file mode 100644 index 96eaf4ed07..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/projection/JpaProjectionIntegrationTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.baeldung.projection; - -import com.baeldung.projection.model.Person; -import com.baeldung.projection.repository.AddressRepository; -import com.baeldung.projection.repository.PersonRepository; -import com.baeldung.projection.view.AddressView; -import com.baeldung.projection.view.PersonDto; -import com.baeldung.projection.view.PersonView; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; - -@DataJpaTest -@RunWith(SpringRunner.class) -@Sql(scripts = "/projection-insert-data.sql") -@Sql(scripts = "/projection-clean-up-data.sql", executionPhase = AFTER_TEST_METHOD) -public class JpaProjectionIntegrationTest { - @Autowired - private AddressRepository addressRepository; - - @Autowired - private PersonRepository personRepository; - - @Test - public void whenUsingClosedProjections_thenViewWithRequiredPropertiesIsReturned() { - AddressView addressView = addressRepository.getAddressByState("CA").get(0); - assertThat(addressView.getZipCode()).isEqualTo("90001"); - - PersonView personView = addressView.getPerson(); - assertThat(personView.getFirstName()).isEqualTo("John"); - assertThat(personView.getLastName()).isEqualTo("Doe"); - } - - @Test - public void whenUsingOpenProjections_thenViewWithRequiredPropertiesIsReturned() { - PersonView personView = personRepository.findByLastName("Doe"); - assertThat(personView.getFullName()).isEqualTo("John Doe"); - } - - @Test - public void whenUsingClassBasedProjections_thenDtoWithRequiredPropertiesIsReturned() { - PersonDto personDto = personRepository.findByFirstName("John"); - assertThat(personDto.getFirstName()).isEqualTo("John"); - assertThat(personDto.getLastName()).isEqualTo("Doe"); - } - - @Test - public void whenUsingDynamicProjections_thenObjectWithRequiredPropertiesIsReturned() { - Person person = personRepository.findByLastName("Doe", Person.class); - PersonView personView = personRepository.findByLastName("Doe", PersonView.class); - PersonDto personDto = personRepository.findByLastName("Doe", PersonDto.class); - - assertThat(person.getFirstName()).isEqualTo("John"); - assertThat(personView.getFirstName()).isEqualTo("John"); - assertThat(personDto.getFirstName()).isEqualTo("John"); - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java deleted file mode 100644 index 5d6457ce30..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/CustomerRepositoryIntegrationTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.baeldung.repository; - -import com.baeldung.entity.Customer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -@DataJpaTest -@RunWith(SpringRunner.class) -public class CustomerRepositoryIntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private CustomerRepository repository; - - @Before - public void before() { - entityManager.persist(new Customer("A", "A@example.com")); - entityManager.persist(new Customer("D", null)); - entityManager.persist(new Customer("D", "D@example.com")); - } - - @Test - public void givenQueryMethod_whenEmailIsNull_thenFoundByNullEmail() { - List customers = repository.findByNameAndEmail("D", null); - - assertEquals(1, customers.size()); - Customer actual = customers.get(0); - - assertEquals(null, actual.getEmail()); - assertEquals("D", actual.getName()); - } - - @Test - public void givenQueryMethod_whenEmailIsAbsent_thenIgnoreEmail() { - List customers = repository.findByName("D"); - - assertEquals(2, customers.size()); - } - - @Test - public void givenQueryAnnotation_whenEmailIsNull_thenIgnoreEmail() { - List customers = repository.findCustomerByNameAndEmail("D", null); - - assertEquals(2, customers.size()); - } - - @After - public void cleanUp() { - repository.deleteAll(); - } -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitPopulatorIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitPopulatorIntegrationTest.java deleted file mode 100644 index 4d3661e717..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitPopulatorIntegrationTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.repository; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.entity.Fruit; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class FruitPopulatorIntegrationTest { - - @Autowired - private FruitRepository fruitRepository; - - @Test - public void givenFruitJsonPopulatorThenShouldInsertRecordOnStart() { - - List fruits = fruitRepository.findAll(); - assertEquals("record count is not matching", 2, fruits.size()); - - fruits.forEach(fruit -> { - if (1 == fruit.getId()) { - assertEquals("apple", fruit.getName()); - assertEquals("red", fruit.getColor()); - } else if (2 == fruit.getId()) { - assertEquals("guava", fruit.getName()); - assertEquals("green", fruit.getColor()); - } - }); - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitRepositoryIntegrationTest.java deleted file mode 100644 index cf771dc833..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/FruitRepositoryIntegrationTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.baeldung.repository; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.entity.Fruit; - -@RunWith(SpringRunner.class) -@SpringBootTest -class FruitRepositoryIntegrationTest { - - @Autowired - private FruitRepository fruitRepository; - - @Transactional - @Test - @Sql(scripts = { "/test-fruit-data.sql" }) - public void givenFruits_WhenDeletedByColor_ThenDeletedFruitsShouldReturn() { - - List fruits = fruitRepository.deleteByColor("green"); - - assertEquals("number of fruits are not matching", 2, fruits.size()); - fruits.forEach(fruit -> assertEquals("Its not a green fruit", "green", fruit.getColor())); - } - - @Transactional - @Test - @Sql(scripts = { "/test-fruit-data.sql" }) - public void givenFruits_WhenDeletedByName_ThenDeletedFruitCountShouldReturn() { - - Long deletedFruitCount = fruitRepository.deleteByName("apple"); - - assertEquals("deleted fruit count is not matching", 1, deletedFruitCount.intValue()); - } - - @Transactional - @Test - @Sql(scripts = { "/test-fruit-data.sql" }) - public void givenFruits_WhenRemovedByColor_ThenDeletedFruitsShouldReturn() { - - List fruits = fruitRepository.removeByColor("green"); - - assertEquals("number of fruits are not matching", 2, fruits.size()); - fruits.forEach(fruit -> assertEquals("Its not a green fruit", "green", fruit.getColor())); - } - - @Transactional - @Test - @Sql(scripts = { "/test-fruit-data.sql" }) - public void givenFruits_WhenRemovedByName_ThenDeletedFruitCountShouldReturn() { - - Long deletedFruitCount = fruitRepository.removeByName("apple"); - - assertEquals("deleted fruit count is not matching", 1, deletedFruitCount.intValue()); - } - - @Transactional - @Test - @Sql(scripts = { "/test-fruit-data.sql" }) - public void givenFruits_WhenDeletedByColorOrName_ThenDeletedFruitsShouldReturn() { - - int deletedCount = fruitRepository.deleteFruits("apple", "green"); - - assertEquals("number of fruits are not matching", 3, deletedCount); - } -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java deleted file mode 100644 index f96f0249d7..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/PassengerRepositoryIntegrationTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.baeldung.repository; - -import com.baeldung.entity.Passenger; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.core.IsNot.not; - -@DataJpaTest -@RunWith(SpringRunner.class) -public class PassengerRepositoryIntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - @Autowired - private PassengerRepository repository; - - @Before - public void before() { - entityManager.persist(Passenger.from("Jill", "Smith")); - entityManager.persist(Passenger.from("Eve", "Jackson")); - entityManager.persist(Passenger.from("Fred", "Bloggs")); - entityManager.persist(Passenger.from("Ricki", "Bobbie")); - entityManager.persist(Passenger.from("Siya", "Kolisi")); - } - - @Test - public void givenPassengers_whenMatchingIgnoreCase_thenExpectedReturned() { - Passenger jill = Passenger.from("Jill", "Smith"); - Passenger eve = Passenger.from("Eve", "Jackson"); - Passenger fred = Passenger.from("Fred", "Bloggs"); - Passenger siya = Passenger.from("Siya", "Kolisi"); - Passenger ricki = Passenger.from("Ricki", "Bobbie"); - - List passengers = repository.findByFirstNameIgnoreCase("FRED"); - - assertThat(passengers, contains(fred)); - assertThat(passengers, not(contains(eve))); - assertThat(passengers, not(contains(siya))); - assertThat(passengers, not(contains(jill))); - assertThat(passengers, not(contains(ricki))); - - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/SongRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/SongRepositoryIntegrationTest.java deleted file mode 100644 index 14912a4ecb..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/repository/SongRepositoryIntegrationTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.repository; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.entity.Song; - -@RunWith(SpringRunner.class) -@SpringBootTest -@Sql(scripts = { "/test-song-data.sql" }) -public class SongRepositoryIntegrationTest { - - @Autowired private SongRepository songRepository; - - @Transactional - @Test - public void givenSong_WhenFindLikeByName_ThenShouldReturnOne() { - List songs = songRepository.findByNameLike("Despacito"); - assertEquals(1, songs.size()); - } - - @Transactional - @Test - public void givenSong_WhenFindByNameNotLike_thenShouldReturn3Songs() { - List songs = songRepository.findByNameNotLike("Despacito"); - assertEquals(5, songs.size()); - } - - @Transactional - @Test - public void givenSong_WhenFindByNameStartingWith_thenShouldReturn2Songs() { - List songs = songRepository.findByNameStartingWith("Co"); - assertEquals(2, songs.size()); - } - - @Transactional - @Test - public void givenSong_WhenFindByNameEndingWith_thenShouldReturn2Songs() { - List songs = songRepository.findByNameEndingWith("Life"); - assertEquals(2, songs.size()); - } - - @Transactional - @Test - public void givenSong_WhenFindBySingerContaining_thenShouldReturn2Songs() { - List songs = songRepository.findBySingerContaining("Luis"); - assertEquals(2, songs.size()); - } -} diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/entitygraph-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/entitygraph-data.sql deleted file mode 100644 index 685ec2c605..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/resources/entitygraph-data.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO Item(id,name) VALUES (1,'Table'); -INSERT INTO Item(id,name) VALUES (2,'Bottle'); - -INSERT INTO Characteristic(id,item_id, type) VALUES (1,1,'Rigid'); -INSERT INTO Characteristic(id,item_id,type) VALUES (2,1,'Big'); -INSERT INTO Characteristic(id,item_id,type) VALUES (3,2,'Fragile'); -INSERT INTO Characteristic(id,item_id,type) VALUES (4,2,'Small'); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/projection-clean-up-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/projection-clean-up-data.sql deleted file mode 100644 index d34f6f0636..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/resources/projection-clean-up-data.sql +++ /dev/null @@ -1,2 +0,0 @@ -DELETE FROM address; -DELETE FROM person; \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/projection-insert-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/projection-insert-data.sql deleted file mode 100644 index 544dcc4b88..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/resources/projection-insert-data.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO person(id,first_name,last_name) VALUES (1,'John','Doe'); -INSERT INTO address(id,person_id,state,city,street,zip_code) VALUES (1,1,'CA', 'Los Angeles', 'Standford Ave', '90001'); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/test-aggregation-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/test-aggregation-data.sql deleted file mode 100644 index 12409a124e..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/resources/test-aggregation-data.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO post (id, title, content) VALUES (1, 'Comment 1', 'Content 1'); -INSERT INTO post (id, title, content) VALUES (2, 'Comment 2', 'Content 2'); -INSERT INTO post (id, title, content) VALUES (3, 'Comment 3', 'Content 3'); -INSERT INTO comment (id, year, approved, content, post_id) VALUES (1, 2019, false, 'Comment 1', 1); -INSERT INTO comment (id, year, approved, content, post_id) VALUES (2, 2018, true, 'Comment 2', 1); -INSERT INTO comment (id, year, approved, content, post_id) VALUES (3, 2018, true, 'Comment 3', 2); -INSERT INTO comment (id, year, approved, content, post_id) VALUES (4, 2017, false, 'Comment 4', 3); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/test-fruit-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/test-fruit-data.sql deleted file mode 100644 index d99f42e5a7..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/resources/test-fruit-data.sql +++ /dev/null @@ -1,6 +0,0 @@ -truncate table fruit; - -insert into fruit(id,name,color) values (1,'apple','red'); -insert into fruit(id,name,color) values (2,'custard apple','green'); -insert into fruit(id,name,color) values (3,'mango','yellow'); -insert into fruit(id,name,color) values (4,'guava','green'); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/resources/test-song-data.sql b/persistence-modules/spring-data-jpa-2/src/test/resources/test-song-data.sql deleted file mode 100644 index 5a2b1a5555..0000000000 --- a/persistence-modules/spring-data-jpa-2/src/test/resources/test-song-data.sql +++ /dev/null @@ -1,8 +0,0 @@ -INSERT INTO song(id,name,length_in_seconds,compositor,singer,released,genre) -VALUES -(1,'Despacito',209,'Luis Fonsi','Luis Fonsi, Daddy Yankee','2017-01-12','Reggaeton'), -(2,'Con calma',188,'Daddy Yankee','Daddy Yankee','2019-01-24','Reggaeton'), -(3,'It''s My Life',205,'Bon Jovi','Jon Bon Jovi','2000-05-23','Pop'), -(4,'Live is Life',242,'Opus','Opus','1985-01-01','Reggae'), -(5,'Countdown to Extinction',249,'Megadeth','Megadeth','1992-07-14','Heavy Metal'), -(6, 'Si nos dejan',139,'Luis Miguel','Luis Miguel','1995-10-17','Bolero'); \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-3/README.md b/persistence-modules/spring-data-jpa-3/README.md deleted file mode 100644 index bac52bf114..0000000000 --- a/persistence-modules/spring-data-jpa-3/README.md +++ /dev/null @@ -1,20 +0,0 @@ -### Relevant Articles: -- [Limiting Query Results with JPA and Spring Data JPA](https://www.baeldung.com/jpa-limit-query-results) -- [Sorting Query Results with Spring Data](https://www.baeldung.com/spring-data-sorting) -- [INSERT Statement in JPA](https://www.baeldung.com/jpa-insert) -- [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting) -- [Spring Data JPA Query by Example](https://www.baeldung.com/spring-data-query-by-example) -- [DB Integration Tests with Spring Boot and Testcontainers](https://www.baeldung.com/spring-boot-testcontainers-integration-test) -- [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation) -- [Spring Data JPA Batch Inserts](https://www.baeldung.com/spring-data-jpa-batch-inserts) -- [Batch Insert/Update with Hibernate/JPA](https://www.baeldung.com/jpa-hibernate-batch-insert-update) -- [Difference Between save() and saveAndFlush() in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-save-saveandflush) - -### Eclipse Config -After importing the project into Eclipse, you may see the following error: -"No persistence xml file found in project" - -This can be ignored: -- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" -Or: -- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator diff --git a/persistence-modules/spring-data-jpa-3/pom.xml b/persistence-modules/spring-data-jpa-3/pom.xml deleted file mode 100644 index d02d089ba3..0000000000 --- a/persistence-modules/spring-data-jpa-3/pom.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - 4.0.0 - spring-data-jpa-3 - spring-data-jpa-3 - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - - - com.google.guava - guava - ${guava.version} - - - com.h2database - h2 - - - net.ttddyy - datasource-proxy - ${datasource-proxy.version} - - - org.postgresql - postgresql - - - com.h2database - h2 - runtime - - - - - org.testcontainers - postgresql - ${testcontainers.version} - test - - - - - - 1.4.1 - 21.0 - 1.12.2 - - - diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/Application.java deleted file mode 100644 index ce10072031..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/Application.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; - -@SpringBootApplication -@EnableJpaRepositories -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java deleted file mode 100644 index 504357db44..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.batchinserts; - -import java.lang.reflect.Method; -import javax.sql.DataSource; -import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder; -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; -import org.springframework.aop.framework.ProxyFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Component; -import org.springframework.util.ReflectionUtils; - -@Component -@Profile("batchinserts") -public class DatasourceProxyBeanPostProcessor implements BeanPostProcessor { - - @Override - public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException { - return bean; - } - - @Override - public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { - if (bean instanceof DataSource) { - ProxyFactory factory = new ProxyFactory(bean); - factory.setProxyTargetClass(true); - factory.addAdvice(new ProxyDataSourceInterceptor((DataSource) bean)); - return factory.getProxy(); - } - - return bean; - } - - private static class ProxyDataSourceInterceptor implements MethodInterceptor { - - private final DataSource dataSource; - - public ProxyDataSourceInterceptor(final DataSource dataSource) { - this.dataSource = ProxyDataSourceBuilder.create(dataSource).name("Batch-Insert-Logger").asJson().countQuery().logQueryToSysOut().build(); - } - - @Override - public Object invoke(final MethodInvocation invocation) throws Throwable { - Method proxyMethod = ReflectionUtils.findMethod(dataSource.getClass(), invocation.getMethod().getName()); - if (proxyMethod != null) { - return proxyMethod.invoke(dataSource, invocation.getArguments()); - } - return invocation.proceed(); - } - } -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/model/School.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/model/School.java deleted file mode 100644 index 6d2f333ac7..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/model/School.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.batchinserts.model; - -import java.util.List; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToMany; - -@Entity -public class School { - - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE) - private long id; - - private String name; - - @OneToMany(mappedBy = "school") - private List students; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getStudents() { - return students; - } - - public void setStudents(List students) { - this.students = students; - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/model/Student.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/model/Student.java deleted file mode 100644 index d38214f122..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/batchinserts/model/Student.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.batchinserts.model; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.ManyToOne; - -@Entity -public class Student { - - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE) - private long id; - - private String name; - - @ManyToOne - private School school; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public School getSchool() { - return school; - } - - public void setSchool(School school) { - this.school = school; - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/Application.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/Application.java deleted file mode 100644 index aaca760499..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/Application.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.boot; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; - -@SpringBootApplication -@EnableJpaRepositories("com.baeldung") -@EntityScan("com.baeldung") -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/CustomerRepository.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/CustomerRepository.java deleted file mode 100644 index 7cb7e45b27..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/CustomerRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.boot.daos; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.boot.domain.Customer; - -/** - * JPA CrudRepository interface - * - * @author ysharma2512 - * - */ -@Repository -@Transactional -public interface CustomerRepository extends CrudRepository{ - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java deleted file mode 100644 index 373532e1c3..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/impl/PersonInsertRepository.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.boot.daos.impl; - -import org.springframework.stereotype.Repository; - -import com.baeldung.boot.domain.Person; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.transaction.Transactional; - -@Repository -public class PersonInsertRepository { - - @PersistenceContext - private EntityManager entityManager; - - @Transactional - public void insertWithQuery(Person person) { - entityManager.createNativeQuery("INSERT INTO person (id, first_name, last_name) VALUES (?,?,?)") - .setParameter(1, person.getId()) - .setParameter(2, person.getFirstName()) - .setParameter(3, person.getLastName()) - .executeUpdate(); - } - - @Transactional - public void insertWithEntityManager(Person person) { - this.entityManager.persist(person); - } - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepository.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepository.java deleted file mode 100644 index 53f692ff28..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepository.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.baeldung.boot.daos.user; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import com.baeldung.boot.domain.User; - -import java.time.LocalDate; -import java.util.Collection; -import java.util.List; -import java.util.stream.Stream; - -public interface UserRepository extends JpaRepository , UserRepositoryCustom{ - - Stream findAllByName(String name); - - @Query("SELECT u FROM User u WHERE u.status = 1") - Collection findAllActiveUsers(); - - @Query("select u from User u where u.email like '%@gmail.com'") - List findUsersWithGmailAddress(); - - @Query(value = "SELECT * FROM Users u WHERE u.status = 1", nativeQuery = true) - Collection findAllActiveUsersNative(); - - @Query("SELECT u FROM User u WHERE u.status = ?1") - User findUserByStatus(Integer status); - - @Query(value = "SELECT * FROM Users u WHERE u.status = ?1", nativeQuery = true) - User findUserByStatusNative(Integer status); - - @Query("SELECT u FROM User u WHERE u.status = ?1 and u.name = ?2") - User findUserByStatusAndName(Integer status, String name); - - @Query("SELECT u FROM User u WHERE u.status = :status and u.name = :name") - User findUserByStatusAndNameNamedParams(@Param("status") Integer status, @Param("name") String name); - - @Query(value = "SELECT * FROM Users u WHERE u.status = :status AND u.name = :name", nativeQuery = true) - User findUserByStatusAndNameNamedParamsNative(@Param("status") Integer status, @Param("name") String name); - - @Query("SELECT u FROM User u WHERE u.status = :status and u.name = :name") - User findUserByUserStatusAndUserName(@Param("status") Integer userStatus, @Param("name") String userName); - - @Query("SELECT u FROM User u WHERE u.name like ?1%") - User findUserByNameLike(String name); - - @Query("SELECT u FROM User u WHERE u.name like :name%") - User findUserByNameLikeNamedParam(@Param("name") String name); - - @Query(value = "SELECT * FROM users u WHERE u.name LIKE ?1%", nativeQuery = true) - User findUserByNameLikeNative(String name); - - @Query(value = "SELECT u FROM User u") - List findAllUsers(Sort sort); - - @Query(value = "SELECT u FROM User u ORDER BY id") - Page findAllUsersWithPagination(Pageable pageable); - - @Query(value = "SELECT * FROM Users ORDER BY id", countQuery = "SELECT count(*) FROM Users", nativeQuery = true) - Page findAllUsersWithPaginationNative(Pageable pageable); - - @Modifying - @Query("update User u set u.status = :status where u.name = :name") - int updateUserSetStatusForName(@Param("status") Integer status, @Param("name") String name); - - @Modifying - @Query(value = "UPDATE Users u SET u.status = ? WHERE u.name = ?", nativeQuery = true) - int updateUserSetStatusForNameNative(Integer status, String name); - - @Query(value = "INSERT INTO Users (name, age, email, status, active) VALUES (:name, :age, :email, :status, :active)", nativeQuery = true) - @Modifying - void insertUser(@Param("name") String name, @Param("age") Integer age, @Param("email") String email, @Param("status") Integer status, @Param("active") boolean active); - - @Modifying - @Query(value = "UPDATE Users u SET status = ? WHERE u.name = ?", nativeQuery = true) - int updateUserSetStatusForNameNativePostgres(Integer status, String name); - - @Query(value = "SELECT u FROM User u WHERE u.name IN :names") - List findUserByNameList(@Param("names") Collection names); - - void deleteAllByCreationDateAfter(LocalDate date); - - @Modifying(clearAutomatically = true, flushAutomatically = true) - @Query("update User u set u.active = false where u.lastLoginDate < :date") - void deactivateUsersNotLoggedInSince(@Param("date") LocalDate date); - - @Modifying(clearAutomatically = true, flushAutomatically = true) - @Query("delete User u where u.active = false") - int deleteDeactivatedUsers(); - - @Modifying(clearAutomatically = true, flushAutomatically = true) - @Query(value = "alter table USERS add column deleted int(1) not null default 0", nativeQuery = true) - void addDeletedColumn(); -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java deleted file mode 100644 index c586b54027..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.boot.daos.user; - -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; - -import com.baeldung.boot.domain.User; - -public interface UserRepositoryCustom { - List findUserByEmails(Set emails); - - List findAllUsersByPredicates(Collection> predicates); -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java deleted file mode 100644 index 63a743b6b5..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.baeldung.boot.daos.user; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Path; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - -import com.baeldung.boot.domain.User; - -public class UserRepositoryCustomImpl implements UserRepositoryCustom { - - @PersistenceContext - private EntityManager entityManager; - - @Override - public List findUserByEmails(Set emails) { - CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - CriteriaQuery query = cb.createQuery(User.class); - Root user = query.from(User.class); - - Path emailPath = user.get("email"); - - List predicates = new ArrayList<>(); - for (String email : emails) { - - predicates.add(cb.like(emailPath, email)); - - } - query.select(user) - .where(cb.or(predicates.toArray(new Predicate[predicates.size()]))); - - return entityManager.createQuery(query) - .getResultList(); - } - - @Override - public List findAllUsersByPredicates(Collection> predicates) { - List allUsers = entityManager.createQuery("select u from User u", User.class).getResultList(); - Stream allUsersStream = allUsers.stream(); - for (java.util.function.Predicate predicate : predicates) { - allUsersStream = allUsersStream.filter(predicate); - } - - return allUsersStream.collect(Collectors.toList()); - } - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Customer.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Customer.java deleted file mode 100644 index af88be0be6..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Customer.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -/** - * Customer Entity class - * @author ysharma2512 - * - */ -@Entity -public class Customer { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; - private String firstName; - private String lastName; - - public Customer(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - @Override - public String toString() { - return String.format("Customer[id=%d, firstName='%s', lastName='%s']", id, firstName, lastName); - } - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Person.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Person.java deleted file mode 100644 index 88894ccc72..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Person.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -public class Person { - - @Id - private Long id; - private String firstName; - private String lastName; - - public Person() { - } - - public Person(Long id, String firstName, String lastName) { - this.id = id; - this.firstName = firstName; - this.lastName = lastName; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Possession.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Possession.java deleted file mode 100644 index f13491ad82..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/Possession.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.*; -import com.baeldung.boot.domain.Possession; - -@Entity -@Table -public class Possession { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - private String name; - - public Possession() { - super(); - } - - public Possession(final String name) { - super(); - - this.name = name; - } - - public long getId() { - return id; - } - - public void setId(final int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + (int) (id ^ (id >>> 32)); - result = (prime * result) + ((name == null) ? 0 : name.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final Possession other = (Possession) obj; - if (id != other.id) { - return false; - } - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - return true; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("Possesion [id=").append(id).append(", name=").append(name).append("]"); - return builder.toString(); - } - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/User.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/User.java deleted file mode 100644 index cca00e52a2..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/domain/User.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.*; - -import java.time.LocalDate; -import java.util.List; -import java.util.Objects; - -@Entity -@Table(name = "users") -public class User { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private int id; - private String name; - private LocalDate creationDate; - private LocalDate lastLoginDate; - private boolean active; - private int age; - @Column(unique = true, nullable = false) - private String email; - private Integer status; - @OneToMany - List possessionList; - - public User() { - super(); - } - - public User(String name, LocalDate creationDate,String email, Integer status) { - this.name = name; - this.creationDate = creationDate; - this.email = email; - this.status = status; - this.active = true; - } - - public int getId() { - return id; - } - - public void setId(final int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public String getEmail() { - return email; - } - - public void setEmail(final String email) { - this.email = email; - } - - public Integer getStatus() { - return status; - } - - public void setStatus(Integer status) { - this.status = status; - } - - public int getAge() { - return age; - } - - public void setAge(final int age) { - this.age = age; - } - - public LocalDate getCreationDate() { - return creationDate; - } - - public List getPossessionList() { - return possessionList; - } - - public void setPossessionList(List possessionList) { - this.possessionList = possessionList; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("User [name=").append(name).append(", id=").append(id).append("]"); - return builder.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - User user = (User) o; - return id == user.id && - age == user.age && - Objects.equals(name, user.name) && - Objects.equals(creationDate, user.creationDate) && - Objects.equals(email, user.email) && - Objects.equals(status, user.status); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, creationDate, age, email, status); - } - - public LocalDate getLastLoginDate() { - return lastLoginDate; - } - - public void setLastLoginDate(LocalDate lastLoginDate) { - this.lastLoginDate = lastLoginDate; - } - - public boolean isActive() { - return active; - } - - public void setActive(boolean active) { - this.active = active; - } - -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java deleted file mode 100644 index 7152286c83..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/CustomPassengerRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.boot.passenger; - -import java.util.List; - -interface CustomPassengerRepository { - - List findOrderedBySeatNumberLimitedTo(int limit); -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/Passenger.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/Passenger.java deleted file mode 100644 index c75107a783..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/Passenger.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.baeldung.boot.passenger; - -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import java.util.Objects; - -@Entity -class Passenger { - - @Id - @GeneratedValue - @Column(nullable = false) - private Long id; - - @Basic(optional = false) - @Column(nullable = false) - private String firstName; - - @Basic(optional = false) - @Column(nullable = false) - private String lastName; - - @Basic(optional = false) - @Column(nullable = false) - private Integer seatNumber; - - private Passenger(String firstName, String lastName, Integer seatNumber) { - this.firstName = firstName; - this.lastName = lastName; - this.seatNumber = seatNumber; - } - - static Passenger from(String firstName, String lastName, Integer seatNumber) { - return new Passenger(firstName, lastName, seatNumber); - } - - @Override - public boolean equals(Object object) { - if (this == object) - return true; - if (object == null || getClass() != object.getClass()) - return false; - Passenger passenger = (Passenger) object; - return getSeatNumber() == passenger.getSeatNumber() && Objects.equals(getFirstName(), passenger.getFirstName()) - && Objects.equals(getLastName(), passenger.getLastName()); - } - - @Override - public int hashCode() { - return Objects.hash(getFirstName(), getLastName(), getSeatNumber()); - } - - @Override - public String toString() { - final StringBuilder toStringBuilder = new StringBuilder(getClass().getSimpleName()); - toStringBuilder.append("{ id=").append(id); - toStringBuilder.append(", firstName='").append(firstName).append('\''); - toStringBuilder.append(", lastName='").append(lastName).append('\''); - toStringBuilder.append(", seatNumber=").append(seatNumber); - toStringBuilder.append('}'); - return toStringBuilder.toString(); - } - - Long getId() { - return id; - } - - String getFirstName() { - return firstName; - } - - String getLastName() { - return lastName; - } - - Integer getSeatNumber() { - return seatNumber; - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java deleted file mode 100644 index 14d5403cb5..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/PassengerRepository.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.boot.passenger; - -import java.util.List; - -import org.springframework.data.domain.Sort; -import org.springframework.data.jpa.repository.JpaRepository; - -interface PassengerRepository extends JpaRepository, CustomPassengerRepository { - - Passenger findFirstByOrderBySeatNumberAsc(); - - Passenger findTopByOrderBySeatNumberAsc(); - - List findByOrderBySeatNumberAsc(); - - List findByFirstNameIgnoreCase(String firstName); - - List findByLastNameOrderBySeatNumberAsc(String lastName); - - List findByLastName(String lastName, Sort sort); - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java deleted file mode 100644 index 508c669066..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/passenger/PassengerRepositoryImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.boot.passenger; - -import org.springframework.stereotype.Repository; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import java.util.List; - -@Repository -class PassengerRepositoryImpl implements CustomPassengerRepository { - - @PersistenceContext - private EntityManager entityManager; - - @Override - public List findOrderedBySeatNumberLimitedTo(int limit) { - return entityManager.createQuery("SELECT p FROM Passenger p ORDER BY p.seatNumber", - Passenger.class).setMaxResults(limit).getResultList(); - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java deleted file mode 100644 index e13afd9b45..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/boot/web/controllers/CustomerController.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.boot.web.controllers; - -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.List; - -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.boot.daos.CustomerRepository; -import com.baeldung.boot.domain.Customer; - -/** - * A simple controller to test the JPA CrudRepository operations - * controllers - * - * @author ysharma2512 - * - */ -@RestController -public class CustomerController { - - CustomerRepository customerRepository; - - public CustomerController(CustomerRepository customerRepository2) { - this.customerRepository = customerRepository2; - } - - @PostMapping("/customers") - public ResponseEntity> insertCustomers() throws URISyntaxException { - Customer c1 = new Customer("James", "Gosling"); - Customer c2 = new Customer("Doug", "Lea"); - Customer c3 = new Customer("Martin", "Fowler"); - Customer c4 = new Customer("Brian", "Goetz"); - List customers = Arrays.asList(c1, c2, c3, c4); - customerRepository.saveAll(customers); - return ResponseEntity.ok(customers); - } - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/entity/Employee.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/entity/Employee.java deleted file mode 100644 index 4c3dbd25b7..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/entity/Employee.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.entity; - -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -public class Employee { - - @Id - private Long id; - private String name; - - public Employee() { - } - - public Employee(Long id, String name) { - this.id = id; - this.name = name; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/model/BasicUser.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/model/BasicUser.java deleted file mode 100644 index 2dc9c18cf6..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/model/BasicUser.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.model; - -import javax.persistence.*; -import java.util.Set; - -@Entity -@Table(name = "users") -public class BasicUser { - - @Id - @GeneratedValue - private Long id; - - private String username; - - @ElementCollection - private Set permissions; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public Set getPermissions() { - return permissions; - } - - public void setPermissions(Set permissions) { - this.permissions = permissions; - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java deleted file mode 100644 index 3b9aa2cc18..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.multipledb; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class MultipleDbApplication { - - public static void main(String[] args) { - SpringApplication.run(MultipleDbApplication.class, args); - } - -} - diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java deleted file mode 100644 index bcf2cd84eb..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.baeldung.multipledb; - -import com.google.common.base.Preconditions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.PlatformTransactionManager; - -import javax.sql.DataSource; -import java.util.HashMap; - -@Configuration -@PropertySource({"classpath:persistence-multiple-db.properties"}) -@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.product", entityManagerFactoryRef = "productEntityManager", transactionManagerRef = "productTransactionManager") -@Profile("!tc") -public class PersistenceProductConfiguration { - @Autowired - private Environment env; - - public PersistenceProductConfiguration() { - super(); - } - - // - - @Bean - public LocalContainerEntityManagerFactoryBean productEntityManager() { - final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); - em.setDataSource(productDataSource()); - em.setPackagesToScan("com.baeldung.multipledb.model.product"); - - final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); - em.setJpaVendorAdapter(vendorAdapter); - final HashMap properties = new HashMap(); - properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); - em.setJpaPropertyMap(properties); - - return em; - } - - @Bean - public DataSource productDataSource() { - final DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); - dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("product.jdbc.url"))); - dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); - dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); - - return dataSource; - } - - @Bean - public PlatformTransactionManager productTransactionManager() { - final JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(productEntityManager().getObject()); - return transactionManager; - } - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java deleted file mode 100644 index 6ce9bcad45..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.multipledb.dao.product; - -import java.util.List; - -import org.springframework.data.domain.Pageable; -import org.springframework.data.repository.PagingAndSortingRepository; - -import com.baeldung.multipledb.model.product.Product; - -public interface ProductRepository extends PagingAndSortingRepository { - - List findAllByPrice(double price, Pageable pageable); -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/model/product/Product.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/model/product/Product.java deleted file mode 100644 index eaf471043c..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/model/product/Product.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung.multipledb.model.product; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(schema = "products") -public class Product { - - @Id - private int id; - - private String name; - - private double price; - - public Product() { - super(); - } - - private Product(int id, String name, double price) { - super(); - this.id = id; - this.name = name; - this.price = price; - } - - public static Product from(int id, String name, double price) { - return new Product(id, name, price); - } - - public int getId() { - return id; - } - - public void setId(final int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public double getPrice() { - return price; - } - - public void setPrice(final double price) { - this.price = price; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("Product [name=") - .append(name) - .append(", id=") - .append(id) - .append("]"); - return builder.toString(); - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/EmployeeRepository.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/EmployeeRepository.java deleted file mode 100644 index 8f0a80814b..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/EmployeeRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.repository; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.baeldung.entity.Employee; - -public interface EmployeeRepository extends JpaRepository { - -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/UserRepository.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/UserRepository.java deleted file mode 100644 index f683be402f..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/repository/UserRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.repository; - -import java.util.Optional; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.baeldung.model.BasicUser; - -public interface UserRepository extends JpaRepository { - - Optional findSummaryByUsername(String username); - - Optional findByUsername(String username); -} diff --git a/persistence-modules/spring-data-jpa-3/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-3/src/main/resources/application.properties deleted file mode 100644 index f127dd5e50..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.main.allow-bean-definition-overriding=true - -spring.jpa.properties.hibernate.jdbc.batch_size=4 -spring.jpa.properties.hibernate.order_inserts=true -spring.jpa.properties.hibernate.order_updates=true -spring.jpa.properties.hibernate.generate_statistics=true diff --git a/persistence-modules/spring-data-jpa-3/src/main/resources/logback.xml b/persistence-modules/spring-data-jpa-3/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-3/src/main/resources/persistence-multiple-db.properties b/persistence-modules/spring-data-jpa-3/src/main/resources/persistence-multiple-db.properties deleted file mode 100644 index 75534e8a54..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/main/resources/persistence-multiple-db.properties +++ /dev/null @@ -1,13 +0,0 @@ -# jdbc.X -jdbc.driverClassName=org.h2.Driver -user.jdbc.url=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS -product.jdbc.url=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS -jdbc.user=sa -jdbc.pass=sa - -# hibernate.X -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=false -hibernate.hbm2ddl.auto=create-drop -hibernate.cache.use_second_level_cache=false -hibernate.cache.use_query_cache=false \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/SpringContextTest.java deleted file mode 100644 index eaccf4acba..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/SpringContextTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.Application; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -public class SpringContextTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java deleted file mode 100644 index 27c71c5bcc..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.Application; - -@RunWith(SpringRunner.class) -@DataJpaTest -@ContextConfiguration(classes = Application.class) -public class SpringJpaContextIntegrationTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java deleted file mode 100644 index 7ddf36d3f0..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.batchinserts; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import com.baeldung.boot.Application; -import com.baeldung.boot.daos.CustomerRepository; -import com.baeldung.boot.web.controllers.CustomerController; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes=Application.class) -@AutoConfigureMockMvc -public class BatchInsertIntegrationTest { - - @Autowired - private CustomerRepository customerRepository; - private MockMvc mockMvc; - @Before - public void setUp() throws Exception { - mockMvc = MockMvcBuilders.standaloneSetup( new CustomerController(customerRepository)) - .build(); - } - - @Test - public void whenInsertingCustomers_thenCustomersAreCreated() throws Exception { - this.mockMvc.perform(post("/customers")) - .andExpect(status().isOk()); - } - -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java deleted file mode 100644 index 311f227322..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.baeldung.batchinserts; - -import static com.baeldung.batchinserts.TestObjectHelper.createSchool; -import static com.baeldung.batchinserts.TestObjectHelper.createStudent; - -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.TypedQuery; - -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.batchinserts.model.School; -import com.baeldung.batchinserts.model.Student; -import com.baeldung.boot.Application; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -@Transactional -@ActiveProfiles("batchinserts") -public class JpaBatchInsertsIntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - - private static final int BATCH_SIZE = 5; - - @Transactional - @Test - public void whenInsertingSingleTypeOfEntity_thenCreatesSingleBatch() { - for (int i = 0; i < 10; i++) { - School school = createSchool(i); - entityManager.persist(school); - } - } - - @Transactional - @Test - public void whenFlushingAfterBatch_ThenClearsMemory() { - for (int i = 0; i < 10; i++) { - if (i > 0 && i % BATCH_SIZE == 0) { - entityManager.flush(); - entityManager.clear(); - } - - School school = createSchool(i); - entityManager.persist(school); - } - } - - @Transactional - @Test - public void whenThereAreMultipleEntities_ThenCreatesNewBatch() { - for (int i = 0; i < 10; i++) { - if (i > 0 && i % BATCH_SIZE == 0) { - entityManager.flush(); - entityManager.clear(); - } - - School school = createSchool(i); - entityManager.persist(school); - Student firstStudent = createStudent(school); - Student secondStudent = createStudent(school); - entityManager.persist(firstStudent); - entityManager.persist(secondStudent); - } - } - - @Transactional - @Test - public void whenUpdatingEntities_thenCreatesBatch() { - for (int i = 0; i < 10; i++) { - School school = createSchool(i); - entityManager.persist(school); - } - - entityManager.flush(); - - TypedQuery schoolQuery = entityManager.createQuery("SELECT s from School s", School.class); - List allSchools = schoolQuery.getResultList(); - - for (School school : allSchools) { - school.setName("Updated_" + school.getName()); - } - } - - @After - public void tearDown() { - entityManager.flush(); - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java deleted file mode 100644 index 75b3f1f3aa..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.batchinserts; - -import static com.baeldung.batchinserts.TestObjectHelper.createSchool; - -import com.baeldung.batchinserts.model.School; -import com.baeldung.boot.Application; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -@Transactional -@ActiveProfiles("batchinserts") -@TestPropertySource(properties = "spring.jpa.properties.hibernate.jdbc.batch_size=-1") -public class JpaNoBatchInsertsIntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - - @Test - public void whenNotConfigured_ThenSendsInsertsSeparately() { - for (int i = 0; i < 10; i++) { - School school = createSchool(i); - entityManager.persist(school); - } - } - - @After - public void tearDown() { - entityManager.flush(); - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java deleted file mode 100644 index fcd26cb721..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.batchinserts; - -import com.baeldung.batchinserts.model.School; -import com.baeldung.batchinserts.model.Student; - -public class TestObjectHelper { - - public static School createSchool(int nameIdentifier) { - School school = new School(); - school.setName("School" + (nameIdentifier + 1)); - return school; - } - - public static Student createStudent(School school) { - Student student = new Student(); - student.setName("Student-" + school.getName()); - student.setSchool(school); - return student; - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java deleted file mode 100644 index 9d45c17035..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/PersonInsertRepositoryIntegrationTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.baeldung.boot.daos; - -import com.baeldung.boot.daos.impl.PersonInsertRepository; -import com.baeldung.boot.domain.Person; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.persistence.EntityExistsException; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceException; - -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -@RunWith(SpringRunner.class) -@DataJpaTest -@Import(PersonInsertRepository.class) -public class PersonInsertRepositoryIntegrationTest { - - private static final Long ID = 1L; - private static final String FIRST_NAME = "firstname"; - private static final String LAST_NAME = "lastname"; - private static final Person PERSON = new Person(ID, FIRST_NAME, LAST_NAME); - - @Autowired - private PersonInsertRepository personInsertRepository; - - @Autowired - private EntityManager entityManager; - - @Test - public void givenPersonEntity_whenInsertWithNativeQuery_ThenPersonIsPersisted() { - insertWithQuery(); - - assertPersonPersisted(); - } - - @Test - public void givenPersonEntity_whenInsertedTwiceWithNativeQuery_thenPersistenceExceptionExceptionIsThrown() { - assertThatExceptionOfType(PersistenceException.class).isThrownBy(() -> { - insertWithQuery(); - insertWithQuery(); - }); - } - - @Test - public void givenPersonEntity_whenInsertWithEntityManager_thenPersonIsPersisted() { - insertPersonWithEntityManager(); - - assertPersonPersisted(); - } - - @Test - public void givenPersonEntity_whenInsertedTwiceWithEntityManager_thenEntityExistsExceptionIsThrown() { - assertThatExceptionOfType(EntityExistsException.class).isThrownBy(() -> { - insertPersonWithEntityManager(); - insertPersonWithEntityManager(); - }); - } - - private void insertWithQuery() { - personInsertRepository.insertWithQuery(PERSON); - } - - private void insertPersonWithEntityManager() { - personInsertRepository.insertWithEntityManager(new Person(ID, FIRST_NAME, LAST_NAME)); - } - - private void assertPersonPersisted() { - Person person = entityManager.find(Person.class, ID); - - assertThat(person).isNotNull(); - assertThat(person.getId()).isEqualTo(PERSON.getId()); - assertThat(person.getFirstName()).isEqualTo(PERSON.getFirstName()); - assertThat(person.getLastName()).isEqualTo(PERSON.getLastName()); - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java deleted file mode 100644 index b2581b8034..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java +++ /dev/null @@ -1,545 +0,0 @@ -package com.baeldung.boot.daos; - -import org.junit.After; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.data.jpa.domain.JpaSort; -import org.springframework.data.mapping.PropertyReferenceException; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.boot.daos.user.UserRepository; -import com.baeldung.boot.domain.User; - -import javax.persistence.EntityManager; -import javax.persistence.Query; -import java.time.LocalDate; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; - -public class UserRepositoryCommon { - - final String USER_EMAIL = "email@example.com"; - final String USER_EMAIL2 = "email2@example.com"; - final String USER_EMAIL3 = "email3@example.com"; - final String USER_EMAIL4 = "email4@example.com"; - final Integer INACTIVE_STATUS = 0; - final Integer ACTIVE_STATUS = 1; - final String USER_EMAIL5 = "email5@example.com"; - final String USER_EMAIL6 = "email6@example.com"; - final String USER_NAME_ADAM = "Adam"; - final String USER_NAME_PETER = "Peter"; - - @Autowired - protected UserRepository userRepository; - @Autowired - private EntityManager entityManager; - - @Test - @Transactional - public void givenUsersWithSameNameInDB_WhenFindAllByName_ThenReturnStreamOfUsers() { - User user1 = new User(); - user1.setName(USER_NAME_ADAM); - user1.setEmail(USER_EMAIL); - userRepository.save(user1); - - User user2 = new User(); - user2.setName(USER_NAME_ADAM); - user2.setEmail(USER_EMAIL2); - userRepository.save(user2); - - User user3 = new User(); - user3.setName(USER_NAME_ADAM); - user3.setEmail(USER_EMAIL3); - userRepository.save(user3); - - User user4 = new User(); - user4.setName("SAMPLE"); - user4.setEmail(USER_EMAIL4); - userRepository.save(user4); - - try (Stream foundUsersStream = userRepository.findAllByName(USER_NAME_ADAM)) { - assertThat(foundUsersStream.count()).isEqualTo(3l); - } - } - - @Test - public void givenUsersInDB_WhenFindAllWithQueryAnnotation_ThenReturnCollectionWithActiveUsers() { - User user1 = new User(); - user1.setName(USER_NAME_ADAM); - user1.setEmail(USER_EMAIL); - user1.setStatus(ACTIVE_STATUS); - userRepository.save(user1); - - User user2 = new User(); - user2.setName(USER_NAME_ADAM); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User user3 = new User(); - user3.setName(USER_NAME_ADAM); - user3.setEmail(USER_EMAIL3); - user3.setStatus(INACTIVE_STATUS); - userRepository.save(user3); - - Collection allActiveUsers = userRepository.findAllActiveUsers(); - - assertThat(allActiveUsers.size()).isEqualTo(2); - } - - @Test - public void givenUsersInDB_WhenFindAllWithQueryAnnotationNative_ThenReturnCollectionWithActiveUsers() { - User user1 = new User(); - user1.setName(USER_NAME_ADAM); - user1.setEmail(USER_EMAIL); - user1.setStatus(ACTIVE_STATUS); - userRepository.save(user1); - - User user2 = new User(); - user2.setName(USER_NAME_ADAM); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User user3 = new User(); - user3.setName(USER_NAME_ADAM); - user3.setEmail(USER_EMAIL3); - user3.setStatus(INACTIVE_STATUS); - userRepository.save(user3); - - Collection allActiveUsers = userRepository.findAllActiveUsersNative(); - - assertThat(allActiveUsers.size()).isEqualTo(2); - } - - @Test - public void givenUserInDB_WhenFindUserByStatusWithQueryAnnotation_ThenReturnActiveUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByStatus(ACTIVE_STATUS); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUserInDB_WhenFindUserByStatusWithQueryAnnotationNative_ThenReturnActiveUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByStatusNative(ACTIVE_STATUS); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationIndexedParams_ThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByStatusAndName(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationNamedParams_ThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByStatusAndNameNamedParams(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationNativeNamedParams_ThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByStatusAndNameNamedParamsNative(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationNamedParamsCustomNames_ThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByUserStatusAndUserName(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByNameLikeWithQueryAnnotationIndexedParams_ThenReturnUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByNameLike("Ad"); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByNameLikeWithQueryAnnotationNamedParams_ThenReturnUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByNameLikeNamedParam("Ad"); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByNameLikeWithQueryAnnotationNative_ThenReturnUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByNameLikeNative("Ad"); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindAllWithSortByName_ThenReturnUsersSorted() { - userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); - - List usersSortByName = userRepository.findAll(Sort.by(Sort.Direction.ASC, "name")); - - assertThat(usersSortByName.get(0) - .getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test(expected = PropertyReferenceException.class) - public void givenUsersInDB_WhenFindAllSortWithFunction_ThenThrowException() { - userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); - - userRepository.findAll(Sort.by(Sort.Direction.ASC, "name")); - - List usersSortByNameLength = userRepository.findAll(Sort.by("LENGTH(name)")); - - assertThat(usersSortByNameLength.get(0) - .getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindAllSortWithFunctionQueryAnnotationJPQL_ThenReturnUsersSorted() { - userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); - - userRepository.findAllUsers(Sort.by("name")); - - List usersSortByNameLength = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)")); - - assertThat(usersSortByNameLength.get(0) - .getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindAllWithPageRequestQueryAnnotationJPQL_ThenReturnPageOfUsers() { - userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL4, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE2", LocalDate.now(), USER_EMAIL5, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL6, INACTIVE_STATUS)); - - Page usersPage = userRepository.findAllUsersWithPagination(PageRequest.of(1, 3)); - - assertThat(usersPage.getContent() - .get(0) - .getName()).isEqualTo("SAMPLE1"); - } - - @Test - public void givenUsersInDB_WhenFindAllWithPageRequestQueryAnnotationNative_ThenReturnPageOfUsers() { - userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL4, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE2", LocalDate.now(), USER_EMAIL5, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL6, INACTIVE_STATUS)); - - Page usersSortByNameLength = userRepository.findAllUsersWithPaginationNative(PageRequest.of(1, 3)); - - assertThat(usersSortByNameLength.getContent() - .get(0) - .getName()).isEqualTo(USER_NAME_PETER); - } - - @Test - @Transactional - public void givenUsersInDB_WhenUpdateStatusForNameModifyingQueryAnnotationJPQL_ThenModifyMatchingUsers() { - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); - - int updatedUsersSize = userRepository.updateUserSetStatusForName(INACTIVE_STATUS, "SAMPLE"); - - assertThat(updatedUsersSize).isEqualTo(2); - } - - @Test - public void givenUsersInDB_WhenFindByEmailsWithDynamicQuery_ThenReturnCollection() { - - User user1 = new User(); - user1.setEmail(USER_EMAIL); - userRepository.save(user1); - - User user2 = new User(); - user2.setEmail(USER_EMAIL2); - userRepository.save(user2); - - User user3 = new User(); - user3.setEmail(USER_EMAIL3); - userRepository.save(user3); - - Set emails = new HashSet<>(); - emails.add(USER_EMAIL2); - emails.add(USER_EMAIL3); - - Collection usersWithEmails = userRepository.findUserByEmails(emails); - - assertThat(usersWithEmails.size()).isEqualTo(2); - } - - @Test - public void givenUsersInDBWhenFindByNameListReturnCollection() { - - User user1 = new User(); - user1.setName(USER_NAME_ADAM); - user1.setEmail(USER_EMAIL); - userRepository.save(user1); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setEmail(USER_EMAIL2); - userRepository.save(user2); - - List names = Arrays.asList(USER_NAME_ADAM, USER_NAME_PETER); - - List usersWithNames = userRepository.findUserByNameList(names); - - assertThat(usersWithNames.size()).isEqualTo(2); - } - - - @Test - @Transactional - public void whenInsertedWithQuery_ThenUserIsPersisted() { - userRepository.insertUser(USER_NAME_ADAM, 1, USER_EMAIL, ACTIVE_STATUS, true); - userRepository.insertUser(USER_NAME_PETER, 1, USER_EMAIL2, ACTIVE_STATUS, true); - - User userAdam = userRepository.findUserByNameLike(USER_NAME_ADAM); - User userPeter = userRepository.findUserByNameLike(USER_NAME_PETER); - - assertThat(userAdam).isNotNull(); - assertThat(userAdam.getEmail()).isEqualTo(USER_EMAIL); - assertThat(userPeter).isNotNull(); - assertThat(userPeter.getEmail()).isEqualTo(USER_EMAIL2); - } - - - @Test - @Transactional - public void givenTwoUsers_whenFindByNameUsr01_ThenUserUsr01() { - User usr01 = new User("usr01", LocalDate.now(), "usr01@baeldung.com", 1); - User usr02 = new User("usr02", LocalDate.now(), "usr02@baeldung.com", 1); - - userRepository.save(usr01); - userRepository.save(usr02); - - try (Stream users = userRepository.findAllByName("usr01")) { - assertTrue(users.allMatch(usr -> usr.equals(usr01))); - } - } - - @Test - @Transactional - public void givenTwoUsers_whenFindByNameUsr00_ThenNoUsers() { - User usr01 = new User("usr01", LocalDate.now(), "usr01@baeldung.com", 1); - User usr02 = new User("usr02", LocalDate.now(), "usr02@baeldung.com", 1); - - userRepository.save(usr01); - userRepository.save(usr02); - - try (Stream users = userRepository.findAllByName("usr00")) { - assertEquals(0, users.count()); - } - } - - @Test - public void givenTwoUsers_whenFindUsersWithGmailAddress_ThenUserUsr02() { - User usr01 = new User("usr01", LocalDate.now(), "usr01@baeldung.com", 1); - User usr02 = new User("usr02", LocalDate.now(), "usr02@gmail.com", 1); - - userRepository.save(usr01); - userRepository.save(usr02); - - List users = userRepository.findUsersWithGmailAddress(); - assertEquals(1, users.size()); - assertEquals(usr02, users.get(0)); - } - - @Test - @Transactional - public void givenTwoUsers_whenDeleteAllByCreationDateAfter_ThenOneUserRemains() { - User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); - User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.com", 1); - - userRepository.save(usr01); - userRepository.save(usr02); - - userRepository.deleteAllByCreationDateAfter(LocalDate.of(2018, 5, 1)); - - List users = userRepository.findAll(); - - assertEquals(1, users.size()); - assertEquals(usr01, users.get(0)); - } - - @Test - public void givenTwoUsers_whenFindAllUsersByPredicates_ThenUserUsr01() { - User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); - User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.org", 1); - - userRepository.save(usr01); - userRepository.save(usr02); - - List> predicates = new ArrayList<>(); - predicates.add(usr -> usr.getCreationDate().isAfter(LocalDate.of(2017, 12, 31))); - predicates.add(usr -> usr.getEmail().endsWith(".com")); - - List users = userRepository.findAllUsersByPredicates(predicates); - - assertEquals(1, users.size()); - assertEquals(usr01, users.get(0)); - } - - @Test - @Transactional - public void givenTwoUsers_whenDeactivateUsersNotLoggedInSince_ThenUserUsr02Deactivated() { - User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); - usr01.setLastLoginDate(LocalDate.now()); - User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.org", 1); - usr02.setLastLoginDate(LocalDate.of(2018, 7, 20)); - - userRepository.save(usr01); - userRepository.save(usr02); - - userRepository.deactivateUsersNotLoggedInSince(LocalDate.of(2018, 8, 1)); - - List users = userRepository.findAllUsers(Sort.by(Sort.Order.asc("name"))); - assertTrue(users.get(0).isActive()); - assertFalse(users.get(1).isActive()); - } - - @Test - @Transactional - public void givenTwoUsers_whenDeleteDeactivatedUsers_ThenUserUsr02Deleted() { - User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); - usr01.setLastLoginDate(LocalDate.now()); - User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.com", 0); - usr02.setLastLoginDate(LocalDate.of(2018, 7, 20)); - usr02.setActive(false); - - userRepository.save(usr01); - userRepository.save(usr02); - - int deletedUsersCount = userRepository.deleteDeactivatedUsers(); - - List users = userRepository.findAll(); - assertEquals(1, users.size()); - assertEquals(usr01, users.get(0)); - assertEquals(1, deletedUsersCount); - } - - @Test - @Transactional - public void givenTwoUsers_whenAddDeletedColumn_ThenUsersHaveDeletedColumn() { - User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); - usr01.setLastLoginDate(LocalDate.now()); - User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.org", 1); - usr02.setLastLoginDate(LocalDate.of(2018, 7, 20)); - usr02.setActive(false); - - userRepository.save(usr01); - userRepository.save(usr02); - - userRepository.addDeletedColumn(); - - Query nativeQuery = entityManager.createNativeQuery("select deleted from USERS where NAME = 'usr01'"); - assertEquals(0, nativeQuery.getResultList().get(0)); - } - - @After - public void cleanUp() { - userRepository.deleteAll(); - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java deleted file mode 100644 index 99eabc8271..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.boot.daos; - -import com.baeldung.boot.Application; -import com.baeldung.boot.domain.User; -import com.baeldung.util.BaeldungPostgresqlContainer; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; -import org.testcontainers.containers.PostgreSQLContainer; - -import java.time.LocalDate; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Created by adam. - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -@ActiveProfiles({"tc", "tc-auto"}) -public class UserRepositoryTCAutoLiveTest extends UserRepositoryCommon { - - @ClassRule - public static PostgreSQLContainer postgreSQLContainer = BaeldungPostgresqlContainer.getInstance(); - - @Test - @Transactional - public void givenUsersInDB_WhenUpdateStatusForNameModifyingQueryAnnotationNativePostgres_ThenModifyMatchingUsers() { - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); - userRepository.flush(); - - int updatedUsersSize = userRepository.updateUserSetStatusForNameNativePostgres(INACTIVE_STATUS, "SAMPLE"); - - assertThat(updatedUsersSize).isEqualTo(2); - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java deleted file mode 100644 index be8843c166..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.boot.daos; - -import com.baeldung.boot.Application; -import com.baeldung.boot.domain.User; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.util.TestPropertyValues; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; -import org.testcontainers.containers.PostgreSQLContainer; - -import java.time.LocalDate; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -@ActiveProfiles("tc") -@ContextConfiguration(initializers = {UserRepositoryTCLiveTest.Initializer.class}) -public class UserRepositoryTCLiveTest extends UserRepositoryCommon { - - @ClassRule - public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:11.1") - .withDatabaseName("integration-tests-db") - .withUsername("sa") - .withPassword("sa"); - - @Test - @Transactional - public void givenUsersInDB_WhenUpdateStatusForNameModifyingQueryAnnotationNative_ThenModifyMatchingUsers() { - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); - userRepository.flush(); - - int updatedUsersSize = userRepository.updateUserSetStatusForNameNativePostgres(INACTIVE_STATUS, "SAMPLE"); - - assertThat(updatedUsersSize).isEqualTo(2); - } - - static class Initializer - implements ApplicationContextInitializer { - public void initialize(ConfigurableApplicationContext configurableApplicationContext) { - TestPropertyValues.of( - "spring.datasource.url=" + postgreSQLContainer.getJdbcUrl(), - "spring.datasource.username=" + postgreSQLContainer.getUsername(), - "spring.datasource.password=" + postgreSQLContainer.getPassword() - ).applyTo(configurableApplicationContext.getEnvironment()); - } - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java deleted file mode 100644 index f082350019..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/boot/passenger/PassengerRepositoryIntegrationTest.java +++ /dev/null @@ -1,190 +0,0 @@ -package com.baeldung.boot.passenger; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.data.domain.Example; -import org.springframework.data.domain.ExampleMatcher; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.passenger.Passenger; -import com.baeldung.boot.passenger.PassengerRepository; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import java.util.List; -import java.util.Optional; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - - -@DataJpaTest -@RunWith(SpringRunner.class) -public class PassengerRepositoryIntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - @Autowired - private PassengerRepository repository; - - @Before - public void before() { - entityManager.persist(Passenger.from("Jill", "Smith", 50)); - entityManager.persist(Passenger.from("Eve", "Jackson", 95)); - entityManager.persist(Passenger.from("Fred", "Bloggs", 22)); - entityManager.persist(Passenger.from("Ricki", "Bobbie", 36)); - entityManager.persist(Passenger.from("Siya", "Kolisi", 85)); - } - - @Test - public void givenSeveralPassengersWhenOrderedBySeatNumberLimitedToThenThePassengerInTheFirstFilledSeatIsReturned() { - Passenger expected = Passenger.from("Fred", "Bloggs", 22); - - List passengers = repository.findOrderedBySeatNumberLimitedTo(1); - - assertEquals(1, passengers.size()); - - Passenger actual = passengers.get(0); - assertEquals(expected, actual); - } - - @Test - public void givenSeveralPassengersWhenFindFirstByOrderBySeatNumberAscThenThePassengerInTheFirstFilledSeatIsReturned() { - Passenger expected = Passenger.from("Fred", "Bloggs", 22); - - Passenger actual = repository.findFirstByOrderBySeatNumberAsc(); - - assertEquals(expected, actual); - } - - @Test - public void givenSeveralPassengersWhenFindPageSortedByThenThePassengerInTheFirstFilledSeatIsReturned() { - Passenger expected = Passenger.from("Fred", "Bloggs", 22); - - Page page = repository.findAll(PageRequest.of(0, 1, - Sort.by(Sort.Direction.ASC, "seatNumber"))); - - assertEquals(1, page.getContent().size()); - - Passenger actual = page.getContent().get(0); - assertEquals(expected, actual); - } - - @Test - public void givenPassengers_whenOrderedBySeatNumberAsc_thenCorrectOrder() { - Passenger fred = Passenger.from("Fred", "Bloggs", 22); - Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); - Passenger jill = Passenger.from("Jill", "Smith", 50); - Passenger siya = Passenger.from("Siya", "Kolisi", 85); - Passenger eve = Passenger.from("Eve", "Jackson", 95); - - List passengers = repository.findByOrderBySeatNumberAsc(); - - assertThat(passengers, contains(fred, ricki, jill, siya, eve)); - } - - @Test - public void givenPassengers_whenFindAllWithSortBySeatNumberAsc_thenCorrectOrder() { - Passenger fred = Passenger.from("Fred", "Bloggs", 22); - Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); - Passenger jill = Passenger.from("Jill", "Smith", 50); - Passenger siya = Passenger.from("Siya", "Kolisi", 85); - Passenger eve = Passenger.from("Eve", "Jackson", 95); - - List passengers = repository.findAll(Sort.by(Sort.Direction.ASC, "seatNumber")); - - assertThat(passengers, contains(fred, ricki, jill, siya, eve)); - } - - @Test - public void givenPassengers_whenFindByExampleDefaultMatcher_thenExpectedReturned() { - Example example = Example.of(Passenger.from("Fred", "Bloggs", null)); - - Optional actual = repository.findOne(example); - - assertTrue(actual.isPresent()); - assertEquals(Passenger.from("Fred", "Bloggs", 22), actual.get()); - } - - @Test - public void givenPassengers_whenFindByExampleCaseInsensitiveMatcher_thenExpectedReturned() { - ExampleMatcher caseInsensitiveExampleMatcher = ExampleMatcher.matchingAll().withIgnoreCase(); - Example example = Example.of(Passenger.from("fred", "bloggs", null), - caseInsensitiveExampleMatcher); - - Optional actual = repository.findOne(example); - - assertTrue(actual.isPresent()); - assertEquals(Passenger.from("Fred", "Bloggs", 22), actual.get()); - } - - @Test - public void givenPassengers_whenFindByExampleCustomMatcher_thenExpectedReturned() { - Passenger jill = Passenger.from("Jill", "Smith", 50); - Passenger eve = Passenger.from("Eve", "Jackson", 95); - Passenger fred = Passenger.from("Fred", "Bloggs", 22); - Passenger siya = Passenger.from("Siya", "Kolisi", 85); - Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); - - ExampleMatcher customExampleMatcher = ExampleMatcher.matchingAny().withMatcher("firstName", - ExampleMatcher.GenericPropertyMatchers.contains().ignoreCase()).withMatcher("lastName", - ExampleMatcher.GenericPropertyMatchers.contains().ignoreCase()); - - Example example = Example.of(Passenger.from("e", "s", null), - customExampleMatcher); - - List passengers = repository.findAll(example); - - assertThat(passengers, contains(jill, eve, fred, siya)); - assertThat(passengers, not(contains(ricki))); - } - - @Test - public void givenPassengers_whenFindByIgnoringMatcher_thenExpectedReturned() { - Passenger jill = Passenger.from("Jill", "Smith", 50); - Passenger eve = Passenger.from("Eve", "Jackson", 95); - Passenger fred = Passenger.from("Fred", "Bloggs", 22); - Passenger siya = Passenger.from("Siya", "Kolisi", 85); - Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); - - ExampleMatcher ignoringExampleMatcher = ExampleMatcher.matchingAny().withMatcher("lastName", - ExampleMatcher.GenericPropertyMatchers.startsWith().ignoreCase()).withIgnorePaths("firstName", "seatNumber"); - - Example example = Example.of(Passenger.from(null, "b", null), - ignoringExampleMatcher); - - List passengers = repository.findAll(example); - - assertThat(passengers, contains(fred, ricki)); - assertThat(passengers, not(contains(jill))); - assertThat(passengers, not(contains(eve))); - assertThat(passengers, not(contains(siya))); - } - - @Test - public void givenPassengers_whenMatchingIgnoreCase_thenExpectedReturned() { - Passenger jill = Passenger.from("Jill", "Smith", 50); - Passenger eve = Passenger.from("Eve", "Jackson", 95); - Passenger fred = Passenger.from("Fred", "Bloggs", 22); - Passenger siya = Passenger.from("Siya", "Kolisi", 85); - Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); - - List passengers = repository.findByFirstNameIgnoreCase("FRED"); - - assertThat(passengers, contains(fred)); - assertThat(passengers, not(contains(eve))); - assertThat(passengers, not(contains(siya))); - assertThat(passengers, not(contains(jill))); - assertThat(passengers, not(contains(ricki))); - - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java deleted file mode 100644 index 831790af95..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.baeldung.multipledb; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.EnableTransactionManagement; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.multipledb.dao.product.ProductRepository; -import com.baeldung.multipledb.model.product.Product; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes=MultipleDbApplication.class) -@EnableTransactionManagement -public class ProductRepositoryIntegrationTest { - - @Autowired - private ProductRepository productRepository; - - @Before - @Transactional("productTransactionManager") - public void setUp() { - productRepository.save(Product.from(1001, "Book", 21)); - productRepository.save(Product.from(1002, "Coffee", 10)); - productRepository.save(Product.from(1003, "Jeans", 30)); - productRepository.save(Product.from(1004, "Shirt", 32)); - productRepository.save(Product.from(1005, "Bacon", 10)); - } - - @Test - public void whenRequestingFirstPageOfSizeTwo_ThenReturnFirstPage() { - Pageable pageRequest = PageRequest.of(0, 2); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(2)); - assertTrue(result.stream() - .map(Product::getId) - .allMatch(id -> Arrays.asList(1001, 1002) - .contains(id))); - } - - @Test - public void whenRequestingSecondPageOfSizeTwo_ThenReturnSecondPage() { - Pageable pageRequest = PageRequest.of(1, 2); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(2)); - assertTrue(result.stream() - .map(Product::getId) - .allMatch(id -> Arrays.asList(1003, 1004) - .contains(id))); - } - - @Test - public void whenRequestingLastPage_ThenReturnLastPageWithRemData() { - Pageable pageRequest = PageRequest.of(2, 2); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(1)); - assertTrue(result.stream() - .map(Product::getId) - .allMatch(id -> Arrays.asList(1005) - .contains(id))); - } - - @Test - public void whenSortingByNameAscAndPaging_ThenReturnSortedPagedResult() { - Pageable pageRequest = PageRequest.of(0, 3, Sort.by("name")); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(3)); - assertThat(result.getContent() - .stream() - .map(Product::getId) - .collect(Collectors.toList()), equalTo(Arrays.asList(1005, 1001, 1002))); - - } - - @Test - public void whenSortingByPriceDescAndPaging_ThenReturnSortedPagedResult() { - Pageable pageRequest = PageRequest.of(0, 3, Sort.by("price") - .descending()); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(3)); - assertThat(result.getContent() - .stream() - .map(Product::getId) - .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001))); - - } - - @Test - public void whenSortingByPriceDescAndNameAscAndPaging_ThenReturnSortedPagedResult() { - Pageable pageRequest = PageRequest.of(0, 5, Sort.by("price") - .descending() - .and(Sort.by("name"))); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(5)); - assertThat(result.getContent() - .stream() - .map(Product::getId) - .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001, 1005, 1002))); - - } - - @Test - public void whenRequestingFirstPageOfSizeTwoUsingCustomMethod_ThenReturnFirstPage() { - Pageable pageRequest = PageRequest.of(0, 2); - - List result = productRepository.findAllByPrice(10, pageRequest); - - assertThat(result, hasSize(2)); - assertTrue(result.stream() - .map(Product::getId) - .allMatch(id -> Arrays.asList(1002, 1005) - .contains(id))); - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java deleted file mode 100644 index 0fc9918701..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/repository/EmployeeRepositoryIntegrationTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.repository; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.Application; -import com.baeldung.entity.Employee; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -public class EmployeeRepositoryIntegrationTest { - - private static final Employee EMPLOYEE1 = new Employee(1L, "John"); - private static final Employee EMPLOYEE2 = new Employee(2L, "Alice"); - - @Autowired - private EmployeeRepository employeeRepository; - - @Test - public void givenEmployeeEntity_whenInsertWithSave_ThenEmployeeIsPersisted() { - employeeRepository.save(EMPLOYEE1); - assertEmployeePersisted(EMPLOYEE1); - } - - @Test - public void givenEmployeeEntity_whenInsertWithSaveAndFlush_ThenEmployeeIsPersisted() { - employeeRepository.saveAndFlush(EMPLOYEE2); - assertEmployeePersisted(EMPLOYEE2); - } - - private void assertEmployeePersisted(Employee input) { - Employee employee = employeeRepository.getOne(input.getId()); - assertThat(employee).isNotNull(); - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java deleted file mode 100644 index e5ad2dd448..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.util; - -import org.testcontainers.containers.PostgreSQLContainer; - -public class BaeldungPostgresqlContainer extends PostgreSQLContainer { - - private static final String IMAGE_VERSION = "postgres:11.1"; - - private static BaeldungPostgresqlContainer container; - - - private BaeldungPostgresqlContainer() { - super(IMAGE_VERSION); - } - - public static BaeldungPostgresqlContainer getInstance() { - if (container == null) { - container = new BaeldungPostgresqlContainer(); - } - return container; - } - - @Override - public void start() { - super.start(); - System.setProperty("DB_URL", container.getJdbcUrl()); - System.setProperty("DB_USERNAME", container.getUsername()); - System.setProperty("DB_PASSWORD", container.getPassword()); - } - - @Override - public void stop() { - //do nothing, JVM handles shut down - } -} diff --git a/persistence-modules/spring-data-jpa-3/src/test/resources/application-batchinserts.properties b/persistence-modules/spring-data-jpa-3/src/test/resources/application-batchinserts.properties deleted file mode 100644 index 4141f5668e..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/resources/application-batchinserts.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.jpa.show-sql=false - -spring.jpa.properties.hibernate.jdbc.batch_size=5 -spring.jpa.properties.hibernate.order_inserts=true -spring.jpa.properties.hibernate.order_updates=true -spring.jpa.properties.hibernate.batch_versioned_data=true \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-3/src/test/resources/application-tc-auto.properties b/persistence-modules/spring-data-jpa-3/src/test/resources/application-tc-auto.properties deleted file mode 100644 index c3005d861f..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/resources/application-tc-auto.properties +++ /dev/null @@ -1,4 +0,0 @@ -# configuration for test containers testing -spring.datasource.url=${DB_URL} -spring.datasource.username=${DB_USERNAME} -spring.datasource.password=${DB_PASSWORD} diff --git a/persistence-modules/spring-data-jpa-3/src/test/resources/application-tc.properties b/persistence-modules/spring-data-jpa-3/src/test/resources/application-tc.properties deleted file mode 100644 index 3bf8693d53..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/resources/application-tc.properties +++ /dev/null @@ -1,4 +0,0 @@ -# configuration for Test Containers testing -spring.datasource.driver-class-name=org.postgresql.Driver -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false diff --git a/persistence-modules/spring-data-jpa-3/src/test/resources/application-test.properties b/persistence-modules/spring-data-jpa-3/src/test/resources/application-test.properties deleted file mode 100644 index f9497c8f37..0000000000 --- a/persistence-modules/spring-data-jpa-3/src/test/resources/application-test.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring.jpa.hibernate.ddl-auto=update -spring.datasource.url=jdbc:h2:mem:jpa3 \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/README.md b/persistence-modules/spring-data-jpa-4/README.md deleted file mode 100644 index 085dfcb366..0000000000 --- a/persistence-modules/spring-data-jpa-4/README.md +++ /dev/null @@ -1,18 +0,0 @@ -### Relevant Articles: -- [Derived Query Methods in Spring Data JPA Repositories](https://www.baeldung.com/spring-data-derived-queries) -- [LIKE Queries in Spring JPA Repositories](https://www.baeldung.com/spring-jpa-like-queries) -- [A Guide to Spring’s Open Session In View](https://www.baeldung.com/spring-open-session-in-view) -- [Programmatic Transaction Management in Spring](https://www.baeldung.com/spring-programmatic-transaction-management) -- [JPA Entity Lifecycle Events](https://www.baeldung.com/jpa-entity-lifecycle-events) -- [Working with Lazy Element Collections in JPA](https://www.baeldung.com/java-jpa-lazy-collections) -- [Calling Stored Procedures from Spring Data JPA Repositories](https://www.baeldung.com/spring-data-jpa-stored-procedures) -- [Custom Naming Convention with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-custom-naming) - -### Eclipse Config -After importing the project into Eclipse, you may see the following error: -"No persistence xml file found in project" - -This can be ignored: -- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" -Or: -- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator diff --git a/persistence-modules/spring-data-jpa-4/create.sql b/persistence-modules/spring-data-jpa-4/create.sql deleted file mode 100644 index 1bbe1640a7..0000000000 --- a/persistence-modules/spring-data-jpa-4/create.sql +++ /dev/null @@ -1,2 +0,0 @@ -create table PERSON (ID int8 not null, FIRST_NAME varchar(255), LAST_NAME varchar(255), primary key (ID)) -create table person (id int8 not null, first_name varchar(255), last_name varchar(255), primary key (id)) diff --git a/persistence-modules/spring-data-jpa-4/pom.xml b/persistence-modules/spring-data-jpa-4/pom.xml deleted file mode 100644 index 71fc21527f..0000000000 --- a/persistence-modules/spring-data-jpa-4/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - 4.0.0 - spring-data-jpa-4 - spring-data-jpa-4 - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-data-jdbc - - - - mysql - mysql-connector-java - - - - org.postgresql - postgresql - - - - com.h2database - h2 - - - - \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/QueryApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/QueryApplication.java deleted file mode 100644 index d7a1950305..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/QueryApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.derivedquery; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class QueryApplication { - - public static void main(String[] args) { - SpringApplication.run(QueryApplication.class, args); - } - -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/entity/User.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/entity/User.java deleted file mode 100644 index 49e824f09f..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/entity/User.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.baeldung.derivedquery.entity; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; -import java.time.ZonedDateTime; - -@Table(name = "users") -@Entity -public class User { - - @Id - @GeneratedValue - private Integer id; - private String name; - private Integer age; - private ZonedDateTime birthDate; - private Boolean active; - - public User() { - } - - public User(String name, Integer age, ZonedDateTime birthDate, Boolean active) { - this.name = name; - this.age = age; - this.birthDate = birthDate; - this.active = active; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Integer getAge() { - return age; - } - - public void setAge(Integer age) { - this.age = age; - } - - public ZonedDateTime getBirthDate() { - return birthDate; - } - - public void setBirthDate(ZonedDateTime birthDate) { - this.birthDate = birthDate; - } - - public Boolean getActive() { - return active; - } - - public void setActive(Boolean active) { - this.active = active; - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/repository/UserRepository.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/repository/UserRepository.java deleted file mode 100644 index e613ee1531..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/derivedquery/repository/UserRepository.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.derivedquery.repository; - -import com.baeldung.derivedquery.entity.User; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.time.ZonedDateTime; -import java.util.Collection; -import java.util.List; - -public interface UserRepository extends JpaRepository { - - List findByName(String name); - - List findByNameIs(String name); - - List findByNameEquals(String name); - - List findByNameIsNull(); - - List findByNameNot(String name); - - List findByNameIsNot(String name); - - List findByNameStartingWith(String name); - - List findByNameEndingWith(String name); - - List findByNameContaining(String name); - - List findByNameLike(String name); - - List findByAgeLessThan(Integer age); - - List findByAgeLessThanEqual(Integer age); - - List findByAgeGreaterThan(Integer age); - - List findByAgeGreaterThanEqual(Integer age); - - List findByAgeBetween(Integer startAge, Integer endAge); - - List findByBirthDateAfter(ZonedDateTime birthDate); - - List findByBirthDateBefore(ZonedDateTime birthDate); - - List findByActiveTrue(); - - List findByActiveFalse(); - - List findByAgeIn(Collection ages); - - List findByNameOrBirthDate(String name, ZonedDateTime birthDate); - - List findByNameOrBirthDateAndActive(String name, ZonedDateTime birthDate, Boolean active); - - List findByNameOrderByName(String name); - - List findByNameOrderByNameDesc(String name); - -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java deleted file mode 100644 index 3f152a6ffc..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/ElementCollectionApplication.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.elementcollection; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class ElementCollectionApplication { - public static void main(String[] args) { - SpringApplication.run(ElementCollectionApplication.class, args); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/model/Employee.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/model/Employee.java deleted file mode 100644 index 8b98164d63..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/model/Employee.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.baeldung.elementcollection.model; - -import javax.persistence.*; -import java.util.List; -import java.util.Objects; - -@Entity -public class Employee { - @Id - private int id; - private String name; - @ElementCollection - @CollectionTable(name = "employee_phone", joinColumns = @JoinColumn(name = "employee_id")) - private List phones; - - public Employee() { - } - - public Employee(int id) { - this.id = id; - } - - public Employee(int id, String name) { - this.id = id; - this.name = name; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getPhones() { - return phones; - } - - public void setPhones(List phones) { - this.phones = phones; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof Employee)) { - return false; - } - Employee user = (Employee) o; - return getId() == user.getId(); - } - - @Override - public int hashCode() { - return Objects.hash(getId()); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/model/Phone.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/model/Phone.java deleted file mode 100644 index d73d30c47a..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/model/Phone.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.baeldung.elementcollection.model; - -import javax.persistence.Embeddable; -import java.util.Objects; - -@Embeddable -public class Phone { - private String type; - private String areaCode; - private String number; - - public Phone() { - } - - public Phone(String type, String areaCode, String number) { - this.type = type; - this.areaCode = areaCode; - this.number = number; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getAreaCode() { - return areaCode; - } - - public void setAreaCode(String areaCode) { - this.areaCode = areaCode; - } - - public String getNumber() { - return number; - } - - public void setNumber(String number) { - this.number = number; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof Phone)) { - return false; - } - Phone phone = (Phone) o; - return getType().equals(phone.getType()) && getAreaCode().equals(phone.getAreaCode()) - && getNumber().equals(phone.getNumber()); - } - - @Override - public int hashCode() { - return Objects.hash(getType(), getAreaCode(), getNumber()); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java deleted file mode 100644 index 49180c35eb..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/elementcollection/repository/EmployeeRepository.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.elementcollection.repository; - -import com.baeldung.elementcollection.model.Employee; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; - -import javax.persistence.EntityGraph; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import java.util.HashMap; -import java.util.Map; - -@Repository -public class EmployeeRepository { - - @PersistenceContext - private EntityManager em; - - @Transactional - public void save(Employee employee) { - em.persist(employee); - } - - @Transactional - public void remove(int id) { - Employee employee = findById(id); - em.remove(employee); - } - - public Employee findById(int id) { - return em.find(Employee.class, id); - } - - public Employee findByJPQL(int id) { - return em.createQuery("SELECT u FROM Employee AS u JOIN FETCH u.phones WHERE u.id=:id", Employee.class) - .setParameter("id", id).getSingleResult(); - } - - public Employee findByEntityGraph(int id) { - EntityGraph entityGraph = em.createEntityGraph(Employee.class); - entityGraph.addAttributeNodes("name", "phones"); - Map properties = new HashMap<>(); - properties.put("javax.persistence.fetchgraph", entityGraph); - return em.find(Employee.class, id, properties); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/SpringBootLifecycleEventApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/SpringBootLifecycleEventApplication.java deleted file mode 100644 index fbc861c5fe..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/SpringBootLifecycleEventApplication.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.lifecycleevents; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootLifecycleEventApplication { - public static void main(String[] args) { - SpringApplication.run(SpringBootLifecycleEventApplication.class, args); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/model/AuditTrailListener.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/model/AuditTrailListener.java deleted file mode 100644 index 26ebff42e4..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/model/AuditTrailListener.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.lifecycleevents.model; - -import javax.persistence.PostLoad; -import javax.persistence.PostPersist; -import javax.persistence.PostRemove; -import javax.persistence.PostUpdate; -import javax.persistence.PrePersist; -import javax.persistence.PreRemove; -import javax.persistence.PreUpdate; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public class AuditTrailListener { - private static Log log = LogFactory.getLog(AuditTrailListener.class); - - @PrePersist - @PreUpdate - @PreRemove - private void beforeAnyUpdate(User user) { - if (user.getId() == 0) { - log.info("[USER AUDIT] About to add a user"); - } else { - log.info("[USER AUDIT] About to update/delete user: " + user.getId()); - } - } - - @PostPersist - @PostUpdate - @PostRemove - private void afterAnyUpdate(User user) { - log.info("[USER AUDIT] add/update/delete complete for user: " + user.getId()); - } - - @PostLoad - private void afterLoad(User user) { - log.info("[USER AUDIT] user loaded from database: " + user.getId()); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/model/User.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/model/User.java deleted file mode 100644 index a080cb3bf2..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/model/User.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.baeldung.lifecycleevents.model; - -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.PostLoad; -import javax.persistence.PostPersist; -import javax.persistence.PostRemove; -import javax.persistence.PostUpdate; -import javax.persistence.PrePersist; -import javax.persistence.PreRemove; -import javax.persistence.PreUpdate; -import javax.persistence.Transient; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -@Entity -@EntityListeners(AuditTrailListener.class) -public class User { - private static Log log = LogFactory.getLog(User.class); - - @Id - @GeneratedValue - private int id; - - private String userName; - private String firstName; - private String lastName; - @Transient - private String fullName; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getFullName() { - return fullName; - } - - @PrePersist - public void logNewUserAttempt() { - log.info("Attempting to add new user with username: " + userName); - } - - @PostPersist - public void logNewUserAdded() { - log.info("Added user '" + userName + "' with ID: " + id); - } - - @PreRemove - public void logUserRemovalAttempt() { - log.info("Attempting to delete user: " + userName); - } - - @PostRemove - public void logUserRemoval() { - log.info("Deleted user: " + userName); - } - - @PreUpdate - public void logUserUpdateAttempt() { - log.info("Attempting to update user: " + userName); - } - - @PostUpdate - public void logUserUpdate() { - log.info("Updated user: " + userName); - } - - @PostLoad - public void logUserLoad() { - fullName = firstName + " " + lastName; - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/repository/UserRepository.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/repository/UserRepository.java deleted file mode 100644 index af14117ebb..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/lifecycleevents/repository/UserRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.lifecycleevents.repository; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.baeldung.lifecycleevents.model.User; - -public interface UserRepository extends JpaRepository { - public User findByUserName(String userName); -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/LikeApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/LikeApplication.java deleted file mode 100644 index 311aea3001..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/LikeApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.like; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class LikeApplication { - - public static void main(String[] args) { - SpringApplication.run(LikeApplication.class, args); - } - -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/model/Movie.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/model/Movie.java deleted file mode 100644 index bba8bd35c4..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/model/Movie.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.like.model; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class Movie { - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE) - private Long id; - private String title; - private String director; - private String rating; - private int duration; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDirector() { - return director; - } - - public void setDirector(String director) { - this.director = director; - } - - public String getRating() { - return rating; - } - - public void setRating(String rating) { - this.rating = rating; - } - - public int getDuration() { - return duration; - } - - public void setDuration(int duration) { - this.duration = duration; - } - -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/repository/MovieRepository.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/repository/MovieRepository.java deleted file mode 100644 index 241bdd3306..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/like/repository/MovieRepository.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.like.repository; - -import java.util.List; - -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.query.Param; - -import com.baeldung.like.model.Movie; - -public interface MovieRepository extends CrudRepository { - - List findByTitleContaining(String title); - - List findByTitleLike(String title); - - List findByTitleContains(String title); - - List findByTitleIsContaining(String title); - - List findByRatingStartsWith(String rating); - - List findByDirectorEndsWith(String director); - - List findByTitleContainingIgnoreCase(String title); - - List findByRatingNotContaining(String rating); - - List findByDirectorNotLike(String director); - - @Query("SELECT m FROM Movie m WHERE m.title LIKE %:title%") - List searchByTitleLike(@Param("title") String title); - - @Query("SELECT m FROM Movie m WHERE m.rating LIKE ?1%") - List searchByRatingStartsWith(String rating); - - //Escaping works in SpringBoot >= 2.4.1 - //@Query("SELECT m FROM Movie m WHERE m.director LIKE %?#{escape([0])} escape ?#{escapeCharacter()}") - @Query("SELECT m FROM Movie m WHERE m.director LIKE %:#{[0]}") - List searchByDirectorEndsWith(String director); -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/Person.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/Person.java deleted file mode 100644 index cfb6e67c2c..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/Person.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.namingstrategy; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -public class Person { - @Id - private Long id; - - private String firstName; - - private String lastName; - - public Person() {} - - public Person(Long id, String firstName, String lastName) { - this.id = id; - this.firstName = firstName; - this.lastName = lastName; - } - - public Long id() { - return id; - } - - public String firstName() { - return firstName; - } - - public String lastName() { - return lastName; - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/PersonRepository.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/PersonRepository.java deleted file mode 100644 index 3c7c25bbcb..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/PersonRepository.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.springframework.data.jpa.repository.JpaRepository; - -public interface PersonRepository extends JpaRepository { -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java deleted file mode 100644 index 16b01e50e3..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategy.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; - -public class QuotedLowerCaseNamingStrategy extends SpringPhysicalNamingStrategy { - @Override - protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) { - return new Identifier(name.toLowerCase(), true); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java deleted file mode 100644 index 3cb62aa5a2..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategy.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; - -public class QuotedUpperCaseNamingStrategy extends SpringPhysicalNamingStrategy { - @Override - protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) { - return new Identifier(name.toUpperCase(), true); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java deleted file mode 100644 index f223015db8..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/SpringDataJpaNamingConventionApplication.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringDataJpaNamingConventionApplication { -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java deleted file mode 100644 index 69e96aee27..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategy.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; - -public class UnquotedLowerCaseNamingStrategy extends SpringPhysicalNamingStrategy { - @Override - protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) { - return new Identifier(name.toLowerCase(), false); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java deleted file mode 100644 index cb87af10f4..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategy.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.boot.model.naming.Identifier; -import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy; - -public class UnquotedUpperCaseNamingStrategy extends SpringPhysicalNamingStrategy { - @Override - protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) { - return new Identifier(name.toUpperCase(), false); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/OsivApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/OsivApplication.java deleted file mode 100644 index 4cfcf83e56..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/OsivApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.osiv; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class OsivApplication { - - public static void main(String[] args) { - SpringApplication.run(OsivApplication.class, args); - } - -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/model/BasicUser.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/model/BasicUser.java deleted file mode 100644 index 98f4e379d4..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/model/BasicUser.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.osiv.model; - -import javax.persistence.*; -import java.util.Set; - -@Entity -@Table(name = "users") -public class BasicUser { - - @Id - @GeneratedValue - private Long id; - - private String username; - - @ElementCollection - private Set permissions; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public Set getPermissions() { - return permissions; - } - - public void setPermissions(Set permissions) { - this.permissions = permissions; - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java deleted file mode 100644 index e8d5955d91..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/repository/BasicUserRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.osiv.repository; - -import java.util.Optional; - -import org.springframework.data.jpa.repository.EntityGraph; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.osiv.model.BasicUser; - -@Repository -@Transactional -public interface BasicUserRepository extends JpaRepository { - - @EntityGraph(attributePaths = "permissions") - Optional findDetailedByUsername(String username); - -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/SimpleUserService.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/SimpleUserService.java deleted file mode 100644 index 1de51678d5..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/SimpleUserService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.osiv.service; - -import java.util.Optional; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.osiv.model.BasicUser; -import com.baeldung.osiv.repository.BasicUserRepository; - -@Service -public class SimpleUserService implements UserService { - - private final BasicUserRepository userRepository; - - public SimpleUserService(BasicUserRepository userRepository) { - this.userRepository = userRepository; - } - - @Override - @Transactional(readOnly = true) - public Optional findOne(String username) { - return userRepository.findDetailedByUsername(username); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/UserService.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/UserService.java deleted file mode 100644 index 3d089fa41b..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/service/UserService.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.osiv.service; - -import com.baeldung.osiv.model.BasicUser; - -import java.util.Optional; - -public interface UserService { - Optional findOne(String username); -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java deleted file mode 100644 index fd2882c2d5..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/DetailedUserDto.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.osiv.web; - -import com.baeldung.osiv.model.BasicUser; - -import java.util.Set; - -public class DetailedUserDto { - - private Long id; - private String username; - private Set permissions; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public Set getPermissions() { - return permissions; - } - - public void setPermissions(Set permissions) { - this.permissions = permissions; - } - - public static DetailedUserDto fromEntity(BasicUser user) { - DetailedUserDto detailed = new DetailedUserDto(); - detailed.setId(user.getId()); - detailed.setUsername(user.getUsername()); - detailed.setPermissions(user.getPermissions()); - - return detailed; - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/UserController.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/UserController.java deleted file mode 100644 index 5466b95166..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/osiv/web/UserController.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.osiv.web; - -import com.baeldung.osiv.service.UserService; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/users") -public class UserController { - - private final UserService userService; - - public UserController(UserService userService) { - this.userService = userService; - } - - @GetMapping("/{username}") - public ResponseEntity findOne(@PathVariable String username) { - return userService.findOne(username) - .map(DetailedUserDto::fromEntity) - .map(ResponseEntity::ok) - .orElse(ResponseEntity.notFound().build()); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/StoredProcedureApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/StoredProcedureApplication.java deleted file mode 100644 index 5f05764e21..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/StoredProcedureApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.storedprocedure; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class StoredProcedureApplication { - - public static void main(String[] args) { - SpringApplication.run(StoredProcedureApplication.class, args); - } - -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/controller/CarController.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/controller/CarController.java deleted file mode 100644 index 6aef600d01..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/controller/CarController.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.storedprocedure.controller; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.storedprocedure.entity.Car; -import com.baeldung.storedprocedure.service.CarService; - -@RestController -public class CarController { - @Autowired - private CarService carService; - - @GetMapping(path = "/modelcount") - public long getTotalCarsByModel(@RequestParam("model") String model) { - return carService.getTotalCarsByModel(model); - } - - @GetMapping(path = "/modelcountP") - public long getTotalCarsByModelProcedureName(@RequestParam("model") String model) { - return carService.getTotalCarsByModelProcedureName(model); - } - - @GetMapping(path = "/modelcountV") - public long getTotalCarsByModelVaue(@RequestParam("model") String model) { - return carService.getTotalCarsByModelValue(model); - } - - @GetMapping(path = "/modelcountEx") - public long getTotalCarsByModelExplicit(@RequestParam("model") String model) { - return carService.getTotalCarsByModelExplicit(model); - } - - @GetMapping(path = "/modelcountEn") - public long getTotalCarsByModelEntity(@RequestParam("model") String model) { - return carService.getTotalCarsByModelEntity(model); - } - - @GetMapping(path = "/carsafteryear") - public List findCarsAfterYear(@RequestParam("year") Integer year) { - return carService.findCarsAfterYear(year); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/entity/Car.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/entity/Car.java deleted file mode 100644 index 2817c25ff7..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/entity/Car.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.storedprocedure.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedStoredProcedureQuery; -import javax.persistence.StoredProcedureParameter; -import javax.persistence.ParameterMode; - -@Entity -@NamedStoredProcedureQuery(name = "Car.getTotalCardsbyModelEntity", procedureName = "GET_TOTAL_CARS_BY_MODEL", parameters = { - @StoredProcedureParameter(mode = ParameterMode.IN, name = "model_in", type = String.class), - @StoredProcedureParameter(mode = ParameterMode.OUT, name = "count_out", type = Integer.class) }) - -public class Car { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column - private long id; - - @Column - private String model; - - @Column - private Integer year; - - public long getId() { - return id; - } - - public String getModel() { - return model; - } - - public Integer getYear() { - return year; - } - -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/repository/CarRepository.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/repository/CarRepository.java deleted file mode 100644 index 3d9428628e..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/repository/CarRepository.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.storedprocedure.repository; - -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.jpa.repository.query.Procedure; -import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; - -import com.baeldung.storedprocedure.entity.Car; - -@Repository -public interface CarRepository extends JpaRepository { - - @Procedure - int GET_TOTAL_CARS_BY_MODEL(String model); - - @Procedure("GET_TOTAL_CARS_BY_MODEL") - int getTotalCarsByModel(String model); - - @Procedure(procedureName = "GET_TOTAL_CARS_BY_MODEL") - int getTotalCarsByModelProcedureName(String model); - - @Procedure(value = "GET_TOTAL_CARS_BY_MODEL") - int getTotalCarsByModelValue(String model); - - @Procedure(name = "Car.getTotalCardsbyModelEntity") - int getTotalCarsByModelEntiy(@Param("model_in") String model); - - @Query(value = "CALL FIND_CARS_AFTER_YEAR(:year_in);", nativeQuery = true) - List findCarsAfterYear(@Param("year_in") Integer year_in); - -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/service/CarService.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/service/CarService.java deleted file mode 100644 index 104f46e324..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/storedprocedure/service/CarService.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.storedprocedure.service; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.baeldung.storedprocedure.entity.Car; -import com.baeldung.storedprocedure.repository.CarRepository; - -@Service -public class CarService { - @Autowired - private CarRepository carRepository; - - public int getTotalCarsByModel(String model) { - return carRepository.getTotalCarsByModel(model); - } - - public int getTotalCarsByModelProcedureName(String model) { - return carRepository.getTotalCarsByModelProcedureName(model); - } - - public int getTotalCarsByModelValue(String model) { - return carRepository.getTotalCarsByModelValue(model); - } - - public int getTotalCarsByModelExplicit(String model) { - return carRepository.GET_TOTAL_CARS_BY_MODEL(model); - } - - public int getTotalCarsByModelEntity(String model) { - return carRepository.getTotalCarsByModelEntiy(model); - } - - public List findCarsAfterYear(Integer year) { - return carRepository.findCarsAfterYear(year); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/TxApplication.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/TxApplication.java deleted file mode 100644 index 4c982c91e9..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/TxApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.tx; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class TxApplication { - - public static void main(String[] args) { - SpringApplication.run(TxApplication.class, args); - } - -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/model/Payment.java b/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/model/Payment.java deleted file mode 100644 index 921a1e9275..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/java/com/baeldung/tx/model/Payment.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.baeldung.tx.model; - -import javax.persistence.*; - -@Entity -public class Payment { - - @Id - @GeneratedValue - private Long id; - - private Long amount; - - @Column(unique = true) - private String referenceNumber; - - @Enumerated(EnumType.STRING) - private State state; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Long getAmount() { - return amount; - } - - public void setAmount(Long amount) { - this.amount = amount; - } - - public String getReferenceNumber() { - return referenceNumber; - } - - public void setReferenceNumber(String referenceNumber) { - this.referenceNumber = referenceNumber; - } - - public State getState() { - return state; - } - - public void setState(State state) { - this.state = state; - } - - public enum State { - STARTED, FAILED, SUCCESSFUL - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-4/src/main/resources/application.properties deleted file mode 100644 index 65d7b0bf29..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/resources/application.properties +++ /dev/null @@ -1,5 +0,0 @@ -spring.jpa.show-sql=true -#MySql -#spring.datasource.url=jdbc:mysql://localhost:3306/baeldung -#spring.datasource.username=baeldung -#spring.datasource.password=baeldung \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/main/resources/car-mysql.sql b/persistence-modules/spring-data-jpa-4/src/main/resources/car-mysql.sql deleted file mode 100644 index bb4ab2a86e..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/main/resources/car-mysql.sql +++ /dev/null @@ -1,27 +0,0 @@ -DROP TABLE IF EXISTS car; - -CREATE TABLE car (id int(10) NOT NULL AUTO_INCREMENT, - model varchar(50) NOT NULL, - year int(4) NOT NULL, - PRIMARY KEY (id)); - -INSERT INTO car (model, year) VALUES ('BMW', 2000); -INSERT INTO car (model, year) VALUES ('BENZ', 2010); -INSERT INTO car (model, year) VALUES ('PORCHE', 2005); -INSERT INTO car (model, year) VALUES ('PORCHE', 2004); - -DELIMITER $$ - -DROP PROCEDURE IF EXISTS FIND_CARS_AFTER_YEAR$$ -CREATE PROCEDURE FIND_CARS_AFTER_YEAR(IN year_in INT) -BEGIN - SELECT * FROM car WHERE year >= year_in ORDER BY year; -END$$ - -DROP PROCEDURE IF EXISTS GET_TOTAL_CARS_BY_MODEL$$ -CREATE PROCEDURE GET_TOTAL_CARS_BY_MODEL(IN model_in VARCHAR(50), OUT count_out INT) -BEGIN - SELECT COUNT(*) into count_out from car WHERE model = model_in; -END$$ - -DELIMITER ; diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java deleted file mode 100644 index 2a6e166b88..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/derivedquery/repository/UserRepositoryIntegrationTest.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.baeldung.derivedquery.repository; - -import com.baeldung.derivedquery.QueryApplication; -import com.baeldung.derivedquery.entity.User; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.time.ZonedDateTime; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = QueryApplication.class) -public class UserRepositoryIntegrationTest { - - private static final String USER_NAME_ADAM = "Adam"; - private static final String USER_NAME_EVE = "Eve"; - private static final ZonedDateTime BIRTHDATE = ZonedDateTime.now(); - - @Autowired - private UserRepository userRepository; - - @Before - public void setUp() { - - User user1 = new User(USER_NAME_ADAM, 25, BIRTHDATE, true); - User user2 = new User(USER_NAME_ADAM, 20, BIRTHDATE, false); - User user3 = new User(USER_NAME_EVE, 20, BIRTHDATE, true); - User user4 = new User(null, 30, BIRTHDATE, false); - - userRepository.saveAll(Arrays.asList(user1, user2, user3, user4)); - } - - @After - public void tearDown() { - - userRepository.deleteAll(); - } - - @Test - public void whenFindByName_thenReturnsCorrectResult() { - - assertEquals(2, userRepository.findByName(USER_NAME_ADAM).size()); - } - - @Test - public void whenFindByNameIsNull_thenReturnsCorrectResult() { - - assertEquals(1, userRepository.findByNameIsNull().size()); - } - - @Test - public void whenFindByNameNot_thenReturnsCorrectResult() { - - assertEquals(USER_NAME_EVE, userRepository.findByNameNot(USER_NAME_ADAM).get(0).getName()); - } - - @Test - public void whenFindByNameStartingWith_thenReturnsCorrectResult() { - - assertEquals(2, userRepository.findByNameStartingWith("A").size()); - } - - @Test - public void whenFindByNameEndingWith_thenReturnsCorrectResult() { - - assertEquals(1, userRepository.findByNameEndingWith("e").size()); - } - - @Test - public void whenByNameContaining_thenReturnsCorrectResult() { - - assertEquals(1, userRepository.findByNameContaining("v").size()); - } - - - @Test - public void whenByNameLike_thenReturnsCorrectResult() { - - assertEquals(2, userRepository.findByNameEndingWith("m").size()); - } - - @Test - public void whenByAgeLessThan_thenReturnsCorrectResult() { - - assertEquals(2, userRepository.findByAgeLessThan(25).size()); - } - - - @Test - public void whenByAgeLessThanEqual_thenReturnsCorrectResult() { - - assertEquals(3, userRepository.findByAgeLessThanEqual(25).size()); - } - - @Test - public void whenByAgeGreaterThan_thenReturnsCorrectResult() { - - assertEquals(1, userRepository.findByAgeGreaterThan(25).size()); - } - - @Test - public void whenByAgeGreaterThanEqual_thenReturnsCorrectResult() { - - assertEquals(2, userRepository.findByAgeGreaterThanEqual(25).size()); - } - - @Test - public void whenByAgeBetween_thenReturnsCorrectResult() { - - assertEquals(4, userRepository.findByAgeBetween(20, 30).size()); - } - - @Test - public void whenByBirthDateAfter_thenReturnsCorrectResult() { - - final ZonedDateTime yesterday = BIRTHDATE.minusDays(1); - assertEquals(4, userRepository.findByBirthDateAfter(yesterday).size()); - } - - @Test - public void whenByBirthDateBefore_thenReturnsCorrectResult() { - - final ZonedDateTime yesterday = BIRTHDATE.minusDays(1); - assertEquals(0, userRepository.findByBirthDateBefore(yesterday).size()); - } - - @Test - public void whenByActiveTrue_thenReturnsCorrectResult() { - - assertEquals(2, userRepository.findByActiveTrue().size()); - } - - @Test - public void whenByActiveFalse_thenReturnsCorrectResult() { - - assertEquals(2, userRepository.findByActiveFalse().size()); - } - - - @Test - public void whenByAgeIn_thenReturnsCorrectResult() { - - final List ages = Arrays.asList(20, 25); - assertEquals(3, userRepository.findByAgeIn(ages).size()); - } - - @Test - public void whenByNameOrBirthDate() { - - assertEquals(4, userRepository.findByNameOrBirthDate(USER_NAME_ADAM, BIRTHDATE).size()); - } - - @Test - public void whenByNameOrBirthDateAndActive() { - - assertEquals(3, userRepository.findByNameOrBirthDateAndActive(USER_NAME_ADAM, BIRTHDATE, false).size()); - } - - @Test - public void whenByNameOrderByName() { - - assertEquals(2, userRepository.findByNameOrderByName(USER_NAME_ADAM).size()); - } -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java deleted file mode 100644 index 306798aa68..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/elementcollection/ElementCollectionIntegrationTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.baeldung.elementcollection; - -import com.baeldung.elementcollection.model.Employee; -import com.baeldung.elementcollection.model.Phone; -import com.baeldung.elementcollection.repository.EmployeeRepository; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Arrays; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = ElementCollectionApplication.class) -public class ElementCollectionIntegrationTest { - - @Autowired - private EmployeeRepository employeeRepository; - - @Before - public void init() { - Employee employee = new Employee(1, "Fred"); - employee.setPhones( - Arrays.asList(new Phone("work", "+55", "99999-9999"), new Phone("home", "+55", "98888-8888"))); - employeeRepository.save(employee); - } - - @After - public void clean() { - employeeRepository.remove(1); - } - - @Test(expected = org.hibernate.LazyInitializationException.class) - public void whenAccessLazyCollection_thenThrowLazyInitializationException() { - Employee employee = employeeRepository.findById(1); - assertThat(employee.getPhones().size(), is(2)); - } - - @Test - public void whenUseJPAQL_thenFetchResult() { - Employee employee = employeeRepository.findByJPQL(1); - assertThat(employee.getPhones().size(), is(2)); - } - - @Test - public void whenUseEntityGraph_thenFetchResult() { - Employee employee = employeeRepository.findByEntityGraph(1); - assertThat(employee.getPhones().size(), is(2)); - } - - @Test - @Transactional - public void whenUseTransaction_thenFetchResult() { - Employee employee = employeeRepository.findById(1); - assertThat(employee.getPhones().size(), is(2)); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java deleted file mode 100644 index cc96b638ab..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/like/MovieRepositoryIntegrationTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.baeldung.like; - -import com.baeldung.like.model.Movie; -import com.baeldung.like.repository.MovieRepository; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; - -@RunWith(SpringRunner.class) -@Sql(scripts = { "/test-movie-data.sql" }) -@SpringBootTest(classes = LikeApplication.class) -@Sql(scripts = "/test-movie-cleanup.sql", executionPhase = AFTER_TEST_METHOD) -public class MovieRepositoryIntegrationTest { - @Autowired - private MovieRepository movieRepository; - - @Test - public void givenPartialTitle_WhenFindByTitleContaining_ThenMoviesShouldReturn() { - List results = movieRepository.findByTitleContaining("in"); - assertEquals(3, results.size()); - - results = movieRepository.findByTitleLike("%in%"); - assertEquals(3, results.size()); - - results = movieRepository.findByTitleIsContaining("in"); - assertEquals(3, results.size()); - - results = movieRepository.findByTitleContains("in"); - assertEquals(3, results.size()); - } - - @Test - public void givenStartOfRating_WhenFindByRatingStartsWith_ThenMoviesShouldReturn() { - List results = movieRepository.findByRatingStartsWith("PG"); - assertEquals(6, results.size()); - } - - @Test - public void givenLastName_WhenFindByDirectorEndsWith_ThenMoviesShouldReturn() { - List results = movieRepository.findByDirectorEndsWith("Burton"); - assertEquals(1, results.size()); - } - - @Test - public void givenPartialTitle_WhenFindByTitleContainingIgnoreCase_ThenMoviesShouldReturn() { - List results = movieRepository.findByTitleContainingIgnoreCase("the"); - assertEquals(2, results.size()); - } - - @Test - public void givenPartialTitle_WhenSearchByTitleLike_ThenMoviesShouldReturn() { - List results = movieRepository.searchByTitleLike("in"); - assertEquals(3, results.size()); - } - - @Test - public void givenStartOfRating_SearchFindByRatingStartsWith_ThenMoviesShouldReturn() { - List results = movieRepository.searchByRatingStartsWith("PG"); - assertEquals(6, results.size()); - } - - @Test - public void givenLastName_WhenSearchByDirectorEndsWith_ThenMoviesShouldReturn() { - List results = movieRepository.searchByDirectorEndsWith("Burton"); - assertEquals(1, results.size()); - } - - @Test - public void givenPartialRating_findByRatingNotContaining_ThenMoviesShouldReturn() { - List results = movieRepository.findByRatingNotContaining("PG"); - assertEquals(1, results.size()); - } - - @Test - public void givenPartialDirector_WhenFindByDirectorNotLike_ThenMoviesShouldReturn() { - List results = movieRepository.findByDirectorNotLike("An%"); - assertEquals(5, results.size()); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java deleted file mode 100644 index 71a4dbda3f..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyH2IntegrationTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.exception.SQLGrammarException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.TestPropertySource; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) -@TestPropertySource("quoted-lower-case-naming-strategy.properties") -class QuotedLowerCaseNamingStrategyH2IntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private PersonRepository personRepository; - - @BeforeEach - void insertPeople() { - personRepository.saveAll(Arrays.asList( - new Person(1L, "John", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Ted", "Mosby") - )); - } - - @ParameterizedTest - @ValueSource(strings = {"person", "PERSON", "Person"}) - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonUnquoted_thenException(String tableName) { - Query query = entityManager.createNativeQuery("select * from " + tableName); - - // Unexpected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - @Test - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { - Query query = entityManager.createNativeQuery("select * from \"PERSON\""); - - // Expected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - @Test - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { - Query query = entityManager.createNativeQuery("select * from \"person\""); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - public Person fromDatabase(Object databaseRow) { - Object[] typedDatabaseRow = (Object[]) databaseRow; - - return new Person( - ((BigInteger) typedDatabaseRow[0]).longValue(), - (String) typedDatabaseRow[1], - (String) typedDatabaseRow[2] - ); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java deleted file mode 100644 index 6b1c984600..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedLowerCaseNamingStrategyPostgresLiveTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.exception.SQLGrammarException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.TestPropertySource; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) -@TestPropertySource("quoted-lower-case-naming-strategy-on-postgres.properties") -class QuotedLowerCaseNamingStrategyPostgresLiveTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private PersonRepository personRepository; - - @BeforeEach - void insertPeople() { - personRepository.saveAll(Arrays.asList( - new Person(1L, "John", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Ted", "Mosby") - )); - } - - @ParameterizedTest - @ValueSource(strings = {"person", "PERSON", "Person"}) - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { - Query query = entityManager.createNativeQuery("select * from " + tableName); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { - Query query = entityManager.createNativeQuery("select * from \"PERSON\""); - - // Expected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - @Test - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { - Query query = entityManager.createNativeQuery("select * from \"person\""); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - public Person fromDatabase(Object databaseRow) { - Object[] typedDatabaseRow = (Object[]) databaseRow; - - return new Person( - ((BigInteger) typedDatabaseRow[0]).longValue(), - (String) typedDatabaseRow[1], - (String) typedDatabaseRow[2] - ); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java deleted file mode 100644 index f819327a5c..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyH2IntegrationTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.exception.SQLGrammarException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.TestPropertySource; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) -@TestPropertySource("quoted-upper-case-naming-strategy.properties") -class QuotedUpperCaseNamingStrategyH2IntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private PersonRepository personRepository; - - @BeforeEach - void insertPeople() { - personRepository.saveAll(Arrays.asList( - new Person(1L, "John", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Ted", "Mosby") - )); - } - - @ParameterizedTest - @ValueSource(strings = {"person", "PERSON", "Person"}) - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonUnquoted_thenException(String tableName) { - Query query = entityManager.createNativeQuery("select * from " + tableName); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenResult() { - Query query = entityManager.createNativeQuery("select * from \"PERSON\""); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenException() { - Query query = entityManager.createNativeQuery("select * from \"person\""); - - // Expected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - public Person fromDatabase(Object databaseRow) { - Object[] typedDatabaseRow = (Object[]) databaseRow; - - return new Person( - ((BigInteger) typedDatabaseRow[0]).longValue(), - (String) typedDatabaseRow[1], - (String) typedDatabaseRow[2] - ); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java deleted file mode 100644 index bd23b81b4b..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/QuotedUpperCaseNamingStrategyPostgresLiveTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.exception.SQLGrammarException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.TestPropertySource; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) -@TestPropertySource("quoted-upper-case-naming-strategy-on-postgres.properties") -class QuotedUpperCaseNamingStrategyPostgresLiveTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private PersonRepository personRepository; - - @BeforeEach - void insertPeople() { - personRepository.saveAll(Arrays.asList( - new Person(1L, "John", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Ted", "Mosby") - )); - } - - @ParameterizedTest - @ValueSource(strings = {"person", "PERSON", "Person"}) - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { - Query query = entityManager.createNativeQuery("select * from " + tableName); - - // Unexpected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - @Test - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { - Query query = entityManager.createNativeQuery("select * from \"PERSON\""); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { - Query query = entityManager.createNativeQuery("select * from \"person\""); - - // Expected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - public Person fromDatabase(Object databaseRow) { - Object[] typedDatabaseRow = (Object[]) databaseRow; - - return new Person( - ((BigInteger) typedDatabaseRow[0]).longValue(), - (String) typedDatabaseRow[1], - (String) typedDatabaseRow[2] - ); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java deleted file mode 100644 index 1850fea173..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyH2IntegrationTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.exception.SQLGrammarException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.TestPropertySource; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) -@TestPropertySource("spring-physical-naming-strategy.properties") -class SpringPhysicalNamingStrategyH2IntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private PersonRepository personRepository; - - @BeforeEach - void insertPeople() { - personRepository.saveAll(Arrays.asList( - new Person(1L, "John", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Ted", "Mosby") - )); - } - - @ParameterizedTest - @ValueSource(strings = {"person", "PERSON", "Person"}) - void givenPeopleAndSpringNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { - Query query = entityManager.createNativeQuery("select * from " + tableName); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndSpringNamingStrategy_whenQueryPersonQuotedUpperCase_thenResult() { - Query query = entityManager.createNativeQuery("select * from \"PERSON\""); - - // Unexpected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndSpringNamingStrategy_whenQueryPersonQuotedLowerCase_thenException() { - Query query = entityManager.createNativeQuery("select * from \"person\""); - - // Unexpected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - public Person fromDatabase(Object databaseRow) { - Object[] typedDatabaseRow = (Object[]) databaseRow; - - return new Person( - ((BigInteger) typedDatabaseRow[0]).longValue(), - (String) typedDatabaseRow[1], - (String) typedDatabaseRow[2] - ); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java deleted file mode 100644 index e26ebb148d..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/SpringPhysicalNamingStrategyPostgresLiveTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.exception.SQLGrammarException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.TestPropertySource; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) -@TestPropertySource("spring-physical-naming-strategy-on-postgres.properties") -class SpringPhysicalNamingStrategyPostgresLiveTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private PersonRepository personRepository; - - @BeforeEach - void insertPeople() { - personRepository.saveAll(Arrays.asList( - new Person(1L, "John", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Ted", "Mosby") - )); - } - - @ParameterizedTest - @ValueSource(strings = {"person", "PERSON", "Person"}) - void givenPeopleAndSpringNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { - Query query = entityManager.createNativeQuery("select * from " + tableName); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndSpringNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { - Query query = entityManager.createNativeQuery("select * from \"PERSON\""); - - // Expected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - @Test - void givenPeopleAndSpringNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { - Query query = entityManager.createNativeQuery("select * from \"person\""); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - public Person fromDatabase(Object databaseRow) { - Object[] typedDatabaseRow = (Object[]) databaseRow; - - return new Person( - ((BigInteger) typedDatabaseRow[0]).longValue(), - (String) typedDatabaseRow[1], - (String) typedDatabaseRow[2] - ); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java deleted file mode 100644 index 6311c42e93..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyH2IntegrationTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.exception.SQLGrammarException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.TestPropertySource; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) -@TestPropertySource("unquoted-lower-case-naming-strategy.properties") -class UnquotedLowerCaseNamingStrategyH2IntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private PersonRepository personRepository; - - @BeforeEach - void insertPeople() { - personRepository.saveAll(Arrays.asList( - new Person(1L, "John", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Ted", "Mosby") - )); - } - - @ParameterizedTest - @ValueSource(strings = {"person", "PERSON", "Person"}) - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { - Query query = entityManager.createNativeQuery("select * from " + tableName); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenResult() { - Query query = entityManager.createNativeQuery("select * from \"PERSON\""); - - // Unexpected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenException() { - Query query = entityManager.createNativeQuery("select * from \"person\""); - - // Unexpected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - public Person fromDatabase(Object databaseRow) { - Object[] typedDatabaseRow = (Object[]) databaseRow; - - return new Person( - ((BigInteger) typedDatabaseRow[0]).longValue(), - (String) typedDatabaseRow[1], - (String) typedDatabaseRow[2] - ); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java deleted file mode 100644 index 033a213cf5..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedLowerCaseNamingStrategyPostgresLiveTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.exception.SQLGrammarException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.TestPropertySource; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) -@TestPropertySource("unquoted-lower-case-naming-strategy-on-postgres.properties") -class UnquotedLowerCaseNamingStrategyPostgresLiveTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private PersonRepository personRepository; - - @BeforeEach - void insertPeople() { - personRepository.saveAll(Arrays.asList( - new Person(1L, "John", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Ted", "Mosby") - )); - } - - @ParameterizedTest - @ValueSource(strings = {"person", "PERSON", "Person"}) - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { - Query query = entityManager.createNativeQuery("select * from " + tableName); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { - Query query = entityManager.createNativeQuery("select * from \"PERSON\""); - - // Expected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - @Test - void givenPeopleAndLowerCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { - Query query = entityManager.createNativeQuery("select * from \"person\""); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - public Person fromDatabase(Object databaseRow) { - Object[] typedDatabaseRow = (Object[]) databaseRow; - - return new Person( - ((BigInteger) typedDatabaseRow[0]).longValue(), - (String) typedDatabaseRow[1], - (String) typedDatabaseRow[2] - ); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java deleted file mode 100644 index 7af8001854..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyH2IntegrationTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.exception.SQLGrammarException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.TestPropertySource; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) -@TestPropertySource("unquoted-upper-case-naming-strategy.properties") -class UnquotedUpperCaseNamingStrategyH2IntegrationTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private PersonRepository personRepository; - - @BeforeEach - void insertPeople() { - personRepository.saveAll(Arrays.asList( - new Person(1L, "John", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Ted", "Mosby") - )); - } - - @ParameterizedTest - @ValueSource(strings = {"person", "PERSON", "Person"}) - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { - Query query = entityManager.createNativeQuery("select * from " + tableName); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenResult() { - Query query = entityManager.createNativeQuery("select * from \"PERSON\""); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenException() { - Query query = entityManager.createNativeQuery("select * from \"person\""); - - // Expected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - public Person fromDatabase(Object databaseRow) { - Object[] typedDatabaseRow = (Object[]) databaseRow; - - return new Person( - ((BigInteger) typedDatabaseRow[0]).longValue(), - (String) typedDatabaseRow[1], - (String) typedDatabaseRow[2] - ); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java deleted file mode 100644 index 0151e7ece4..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/namingstrategy/UnquotedUpperCaseNamingStrategyPostgresLiveTest.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.namingstrategy; - -import org.hibernate.exception.SQLGrammarException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.TestPropertySource; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.Query; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class) -@TestPropertySource("unquoted-upper-case-naming-strategy-on-postgres.properties") -class UnquotedUpperCaseNamingStrategyPostgresLiveTest { - - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private PersonRepository personRepository; - - @BeforeEach - void insertPeople() { - personRepository.saveAll(Arrays.asList( - new Person(1L, "John", "Doe"), - new Person(2L, "Jane", "Doe"), - new Person(3L, "Ted", "Mosby") - )); - } - - @ParameterizedTest - @ValueSource(strings = {"person", "PERSON", "Person"}) - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonUnquoted_thenResult(String tableName) { - Query query = entityManager.createNativeQuery("select * from " + tableName); - - // Expected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - @Test - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedUpperCase_thenException() { - Query query = entityManager.createNativeQuery("select * from \"PERSON\""); - - // Unexpected result - assertThrows(SQLGrammarException.class, query::getResultStream); - } - - @Test - void givenPeopleAndUpperCaseNamingStrategy_whenQueryPersonQuotedLowerCase_thenResult() { - Query query = entityManager.createNativeQuery("select * from \"person\""); - - // Unexpected result - List result = (List) query.getResultStream() - .map(this::fromDatabase) - .collect(Collectors.toList()); - - assertThat(result).isNotEmpty(); - } - - public Person fromDatabase(Object databaseRow) { - Object[] typedDatabaseRow = (Object[]) databaseRow; - - return new Person( - ((BigInteger) typedDatabaseRow[0]).longValue(), - (String) typedDatabaseRow[1], - (String) typedDatabaseRow[2] - ); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java deleted file mode 100644 index 350b67e1c9..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/osiv/UserControllerIntegrationTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.osiv; - -import com.baeldung.osiv.model.BasicUser; -import com.baeldung.osiv.repository.BasicUserRepository; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.web.servlet.MockMvc; - -import java.util.Arrays; -import java.util.HashSet; - -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@SpringBootTest -@AutoConfigureMockMvc -@ActiveProfiles("test") -@ContextConfiguration(classes = OsivApplication.class) -class UserControllerIntegrationTest { - - @Autowired - private BasicUserRepository userRepository; - - @Autowired - private MockMvc mockMvc; - - @BeforeEach - void setUp() { - BasicUser user = new BasicUser(); - user.setUsername("root"); - user.setPermissions(new HashSet<>(Arrays.asList("PERM_READ", "PERM_WRITE"))); - - userRepository.save(user); - } - - @Test - void givenTheUserExists_WhenOsivIsEnabled_ThenLazyInitWorkEverywhere() throws Exception { - mockMvc.perform(get("/users/root")) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.username").value("root")) - .andExpect(jsonPath("$.permissions", containsInAnyOrder("PERM_READ", "PERM_WRITE"))); - } - - @AfterEach - void flushDb() { - userRepository.deleteAll(); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java deleted file mode 100644 index 01551348c9..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/com/baeldung/tx/ManualTransactionIntegrationTest.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.baeldung.tx; - -import com.baeldung.tx.model.Payment; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.support.DefaultTransactionDefinition; -import org.springframework.transaction.support.TransactionCallbackWithoutResult; -import org.springframework.transaction.support.TransactionTemplate; - -import javax.persistence.EntityManager; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.transaction.annotation.Propagation.NOT_SUPPORTED; - -@DataJpaTest -@ActiveProfiles("test") -@Transactional(propagation = NOT_SUPPORTED) -class ManualTransactionIntegrationTest { - - @Autowired - private PlatformTransactionManager transactionManager; - - @Autowired - private EntityManager entityManager; - - private TransactionTemplate transactionTemplate; - - @BeforeEach - void setUp() { - transactionTemplate = new TransactionTemplate(transactionManager); - } - - @AfterEach - void flushDb() { - transactionTemplate.execute(status -> entityManager - .createQuery("delete from Payment") - .executeUpdate()); - } - - @Test - void givenAPayment_WhenNotDuplicate_ThenShouldCommit() { - Long id = transactionTemplate.execute(status -> { - Payment payment = new Payment(); - payment.setAmount(1000L); - payment.setReferenceNumber("Ref-1"); - payment.setState(Payment.State.SUCCESSFUL); - - entityManager.persist(payment); - - return payment.getId(); - }); - - Payment payment = entityManager.find(Payment.class, id); - assertThat(payment).isNotNull(); - } - - @Test - void givenAPayment_WhenMarkAsRollback_ThenShouldRollback() { - transactionTemplate.execute(status -> { - Payment payment = new Payment(); - payment.setAmount(1000L); - payment.setReferenceNumber("Ref-1"); - payment.setState(Payment.State.SUCCESSFUL); - - entityManager.persist(payment); - status.setRollbackOnly(); - - return payment.getId(); - }); - - assertThat(entityManager - .createQuery("select p from Payment p", Payment.class) - .getResultList()).isEmpty(); - } - - @Test - void givenTwoPayments_WhenRefIsDuplicate_ThenShouldRollback() { - try { - transactionTemplate.execute(s -> { - Payment first = new Payment(); - first.setAmount(1000L); - first.setReferenceNumber("Ref-1"); - first.setState(Payment.State.SUCCESSFUL); - - Payment second = new Payment(); - second.setAmount(2000L); - second.setReferenceNumber("Ref-1"); - second.setState(Payment.State.SUCCESSFUL); - - entityManager.persist(first); - entityManager.persist(second); - - return "Ref-1"; - }); - } catch (Exception ignored) { - } - - assertThat(entityManager - .createQuery("select p from Payment p", Payment.class) - .getResultList()).isEmpty(); - } - - @Test - void givenAPayment_WhenNotExpectingAnyResult_ThenShouldCommit() { - transactionTemplate.execute(new TransactionCallbackWithoutResult() { - @Override - protected void doInTransactionWithoutResult(TransactionStatus status) { - Payment payment = new Payment(); - payment.setReferenceNumber("Ref-1"); - payment.setState(Payment.State.SUCCESSFUL); - - entityManager.persist(payment); - } - }); - - assertThat(entityManager - .createQuery("select p from Payment p", Payment.class) - .getResultList()).hasSize(1); - } - - @Test - void givenAPayment_WhenUsingTxManager_ThenShouldCommit() { - DefaultTransactionDefinition definition = new DefaultTransactionDefinition(); - definition.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ); - definition.setTimeout(3); - - TransactionStatus status = transactionManager.getTransaction(definition); - try { - Payment payment = new Payment(); - payment.setReferenceNumber("Ref-1"); - payment.setState(Payment.State.SUCCESSFUL); - - entityManager.persist(payment); - transactionManager.commit(status); - } catch (Exception ex) { - transactionManager.rollback(status); - } - - assertThat(entityManager - .createQuery("select p from Payment p", Payment.class) - .getResultList()).hasSize(1); - } - -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/java/lifecycleevents/UserRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-4/src/test/java/lifecycleevents/UserRepositoryIntegrationTest.java deleted file mode 100644 index 078f437474..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/java/lifecycleevents/UserRepositoryIntegrationTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package lifecycleevents; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.lifecycleevents.SpringBootLifecycleEventApplication; -import com.baeldung.lifecycleevents.model.User; -import com.baeldung.lifecycleevents.repository.UserRepository; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = SpringBootLifecycleEventApplication.class) -public class UserRepositoryIntegrationTest { - - @Autowired - private UserRepository userRepository; - - @Before - public void setup() { - User user = new User(); - user.setFirstName("Jane"); - user.setLastName("Smith"); - user.setUserName("jsmith123"); - userRepository.save(user); - } - - @After - public void cleanup() { - userRepository.deleteAll(); - } - - @Test - public void whenNewUserProvided_userIsAdded() { - User user = new User(); - user.setFirstName("John"); - user.setLastName("Doe"); - user.setUserName("jdoe123"); - user = userRepository.save(user); - assertTrue(user.getId() > 0); - } - - @Test - public void whenUserNameProvided_userIsLoaded() { - User user = userRepository.findByUserName("jsmith123"); - assertNotNull(user); - assertEquals("jsmith123", user.getUserName()); - } - - @Test - public void whenExistingUserProvided_userIsUpdated() { - User user = userRepository.findByUserName("jsmith123"); - user.setFirstName("Joe"); - user = userRepository.save(user); - assertEquals("Joe", user.getFirstName()); - } - - @Test - public void whenExistingUserDeleted_userIsDeleted() { - User user = userRepository.findByUserName("jsmith123"); - userRepository.delete(user); - user = userRepository.findByUserName("jsmith123"); - assertNull(user); - } - - @Test - public void whenExistingUserLoaded_fullNameIsAvailable() { - String expectedFullName = "Jane Smith"; - User user = userRepository.findByUserName("jsmith123"); - assertEquals(expectedFullName, user.getFullName()); - } -} diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/application-test.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/application-test.properties deleted file mode 100644 index f9497c8f37..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/application-test.properties +++ /dev/null @@ -1,2 +0,0 @@ -spring.jpa.hibernate.ddl-auto=update -spring.datasource.url=jdbc:h2:mem:jpa3 \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties deleted file mode 100644 index 04b29de41f..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy-on-postgres.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.url=jdbc:postgresql://localhost:5432/quoted-lower-case-strategy -spring.datasource.username=postgres -spring.datasource.password=root - -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.QuotedLowerCaseNamingStrategy -#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties deleted file mode 100644 index 6643c12c8a..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-lower-case-naming-strategy.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.url=jdbc:h2:mem:quoted-lower-case-strategy -spring.datasource.username=sa -spring.datasource.password= - -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.QuotedLowerCaseNamingStrategy -#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties deleted file mode 100644 index 36898d5b4f..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy-on-postgres.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.url=jdbc:postgresql://localhost:5432/quoted-upper-case-strategy -spring.datasource.username=postgres -spring.datasource.password=root - -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.QuotedUpperCaseNamingStrategy -#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties deleted file mode 100644 index 6d56d58749..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/quoted-upper-case-naming-strategy.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.url=jdbc:h2:mem:quoted-upper-case-strategy -spring.datasource.username=sa -spring.datasource.password= - -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.QuotedUpperCaseNamingStrategy -#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties deleted file mode 100644 index 706b12b1b6..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy-on-postgres.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.url=jdbc:postgresql://localhost:5432/spring-strategy -spring.datasource.username=postgres -spring.datasource.password=root - -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy -#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=default-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties deleted file mode 100644 index c9a0c6f24c..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/spring-physical-naming-strategy.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.url=jdbc:h2:mem:spring-strategy -spring.datasource.username=sa -spring.datasource.password= - -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy -#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=default-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties deleted file mode 100644 index b22472bd8f..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy-on-postgres.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.url=jdbc:postgresql://localhost:5432/unquoted-lower-case-strategy -spring.datasource.username=postgres -spring.datasource.password=root - -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.UnquotedLowerCaseNamingStrategy -#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties deleted file mode 100644 index 8083515b4b..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-lower-case-naming-strategy.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.url=jdbc:h2:mem:unquoted-lower-case-strategy -spring.datasource.username=sa -spring.datasource.password= - -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.UnquotedLowerCaseNamingStrategy -#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties deleted file mode 100644 index da03a0d7b5..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy-on-postgres.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.url=jdbc:postgresql://localhost:5432/unquoted-upper-case-strategy -spring.datasource.username=postgres -spring.datasource.password=root - -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.UnquotedUpperCaseNamingStrategy -#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties b/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties deleted file mode 100644 index d1b63e008c..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/com/baeldung/namingstrategy/unquoted-upper-case-naming-strategy.properties +++ /dev/null @@ -1,9 +0,0 @@ -spring.datasource.url=jdbc:h2:mem:unquoted-upper-case-strategy -spring.datasource.username=sa -spring.datasource.password= - -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.hibernate.naming.physical-strategy=com.baeldung.namingstrategy.UnquotedUpperCaseNamingStrategy -#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=upper-case-naming-strategy-ddl.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/test-movie-cleanup.sql b/persistence-modules/spring-data-jpa-4/src/test/resources/test-movie-cleanup.sql deleted file mode 100644 index 90aa15307c..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/test-movie-cleanup.sql +++ /dev/null @@ -1 +0,0 @@ -DELETE FROM Movie; \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-4/src/test/resources/test-movie-data.sql b/persistence-modules/spring-data-jpa-4/src/test/resources/test-movie-data.sql deleted file mode 100644 index 37f8e4fe64..0000000000 --- a/persistence-modules/spring-data-jpa-4/src/test/resources/test-movie-data.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO movie(id, title, director, rating, duration) VALUES(1, 'Godzilla: King of the Monsters', ' Michael Dougherty', 'PG-13', 132); -INSERT INTO movie(id, title, director, rating, duration) VALUES(2, 'Avengers: Endgame', 'Anthony Russo', 'PG-13', 181); -INSERT INTO movie(id, title, director, rating, duration) VALUES(3, 'Captain Marvel', 'Anna Boden', 'PG-13', 123); -INSERT INTO movie(id, title, director, rating, duration) VALUES(4, 'Dumbo', 'Tim Burton', 'PG', 112); -INSERT INTO movie(id, title, director, rating, duration) VALUES(5, 'Booksmart', 'Olivia Wilde', 'R', 102); -INSERT INTO movie(id, title, director, rating, duration) VALUES(6, 'Aladdin', 'Guy Ritchie', 'PG', 128); -INSERT INTO movie(id, title, director, rating, duration) VALUES(7, 'The Sun Is Also a Star', 'Ry Russo-Young', 'PG-13', 100); diff --git a/persistence-modules/spring-data-jpa-5/README.md b/persistence-modules/spring-data-jpa-5/README.md deleted file mode 100644 index 0b78ced66c..0000000000 --- a/persistence-modules/spring-data-jpa-5/README.md +++ /dev/null @@ -1,15 +0,0 @@ -### Relevant Articles: - -- [Spring JPA @Embedded and @EmbeddedId](https://www.baeldung.com/spring-jpa-embedded-method-parameters) -- [Generate Database Schema with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-generate-db-schema) -- [Partial Data Update with Spring Data](https://www.baeldung.com/spring-data-partial-update) - -### Eclipse Config -After importing the project into Eclipse, you may see the following error: -"No persistence xml file found in project" - -This can be ignored: -- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" -Or: -- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator - diff --git a/persistence-modules/spring-data-jpa-5/pom.xml b/persistence-modules/spring-data-jpa-5/pom.xml deleted file mode 100644 index db58a16062..0000000000 --- a/persistence-modules/spring-data-jpa-5/pom.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - 4.0.0 - spring-data-jpa-5 - spring-data-jpa-5 - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - - org.springframework.boot - spring-boot-starter-data-jdbc - - - - org.springframework.boot - spring-boot-starter-cache - - - - com.h2database - h2 - - - - org.mapstruct - mapstruct-jdk8 - ${mapstruct.version} - provided - - - - - - src/main/java - - - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - org.mapstruct - mapstruct-processor - 1.3.1.Final - - - - - - - - - 2.1.9.RELEASE - com.baeldung.springdatageode.app.ClientCacheApp - 1.1.1.RELEASE - 2.1.9.RELEASE - 1.3.1.Final - - - diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/BookApplication.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/BookApplication.java deleted file mode 100644 index 52f06058aa..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/BookApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.composite; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class BookApplication { - - public static void main(String[] args) { - SpringApplication.run(BookApplication.class); - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/entity/Book.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/entity/Book.java deleted file mode 100644 index e4f1727654..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/entity/Book.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.composite.entity; - -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; - -@Entity -public class Book { - - @EmbeddedId - private BookId id; - private String genre; - private Integer price; - - public Book() { - } - - public Book(String author, String name, String genre, Integer price) { - BookId id = new BookId(author, name); - this.id = id; - this.genre = genre; - this.price = price; - } - - public BookId getId() { - return id; - } - - public void setId(BookId id) { - this.id = id; - } - - public String getGenre() { - return genre; - } - - public void setGenre(String genre) { - this.genre = genre; - } - - public Integer getPrice() { - return price; - } - - public void setPrice(Integer price) { - this.price = price; - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/entity/BookId.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/entity/BookId.java deleted file mode 100644 index 1524452412..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/entity/BookId.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung.composite.entity; - -import javax.persistence.Embeddable; -import java.io.Serializable; -import java.util.Objects; - -@Embeddable -public class BookId implements Serializable { - - private String author; - private String name; - - public BookId() { - } - - public BookId(String author, String name) { - this.author = author; - this.name = name; - } - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - BookId bookId = (BookId) o; - return Objects.equals(author, bookId.author) && Objects.equals(name, bookId.name); - } - - @Override - public int hashCode() { - return Objects.hash(author, name); - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/repository/BookRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/repository/BookRepository.java deleted file mode 100644 index d5993eaf79..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/composite/repository/BookRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.composite.repository; - -import com.baeldung.composite.entity.Book; -import com.baeldung.composite.entity.BookId; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface BookRepository extends JpaRepository { - - List findByIdName(String name); - - List findByIdAuthor(String author); - - List findByGenre(String genre); -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java deleted file mode 100644 index a750fcadf7..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.partialupdate; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class PartialUpdateApplication { - - public static void main(String[] args) { - SpringApplication.run(PartialUpdateApplication.class, args); - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java deleted file mode 100644 index 352e361bd9..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.partialupdate.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class ContactPhone { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - public long id; - @Column(nullable=false) - public long customerId; - public String phone; - - @Override - public String toString() { - return phone; - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/Customer.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/Customer.java deleted file mode 100644 index b19d0b7952..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/Customer.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.partialupdate.model; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class Customer { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - public long id; - public String name; - public String phone; - //... - public String phone99; - - @Override public String toString() { - return String.format("Customer %s, Phone: %s", - this.name, this.phone); - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java deleted file mode 100644 index 0ecf206d9a..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.partialupdate.model; - -public class CustomerDto { - private long id; - public String name; - public String phone; - //... - private String phone99; - - public CustomerDto(long id) { - this.id = id; - } - - public CustomerDto(Customer c) { - this.id = c.id; - this.name = c.name; - this.phone = c.phone; - } - - public long getId() { - return this.id; - } - - public Customer convertToEntity() { - Customer c = new Customer(); - c.id = id; - c.name = name; - c.phone = phone; - return c; - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java deleted file mode 100644 index dd053a963d..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.partialupdate.model; - -import java.util.List; - -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToMany; - -@Entity -public class CustomerStructured { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - public long id; - public String name; - @OneToMany(fetch = FetchType.EAGER, targetEntity = ContactPhone.class, mappedBy = "customerId") - public List contactPhones; - - @Override public String toString() { - return String.format("Customer %s, Phone: %s", - this.name, this.contactPhones.stream() - .map(e -> e.toString()).reduce("", String::concat)); - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java deleted file mode 100644 index 4668181e05..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.partialupdate.repository; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -import com.baeldung.partialupdate.model.ContactPhone; - -@Repository -public interface ContactPhoneRepository extends CrudRepository { - ContactPhone findById(long id); - ContactPhone findByCustomerId(long id); -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java deleted file mode 100644 index 43e61df8ab..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.partialupdate.repository; - -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; - -import com.baeldung.partialupdate.model.Customer; - -@Repository -public interface CustomerRepository extends CrudRepository { - Customer findById(long id); - - @Modifying - @Query("update Customer u set u.phone = :phone where u.id = :id") - void updatePhone(@Param(value = "id") long id, @Param(value = "phone") String phone); -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java deleted file mode 100644 index 0f9fd1e92e..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.partialupdate.repository; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -import com.baeldung.partialupdate.model.CustomerStructured; - -@Repository -public interface CustomerStructuredRepository extends CrudRepository { - CustomerStructured findById(long id); -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java deleted file mode 100644 index 9da97a7775..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.baeldung.partialupdate.service; - -import javax.transaction.Transactional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.baeldung.partialupdate.model.ContactPhone; -import com.baeldung.partialupdate.model.Customer; -import com.baeldung.partialupdate.model.CustomerDto; -import com.baeldung.partialupdate.model.CustomerStructured; -import com.baeldung.partialupdate.repository.ContactPhoneRepository; -import com.baeldung.partialupdate.repository.CustomerRepository; -import com.baeldung.partialupdate.repository.CustomerStructuredRepository; -import com.baeldung.partialupdate.util.CustomerMapper; - -@Service -@Transactional -public class CustomerService { - - @Autowired - CustomerRepository repo; - @Autowired - CustomerStructuredRepository repo2; - @Autowired - ContactPhoneRepository repo3; - @Autowired - CustomerMapper mapper; - - public Customer getCustomer(long id) { - return repo.findById(id); - } - - public void updateCustomerWithCustomQuery(long id, String phone) { - repo.updatePhone(id, phone); - } - - public Customer addCustomer(String name) { - Customer myCustomer = new Customer(); - myCustomer.name = name; - repo.save(myCustomer); - return myCustomer; - } - - public Customer updateCustomer(long id, String phone) { - Customer myCustomer = repo.findById(id); - myCustomer.phone = phone; - repo.save(myCustomer); - return myCustomer; - } - - public Customer addCustomer(CustomerDto dto) { - Customer myCustomer = new Customer(); - mapper.updateCustomerFromDto(dto, myCustomer); - repo.save(myCustomer); - return myCustomer; - } - - public Customer updateCustomer(CustomerDto dto) { - Customer myCustomer = repo.findById(dto.getId()); - mapper.updateCustomerFromDto(dto, myCustomer); - repo.save(myCustomer); - return myCustomer; - } - - public CustomerStructured addCustomerStructured(String name) { - CustomerStructured myCustomer = new CustomerStructured(); - myCustomer.name = name; - repo2.save(myCustomer); - return myCustomer; - } - - public void addCustomerPhone(long customerId, String phone) { - ContactPhone myPhone = new ContactPhone(); - myPhone.phone = phone; - myPhone.customerId = customerId; - repo3.save(myPhone); - } - - public CustomerStructured updateCustomerStructured(long id, String name) { - CustomerStructured myCustomer = repo2.findById(id); - myCustomer.name = name; - repo2.save(myCustomer); - return myCustomer; - } - -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java deleted file mode 100644 index 8a666e3e6c..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.partialupdate.util; - -import org.mapstruct.BeanMapping; -import org.mapstruct.Mapper; -import org.mapstruct.MappingTarget; -import org.mapstruct.NullValuePropertyMappingStrategy; - -import com.baeldung.partialupdate.model.Customer; -import com.baeldung.partialupdate.model.CustomerDto; - -@Mapper(componentModel = "spring") -public interface CustomerMapper { - @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) - void updateCustomerFromDto(CustomerDto dto, @MappingTarget Customer entity); -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/AccountApplication.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/AccountApplication.java deleted file mode 100644 index 547992a6c1..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/AccountApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.schemageneration; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class AccountApplication { - - public static void main(String[] args) { - SpringApplication.run(AccountApplication.class, args); - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/HibernateUtil.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/HibernateUtil.java deleted file mode 100644 index 7d69d65705..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/HibernateUtil.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.schemageneration; - -import com.baeldung.schemageneration.model.Account; -import com.baeldung.schemageneration.model.AccountSetting; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.Environment; -import org.hibernate.tool.hbm2ddl.SchemaExport; -import org.hibernate.tool.schema.TargetType; - -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -public class HibernateUtil { - - /** - * Generates database create commands for the specified entities using Hibernate native API, SchemaExport. - * Creation commands are exported into the create.sql file. - */ - public static void generateSchema() { - Map settings = new HashMap<>(); - settings.put(Environment.URL, "jdbc:h2:mem:schema"); - - StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(settings).build(); - - MetadataSources metadataSources = new MetadataSources(serviceRegistry); - metadataSources.addAnnotatedClass(Account.class); - metadataSources.addAnnotatedClass(AccountSetting.class); - Metadata metadata = metadataSources.buildMetadata(); - - SchemaExport schemaExport = new SchemaExport(); - schemaExport.setFormat(true); - schemaExport.setOutputFile("create.sql"); - schemaExport.createOnly(EnumSet.of(TargetType.SCRIPT), metadata); - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/Account.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/Account.java deleted file mode 100644 index 785e275e26..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/Account.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.baeldung.schemageneration.model; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import javax.persistence.Table; -import java.util.ArrayList; -import java.util.List; - -@Entity -@Table(name = "accounts") -public class Account { - - @Id - @GeneratedValue - private Long id; - - @Column(nullable = false, length = 100) - private String name; - - @Column(name = "email_address") - private String emailAddress; - - @OneToMany(mappedBy = "account", cascade = CascadeType.ALL) - private List accountSettings = new ArrayList<>(); - - public Account() { - } - - public Account(String name, String emailAddress) { - this.name = name; - this.emailAddress = emailAddress; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getEmailAddress() { - return emailAddress; - } - - public void setEmailAddress(String emailAddress) { - this.emailAddress = emailAddress; - } - - public List getAccountSettings() { - return accountSettings; - } - - public void setAccountSettings(List accountSettings) { - this.accountSettings = accountSettings; - } - - public void addAccountSetting(AccountSetting setting) { - this.accountSettings.add(setting); - setting.setAccount(this); - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java deleted file mode 100644 index 61e43894a8..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/model/AccountSetting.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.baeldung.schemageneration.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "account_settings") -public class AccountSetting { - - @Id - @GeneratedValue - private Long id; - - @Column(name = "name", nullable = false) - private String settingName; - - @Column(name = "value", nullable = false) - private String settingValue; - - @ManyToOne() - @JoinColumn(name ="account_id", nullable = false) - private Account account; - - public AccountSetting() { - } - - public AccountSetting(String settingName, String settingValue) { - this.settingName = settingName; - this.settingValue = settingValue; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getSettingName() { - return settingName; - } - - public void setSettingName(String settingName) { - this.settingName = settingName; - } - - public String getSettingValue() { - return settingValue; - } - - public void setSettingValue(String settingValue) { - this.settingValue = settingValue; - } - - public Account getAccount() { - return account; - } - - public void setAccount(Account account) { - this.account = account; - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java deleted file mode 100644 index dc57ffe6d3..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.schemageneration.repository; - -import com.baeldung.schemageneration.model.Account; -import org.springframework.data.repository.CrudRepository; - -public interface AccountRepository extends CrudRepository { - Account findByName(String name); -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java deleted file mode 100644 index c2b8ff7398..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/schemageneration/repository/AccountSettingRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.schemageneration.repository; - -import com.baeldung.schemageneration.model.AccountSetting; -import org.springframework.data.repository.CrudRepository; - -public interface AccountSettingRepository extends CrudRepository { - AccountSetting findByAccountId(Long accountId); -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-5/src/main/resources/application.properties deleted file mode 100644 index f55ad438ff..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/resources/application.properties +++ /dev/null @@ -1,13 +0,0 @@ - -spring.datasource.url=jdbc:h2:mem:baeldung - -# JPA-Schema-Generation -# Use below configuration to generate database schema create commands based on the entity models -# and export them into the create.sql file -#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=create.sql -#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-source=metadata -#spring.jpa.properties.hibernate.format_sql=true - -spring.jpa.show-sql=true - diff --git a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/composite/repository/BookRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/composite/repository/BookRepositoryIntegrationTest.java deleted file mode 100644 index 9d25acbd96..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/composite/repository/BookRepositoryIntegrationTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.baeldung.composite.repository; - -import com.baeldung.composite.BookApplication; -import com.baeldung.composite.entity.Book; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = BookApplication.class) -public class BookRepositoryIntegrationTest { - - public static final String JAVA_101 = "Java101"; - public static final String JANE = "Jane"; - public static final String TECH = "Tech"; - @Autowired - BookRepository repository; - - @Before - public void setUp() { - Book book1 = new Book("John", JAVA_101, TECH, 20); - Book book2 = new Book(JANE, JAVA_101, "Arch", 25); - Book book3 = new Book(JANE, "Scala101", TECH, 23); - - repository.saveAll(Arrays.asList(book1, book2, book3)); - } - - @After - public void tearDown() { - repository.deleteAll(); - } - - @Test - public void testFindByName() { - List books = repository.findByIdName(JAVA_101); - - assertEquals(2, books.size()); - } - - @Test - public void testFindByAuthor() { - List books = repository.findByIdAuthor(JANE); - - assertEquals(2, books.size()); - } - - @Test - public void testFindByGenre() { - List books = repository.findByGenre(TECH); - - assertEquals(2, books.size()); - } -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java deleted file mode 100644 index 874e18c4ad..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.baeldung.partialupdate; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.partialupdate.model.Customer; -import com.baeldung.partialupdate.model.CustomerDto; -import com.baeldung.partialupdate.model.CustomerStructured; -import com.baeldung.partialupdate.service.CustomerService; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = PartialUpdateApplication.class) -public class PartialUpdateUnitTest { - - @Autowired - CustomerService service; - - @Test - public void givenCustomer_whenUpdate_thenSuccess() { - Customer myCustomer = service.addCustomer("John"); - myCustomer = service.updateCustomer(myCustomer.id, "+00"); - assertEquals("+00", myCustomer.phone); - } - - @Test - public void givenCustomer_whenUpdateWithQuery_thenSuccess() { - Customer myCustomer = service.addCustomer("John"); - service.updateCustomerWithCustomQuery(myCustomer.id, "+88"); - myCustomer = service.getCustomer(myCustomer.id); - assertEquals("+88", myCustomer.phone); - } - - @Test - public void givenCustomerDto_whenUpdateWithMapper_thenSuccess() { - CustomerDto dto = new CustomerDto(new Customer()); - dto.name = "Johnny"; - Customer entity = service.addCustomer(dto); - - CustomerDto dto2 = new CustomerDto(entity.id); - dto2.phone = "+44"; - entity = service.updateCustomer(dto2); - - assertEquals("Johnny", entity.name); - } - - @Test - public void givenCustomerStructured_whenUpdateCustomerPhone_thenSuccess() { - CustomerStructured myCustomer = service.addCustomerStructured("John"); - assertEquals(null, myCustomer.contactPhones); - - service.addCustomerPhone(myCustomer.id, "+44"); - myCustomer = service.updateCustomerStructured(myCustomer.id, "Mr. John"); - - assertNotEquals(null, myCustomer.contactPhones); - assertEquals(1, myCustomer.contactPhones.size()); - } -} diff --git a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java deleted file mode 100644 index 86a7671fe4..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/schemageneration/AccountRepositoryIntegrationTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.baeldung.schemageneration; - -import com.baeldung.schemageneration.model.Account; -import com.baeldung.schemageneration.model.AccountSetting; -import com.baeldung.schemageneration.repository.AccountRepository; -import com.baeldung.schemageneration.repository.AccountSettingRepository; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = AccountApplication.class) -public class AccountRepositoryIntegrationTest { - - private static final String USER_NAME = "Eduard"; - private static final String USER_EMAIL_ADDRESS = "eduard@gmx.com"; - private static final String ACCOUNT_SETTING_NAME = "Timezone"; - private static final String ACCOUNT_SETTING_VALUE = "UTC+02"; - - @Autowired - private AccountRepository accountRepository; - - @Autowired - private AccountSettingRepository accountSettingRepository; - - @After - public void tearDown() { - accountRepository.deleteAll(); - } - - @Test - public void givenNewAccount_whenSave_thenSuccess() { - Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS); - accountRepository.save(account); - - assertEquals(1, accountRepository.count()); - } - - @Test - public void givenSavedAccount_whenFindByName_thenFound() { - Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS); - accountRepository.save(account); - - Account accountFound = accountRepository.findByName(USER_NAME); - - assertNotNull(accountFound); - assertEquals(USER_NAME, accountFound.getName()); - assertEquals(USER_EMAIL_ADDRESS, accountFound.getEmailAddress()); - } - - @Test - public void givenSavedAccount_whenAccountSettingIsAdded_thenPersisted() { - Account account = new Account(USER_NAME, USER_EMAIL_ADDRESS); - account.addAccountSetting(new AccountSetting(ACCOUNT_SETTING_NAME, ACCOUNT_SETTING_VALUE)); - accountRepository.save(account); - - Account accountFound = accountRepository.findByName(USER_NAME); - assertNotNull(accountFound); - AccountSetting accountSetting = accountSettingRepository.findByAccountId(accountFound.getId()); - - assertNotNull(accountSetting); - assertEquals(ACCOUNT_SETTING_NAME, accountSetting.getSettingName()); - assertEquals(ACCOUNT_SETTING_VALUE, accountSetting.getSettingValue()); - } - -} diff --git a/persistence-modules/spring-data-jpa-5/src/test/resources/application-test.properties b/persistence-modules/spring-data-jpa-5/src/test/resources/application-test.properties deleted file mode 100644 index e3d39fe1e2..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/test/resources/application-test.properties +++ /dev/null @@ -1,3 +0,0 @@ -spring.jpa.hibernate.ddl-auto=update -spring.datasource.url=jdbc:h2:mem:baeldung - diff --git a/persistence-modules/spring-data-jpa/README.md b/persistence-modules/spring-data-jpa/README.md deleted file mode 100644 index 1c43edf42b..0000000000 --- a/persistence-modules/spring-data-jpa/README.md +++ /dev/null @@ -1,25 +0,0 @@ -========= - -## Spring Data JPA Example Project - -### Relevant Articles: -- [Spring JPA – Multiple Databases](https://www.baeldung.com/spring-data-jpa-multiple-databases) -- [Spring Data JPA – Adding a Method in All Repositories](https://www.baeldung.com/spring-data-jpa-method-in-all-repositories) -- [An Advanced Tagging Implementation with JPA](https://www.baeldung.com/jpa-tagging-advanced) -- [Spring Data Annotations](https://www.baeldung.com/spring-data-annotations) -- [Spring Data Java 8 Support](https://www.baeldung.com/spring-data-java-8) -- [A Simple Tagging Implementation with JPA](https://www.baeldung.com/jpa-tagging) -- [Spring Data Composable Repositories](https://www.baeldung.com/spring-data-composable-repositories) -- [Query Entities by Dates and Times with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-query-by-date) -- [DDD Aggregates and @DomainEvents](https://www.baeldung.com/spring-data-ddd) -- [Spring Data – CrudRepository save() Method](https://www.baeldung.com/spring-data-crud-repository-save) - -### Eclipse Config -After importing the project into Eclipse, you may see the following error: -"No persistence xml file found in project" - -This can be ignored: -- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" -Or: -- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator - diff --git a/persistence-modules/spring-data-jpa/pom.xml b/persistence-modules/spring-data-jpa/pom.xml deleted file mode 100644 index ddd7e17dcd..0000000000 --- a/persistence-modules/spring-data-jpa/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - 4.0.0 - spring-data-jpa - spring-data-jpa - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.hibernate - hibernate-ehcache - - - org.hibernate - hibernate-envers - - - - com.h2database - h2 - - - - - org.testcontainers - postgresql - ${testcontainers.postgresql.version} - test - - - - org.postgresql - postgresql - - - - - org.springframework.security - spring-security-test - test - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - - - - com.google.guava - guava - ${guava.version} - - - - - com.baeldung.boot.Application - 1.10.6 - 42.2.5 - 21.0 - - - \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/Application.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/Application.java deleted file mode 100644 index c66921a3ca..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/Application.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.boot; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; - -import com.baeldung.boot.daos.impl.ExtendedRepositoryImpl; - -@SpringBootApplication -@EnableJpaRepositories(repositoryBaseClass = ExtendedRepositoryImpl.class) -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java deleted file mode 100644 index 76d5887030..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/config/PersistenceConfiguration.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.boot.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import com.baeldung.boot.services.IBarService; -import com.baeldung.boot.services.impl.BarSpringDataJpaService; - -@Configuration -@Profile("!tc") -@EnableTransactionManagement -@EnableJpaAuditing -public class PersistenceConfiguration { - - @Bean - public IBarService barSpringDataJpaService() { - return new BarSpringDataJpaService(); - } - -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ArticleRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ArticleRepository.java deleted file mode 100644 index 73397ad42e..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ArticleRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.boot.daos; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import com.baeldung.boot.domain.Article; - -import java.util.Date; -import java.util.List; - -public interface ArticleRepository extends JpaRepository { - - List
findAllByPublicationDate(Date publicationDate); - - List
findAllByPublicationTimeBetween(Date publicationTimeStart, - Date publicationTimeEnd); - - @Query("select a from Article a where a.creationDateTime <= :creationDateTime") - List
findAllWithCreationDateTimeBefore( - @Param("creationDateTime") Date creationDateTime); - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java deleted file mode 100644 index 0aebe34921..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.boot.daos; - -import org.springframework.stereotype.Repository; - -import com.baeldung.boot.domain.Item; - -@Repository -public interface CustomItemRepository { - - void deleteCustom(Item entity); - - Item findItemById(Long id); - - void findThenDelete(Long id); - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java deleted file mode 100644 index 832d61408c..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/CustomItemTypeRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.boot.daos; - -import org.springframework.stereotype.Repository; - -import com.baeldung.boot.domain.ItemType; - -@Repository -public interface CustomItemTypeRepository { - - void deleteCustom(ItemType entity); - - void findThenDelete(Long id); -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java deleted file mode 100644 index adb2af4320..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.boot.daos; - -import java.io.Serializable; -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.NoRepositoryBean; - -@NoRepositoryBean -public interface ExtendedRepository extends JpaRepository { - - List findByAttributeContainsText(String attributeName, String text); - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java deleted file mode 100644 index c9b0192536..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ExtendedStudentRepository.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.boot.daos; - -import com.baeldung.boot.domain.Student; - -public interface ExtendedStudentRepository extends ExtendedRepository { -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java deleted file mode 100644 index 921fabe3fb..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IBarCrudRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.boot.daos; - -import org.springframework.data.repository.CrudRepository; - -import com.baeldung.boot.domain.Bar; - -import java.io.Serializable; - -public interface IBarCrudRepository extends CrudRepository { - // -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IFooDao.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IFooDao.java deleted file mode 100644 index d537772076..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/IFooDao.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.boot.daos; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import com.baeldung.boot.domain.Foo; - -public interface IFooDao extends JpaRepository { - - @Query("SELECT f FROM Foo f WHERE LOWER(f.name) = LOWER(:name)") - Foo retrieveByName(@Param("name") String name); -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/InventoryRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/InventoryRepository.java deleted file mode 100644 index 606f3993d5..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/InventoryRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.boot.daos; - -import org.springframework.data.repository.CrudRepository; - -import com.baeldung.boot.domain.MerchandiseEntity; - -public interface InventoryRepository extends CrudRepository { -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java deleted file mode 100644 index 413c09e968..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ItemTypeRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.boot.daos; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import com.baeldung.boot.domain.ItemType; - -@Repository -public interface ItemTypeRepository extends JpaRepository, CustomItemTypeRepository, CustomItemRepository { -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/LocationRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/LocationRepository.java deleted file mode 100644 index 697ce295d0..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/LocationRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.boot.daos; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import com.baeldung.boot.domain.Location; - -@Repository -public interface LocationRepository extends JpaRepository { -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java deleted file mode 100644 index 3a2ea3cda5..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/ReadOnlyLocationRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.boot.daos; - -import java.util.Optional; - -import org.springframework.data.repository.Repository; - -import com.baeldung.boot.domain.Location; - -@org.springframework.stereotype.Repository -public interface ReadOnlyLocationRepository extends Repository { - - Optional findById(Long id); - - Location save(Location location); -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/StoreRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/StoreRepository.java deleted file mode 100644 index ae13f75f66..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/StoreRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.boot.daos; - -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import com.baeldung.boot.domain.Store; - -@Repository -public interface StoreRepository extends JpaRepository { - List findStoreByLocationId(Long locationId); -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java deleted file mode 100644 index 820a2cdd41..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemRepositoryImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.boot.daos.impl; - -import javax.persistence.EntityManager; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; - -import com.baeldung.boot.daos.CustomItemRepository; -import com.baeldung.boot.domain.Item; - -@Repository -public class CustomItemRepositoryImpl implements CustomItemRepository { - - @Autowired - private EntityManager entityManager; - - @Override - public void deleteCustom(Item item) { - entityManager.remove(item); - } - - @Override - public Item findItemById(Long id) { - return entityManager.find(Item.class, id); - } - - @Override - public void findThenDelete(Long id) { - final Item item = entityManager.find(Item.class, id); - entityManager.remove(item); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java deleted file mode 100644 index e057f36b26..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/CustomItemTypeRepositoryImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.boot.daos.impl; - -import javax.persistence.EntityManager; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; - -import com.baeldung.boot.daos.CustomItemTypeRepository; -import com.baeldung.boot.domain.ItemType; - -@Repository -public class CustomItemTypeRepositoryImpl implements CustomItemTypeRepository { - - @Autowired - private EntityManager entityManager; - - @Override - public void deleteCustom(ItemType itemType) { - entityManager.remove(itemType); - } - - @Override - public void findThenDelete(Long id) { - ItemType itemTypeToDelete = entityManager.find(ItemType.class, id); - entityManager.remove(itemTypeToDelete); - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java deleted file mode 100644 index fbe6695844..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/impl/ExtendedRepositoryImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.boot.daos.impl; - -import java.io.Serializable; -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import javax.transaction.Transactional; - -import org.springframework.data.jpa.repository.support.JpaEntityInformation; -import org.springframework.data.jpa.repository.support.SimpleJpaRepository; - -import com.baeldung.boot.daos.ExtendedRepository; - -public class ExtendedRepositoryImpl extends SimpleJpaRepository implements ExtendedRepository { - - private EntityManager entityManager; - - public ExtendedRepositoryImpl(JpaEntityInformation entityInformation, EntityManager entityManager) { - super(entityInformation, entityManager); - this.entityManager = entityManager; - } - - @Transactional - public List findByAttributeContainsText(String attributeName, String text) { - CriteriaBuilder builder = entityManager.getCriteriaBuilder(); - CriteriaQuery query = builder.createQuery(getDomainClass()); - Root root = query.from(getDomainClass()); - query.select(root).where(builder.like(root. get(attributeName), "%" + text + "%")); - TypedQuery q = entityManager.createQuery(query); - return q.getResultList(); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/PossessionRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/PossessionRepository.java deleted file mode 100644 index e102754c18..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/PossessionRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.boot.daos.user; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.baeldung.boot.domain.Possession; - -public interface PossessionRepository extends JpaRepository { - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepository.java deleted file mode 100644 index 53f692ff28..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepository.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.baeldung.boot.daos.user; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import com.baeldung.boot.domain.User; - -import java.time.LocalDate; -import java.util.Collection; -import java.util.List; -import java.util.stream.Stream; - -public interface UserRepository extends JpaRepository , UserRepositoryCustom{ - - Stream findAllByName(String name); - - @Query("SELECT u FROM User u WHERE u.status = 1") - Collection findAllActiveUsers(); - - @Query("select u from User u where u.email like '%@gmail.com'") - List findUsersWithGmailAddress(); - - @Query(value = "SELECT * FROM Users u WHERE u.status = 1", nativeQuery = true) - Collection findAllActiveUsersNative(); - - @Query("SELECT u FROM User u WHERE u.status = ?1") - User findUserByStatus(Integer status); - - @Query(value = "SELECT * FROM Users u WHERE u.status = ?1", nativeQuery = true) - User findUserByStatusNative(Integer status); - - @Query("SELECT u FROM User u WHERE u.status = ?1 and u.name = ?2") - User findUserByStatusAndName(Integer status, String name); - - @Query("SELECT u FROM User u WHERE u.status = :status and u.name = :name") - User findUserByStatusAndNameNamedParams(@Param("status") Integer status, @Param("name") String name); - - @Query(value = "SELECT * FROM Users u WHERE u.status = :status AND u.name = :name", nativeQuery = true) - User findUserByStatusAndNameNamedParamsNative(@Param("status") Integer status, @Param("name") String name); - - @Query("SELECT u FROM User u WHERE u.status = :status and u.name = :name") - User findUserByUserStatusAndUserName(@Param("status") Integer userStatus, @Param("name") String userName); - - @Query("SELECT u FROM User u WHERE u.name like ?1%") - User findUserByNameLike(String name); - - @Query("SELECT u FROM User u WHERE u.name like :name%") - User findUserByNameLikeNamedParam(@Param("name") String name); - - @Query(value = "SELECT * FROM users u WHERE u.name LIKE ?1%", nativeQuery = true) - User findUserByNameLikeNative(String name); - - @Query(value = "SELECT u FROM User u") - List findAllUsers(Sort sort); - - @Query(value = "SELECT u FROM User u ORDER BY id") - Page findAllUsersWithPagination(Pageable pageable); - - @Query(value = "SELECT * FROM Users ORDER BY id", countQuery = "SELECT count(*) FROM Users", nativeQuery = true) - Page findAllUsersWithPaginationNative(Pageable pageable); - - @Modifying - @Query("update User u set u.status = :status where u.name = :name") - int updateUserSetStatusForName(@Param("status") Integer status, @Param("name") String name); - - @Modifying - @Query(value = "UPDATE Users u SET u.status = ? WHERE u.name = ?", nativeQuery = true) - int updateUserSetStatusForNameNative(Integer status, String name); - - @Query(value = "INSERT INTO Users (name, age, email, status, active) VALUES (:name, :age, :email, :status, :active)", nativeQuery = true) - @Modifying - void insertUser(@Param("name") String name, @Param("age") Integer age, @Param("email") String email, @Param("status") Integer status, @Param("active") boolean active); - - @Modifying - @Query(value = "UPDATE Users u SET status = ? WHERE u.name = ?", nativeQuery = true) - int updateUserSetStatusForNameNativePostgres(Integer status, String name); - - @Query(value = "SELECT u FROM User u WHERE u.name IN :names") - List findUserByNameList(@Param("names") Collection names); - - void deleteAllByCreationDateAfter(LocalDate date); - - @Modifying(clearAutomatically = true, flushAutomatically = true) - @Query("update User u set u.active = false where u.lastLoginDate < :date") - void deactivateUsersNotLoggedInSince(@Param("date") LocalDate date); - - @Modifying(clearAutomatically = true, flushAutomatically = true) - @Query("delete User u where u.active = false") - int deleteDeactivatedUsers(); - - @Modifying(clearAutomatically = true, flushAutomatically = true) - @Query(value = "alter table USERS add column deleted int(1) not null default 0", nativeQuery = true) - void addDeletedColumn(); -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java deleted file mode 100644 index c586b54027..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustom.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.boot.daos.user; - -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.function.Predicate; - -import com.baeldung.boot.domain.User; - -public interface UserRepositoryCustom { - List findUserByEmails(Set emails); - - List findAllUsersByPredicates(Collection> predicates); -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java deleted file mode 100644 index 63a743b6b5..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/daos/user/UserRepositoryCustomImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.baeldung.boot.daos.user; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Path; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - -import com.baeldung.boot.domain.User; - -public class UserRepositoryCustomImpl implements UserRepositoryCustom { - - @PersistenceContext - private EntityManager entityManager; - - @Override - public List findUserByEmails(Set emails) { - CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - CriteriaQuery query = cb.createQuery(User.class); - Root user = query.from(User.class); - - Path emailPath = user.get("email"); - - List predicates = new ArrayList<>(); - for (String email : emails) { - - predicates.add(cb.like(emailPath, email)); - - } - query.select(user) - .where(cb.or(predicates.toArray(new Predicate[predicates.size()]))); - - return entityManager.createQuery(query) - .getResultList(); - } - - @Override - public List findAllUsersByPredicates(Collection> predicates) { - List allUsers = entityManager.createQuery("select u from User u", User.class).getResultList(); - Stream allUsersStream = allUsers.stream(); - for (java.util.function.Predicate predicate : predicates) { - allUsersStream = allUsersStream.filter(predicate); - } - - return allUsersStream.collect(Collectors.toList()); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java deleted file mode 100644 index e435f4c85c..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Transient; - -import org.springframework.context.ApplicationEventPublisher; - -@Entity -class Aggregate { - @Transient - private ApplicationEventPublisher eventPublisher; - @Id - private long id; - - private Aggregate() { - } - - Aggregate(long id, ApplicationEventPublisher eventPublisher) { - this.id = id; - this.eventPublisher = eventPublisher; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "DomainEntity [id=" + id + "]"; - } - - void domainOperation() { - // some business logic - if (eventPublisher != null) { - eventPublisher.publishEvent(new DomainEvent()); - } - } - - long getId() { - return id; - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java deleted file mode 100644 index 08f61db812..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import java.util.ArrayList; -import java.util.Collection; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Transient; - -import org.springframework.data.domain.AfterDomainEventPublication; -import org.springframework.data.domain.DomainEvents; - -@Entity -public class Aggregate2 { - @Transient - private final Collection domainEvents; - @Id - @GeneratedValue - private long id; - - public Aggregate2() { - domainEvents = new ArrayList<>(); - } - - @AfterDomainEventPublication - public void clearEvents() { - domainEvents.clear(); - } - - public void domainOperation() { - // some domain operation - domainEvents.add(new DomainEvent()); - } - - @DomainEvents - public Collection events() { - return domainEvents; - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java deleted file mode 100644 index 7f09c410fc..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate2Repository.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import org.springframework.data.repository.CrudRepository; - -public interface Aggregate2Repository extends CrudRepository { - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java deleted file mode 100644 index f664322a59..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -import org.springframework.data.domain.AbstractAggregateRoot; - -@Entity -public class Aggregate3 extends AbstractAggregateRoot { - @Id - @GeneratedValue - private long id; - - public void domainOperation() { - // some domain operation - registerEvent(new DomainEvent()); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java deleted file mode 100644 index 93f50bb5cf..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/Aggregate3Repository.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import org.springframework.data.repository.CrudRepository; - -/** - * @author goobar - * - */ -public interface Aggregate3Repository extends CrudRepository { - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java deleted file mode 100644 index 1c2d3884bf..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/AggregateRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import org.springframework.data.repository.CrudRepository; - -public interface AggregateRepository extends CrudRepository { - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java deleted file mode 100644 index 34cf21463b..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DddConfig.java +++ /dev/null @@ -1,15 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.PropertySource; - -@SpringBootConfiguration -@EnableAutoConfiguration -@PropertySource("classpath:/ddd.properties") -public class DddConfig { - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java deleted file mode 100644 index e7626e742d..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainEvent.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -class DomainEvent { - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainService.java deleted file mode 100644 index 80aa5ca6cb..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/ddd/event/DomainService.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import javax.transaction.Transactional; - -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.stereotype.Service; - -@Service -public class DomainService { - private final ApplicationEventPublisher eventPublisher; - private final AggregateRepository repository; - - public DomainService(AggregateRepository repository, ApplicationEventPublisher eventPublisher) { - this.repository = repository; - this.eventPublisher = eventPublisher; - } - - @Transactional - public void serviceDomainOperation(long entityId) { - repository.findById(entityId) - .ifPresent(entity -> { - entity.domainOperation(); - repository.save(entity); - eventPublisher.publishEvent(new DomainEvent()); - }); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Article.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Article.java deleted file mode 100644 index de4dbed1a0..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Article.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.*; -import java.util.Date; - -@Entity -public class Article { - - @Id - @GeneratedValue - private Integer id; - @Temporal(TemporalType.DATE) - private Date publicationDate; - @Temporal(TemporalType.TIME) - private Date publicationTime; - @Temporal(TemporalType.TIMESTAMP) - private Date creationDateTime; - - public Integer getId() { - return id; - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Bar.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Bar.java deleted file mode 100644 index 35d1903801..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Bar.java +++ /dev/null @@ -1,220 +0,0 @@ -package com.baeldung.boot.domain; - -import com.google.common.collect.Sets; -import org.hibernate.annotations.OrderBy; -import org.hibernate.envers.Audited; -import org.jboss.logging.Logger; -import org.springframework.data.annotation.CreatedBy; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedBy; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.Date; -import java.util.Set; - -@Entity -@NamedQuery(name = "Bar.findAll", query = "SELECT b FROM Bar b") -@Audited -@EntityListeners(AuditingEntityListener.class) -public class Bar implements Serializable { - - private static Logger logger = Logger.getLogger(Bar.class); - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - private int id; - - @Column(name = "name") - private String name; - @OneToMany(mappedBy = "bar", cascade = CascadeType.ALL, fetch = FetchType.LAZY) - @OrderBy(clause = "NAME DESC") - // @NotAudited - private Set fooSet = Sets.newHashSet(); - @Column(name = "operation") - private String operation; - @Column(name = "timestamp") - private long timestamp; - @Column(name = "created_date", updatable = false, nullable = false) - @CreatedDate - private long createdDate; - @Column(name = "modified_date") - @LastModifiedDate - private long modifiedDate; - @Column(name = "created_by") - @CreatedBy - private String createdBy; - @Column(name = "modified_by") - @LastModifiedBy - private String modifiedBy; - - public Bar() { - super(); - } - - public Bar(final String name) { - super(); - - this.name = name; - } - - public Set getFooSet() { - return fooSet; - } - - // API - - public void setFooSet(final Set fooSet) { - this.fooSet = fooSet; - } - - public int getId() { - return id; - } - - public void setId(final int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public OPERATION getOperation() { - return OPERATION.parse(operation); - } - - public void setOperation(final String operation) { - this.operation = operation; - } - - public void setOperation(final OPERATION operation) { - this.operation = operation.getValue(); - } - - public long getTimestamp() { - return timestamp; - } - - public void setTimestamp(final long timestamp) { - this.timestamp = timestamp; - } - - public long getCreatedDate() { - return createdDate; - } - - public void setCreatedDate(final long createdDate) { - this.createdDate = createdDate; - } - - public long getModifiedDate() { - return modifiedDate; - } - - public void setModifiedDate(final long modifiedDate) { - this.modifiedDate = modifiedDate; - } - - public String getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(final String createdBy) { - this.createdBy = createdBy; - } - - public String getModifiedBy() { - return modifiedBy; - } - - public void setModifiedBy(final String modifiedBy) { - this.modifiedBy = modifiedBy; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final Bar other = (Bar) obj; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - return true; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("Bar [name=").append(name).append("]"); - return builder.toString(); - } - - @PrePersist - public void onPrePersist() { - logger.info("@PrePersist"); - audit(OPERATION.INSERT); - } - - @PreUpdate - public void onPreUpdate() { - logger.info("@PreUpdate"); - audit(OPERATION.UPDATE); - } - - @PreRemove - public void onPreRemove() { - logger.info("@PreRemove"); - audit(OPERATION.DELETE); - } - - private void audit(final OPERATION operation) { - setOperation(operation); - setTimestamp((new Date()).getTime()); - } - - public enum OPERATION { - INSERT, UPDATE, DELETE; - private String value; - - OPERATION() { - value = toString(); - } - - public static OPERATION parse(final String value) { - OPERATION operation = null; - for (final OPERATION op : OPERATION.values()) { - if (op.getValue().equals(value)) { - operation = op; - break; - } - } - return operation; - } - - public String getValue() { - return value; - } - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Foo.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Foo.java deleted file mode 100644 index 5030e5600b..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Foo.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.baeldung.boot.domain; - -import org.hibernate.envers.Audited; - -import javax.persistence.*; -import java.io.Serializable; - -@NamedNativeQueries({@NamedNativeQuery(name = "callGetAllFoos", query = "CALL GetAllFoos()", resultClass = Foo.class), @NamedNativeQuery(name = "callGetFoosByName", query = "CALL GetFoosByName(:fooName)", resultClass = Foo.class)}) -@Entity -@Audited -// @Proxy(lazy = false) -public class Foo implements Serializable { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - private long id; - - @Column(name = "name", nullable = false) - private String name; - - @ManyToOne(targetEntity = Bar.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER) - @JoinColumn(name = "BAR_ID") - private Bar bar = new Bar(); - - public Foo() { - super(); - } - - public Foo(final String name) { - super(); - this.name = name; - } - - // - - public Bar getBar() { - return bar; - } - - public void setBar(final Bar bar) { - this.bar = bar; - } - - public long getId() { - return id; - } - - public void setId(final long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - // - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final Foo other = (Foo) obj; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - return true; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("Foo [name=").append(name).append("]"); - return builder.toString(); - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Item.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Item.java deleted file mode 100644 index 8ac06af15a..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Item.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.baeldung.boot.domain; - -import java.math.BigDecimal; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToOne; - -@Entity -public class Item { - - private String color; - private String grade; - - @Id - private Long id; - - @ManyToOne - private ItemType itemType; - - private String name; - private BigDecimal price; - @ManyToOne - private Store store; - - public String getColor() { - return color; - } - - public String getGrade() { - return grade; - } - - public Long getId() { - return id; - } - - public ItemType getItemType() { - return itemType; - } - - public String getName() { - return name; - } - - public BigDecimal getPrice() { - return price; - } - - public Store getStore() { - return store; - } - - public void setColor(String color) { - this.color = color; - } - - public void setGrade(String grade) { - this.grade = grade; - } - - public void setId(Long id) { - this.id = id; - } - - public void setItemType(ItemType itemType) { - this.itemType = itemType; - } - - public void setName(String name) { - this.name = name; - } - - public void setPrice(BigDecimal price) { - this.price = price; - } - - public void setStore(Store store) { - this.store = store; - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/ItemType.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/ItemType.java deleted file mode 100644 index 8a52a9847c..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/ItemType.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.boot.domain; - -import java.util.ArrayList; -import java.util.List; - -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; - -@Entity -public class ItemType { - - @Id - private Long id; - @OneToMany(cascade = CascadeType.ALL) - @JoinColumn(name = "ITEM_TYPE_ID") - private List items = new ArrayList<>(); - - private String name; - - public Long getId() { - return id; - } - - public List getItems() { - return items; - } - - public String getName() { - return name; - } - - public void setId(Long id) { - this.id = id; - } - - public void setItems(List items) { - this.items = items; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/KVTag.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/KVTag.java deleted file mode 100644 index 1901f43c0a..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/KVTag.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.Embeddable; - -@Embeddable -public class KVTag { - private String key; - private String value; - - public KVTag() { - } - - public KVTag(String key, String value) { - super(); - this.key = key; - this.value = value; - } - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Location.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Location.java deleted file mode 100644 index 9c1b93d551..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Location.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.baeldung.boot.domain; - -import java.util.ArrayList; -import java.util.List; - -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; - -@Entity -public class Location { - - private String city; - private String country; - @Id - private Long id; - - @OneToMany(cascade = CascadeType.ALL) - @JoinColumn(name = "LOCATION_ID") - private List stores = new ArrayList<>(); - - public String getCity() { - return city; - } - - public String getCountry() { - return country; - } - - public Long getId() { - return id; - } - - public List getStores() { - return stores; - } - - public void setCity(String city) { - this.city = city; - } - - public void setCountry(String country) { - this.country = country; - } - - public void setId(Long id) { - this.id = id; - } - - public void setStores(List stores) { - this.stores = stores; - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java deleted file mode 100644 index e94c23de86..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/MerchandiseEntity.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import java.math.BigDecimal; - -@Entity -public class MerchandiseEntity { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; - - private String title; - - private BigDecimal price; - - private String brand; - - public MerchandiseEntity() { - } - - public MerchandiseEntity(String title, BigDecimal price) { - this.title = title; - this.price = price; - } - - public Long getId() { - return id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public BigDecimal getPrice() { - return price; - } - - public void setPrice(BigDecimal price) { - this.price = price; - } - - public String getBrand() { - return brand; - } - - public void setBrand(String brand) { - this.brand = brand; - } - - @Override - public String toString() { - return "MerchandiseEntity{" + - "id=" + id + - ", title='" + title + '\'' + - ", price=" + price + - ", brand='" + brand + '\'' + - '}'; - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Possession.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Possession.java deleted file mode 100644 index f13491ad82..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Possession.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.*; -import com.baeldung.boot.domain.Possession; - -@Entity -@Table -public class Possession { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - private String name; - - public Possession() { - super(); - } - - public Possession(final String name) { - super(); - - this.name = name; - } - - public long getId() { - return id; - } - - public void setId(final int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + (int) (id ^ (id >>> 32)); - result = (prime * result) + ((name == null) ? 0 : name.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final Possession other = (Possession) obj; - if (id != other.id) { - return false; - } - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - return true; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("Possesion [id=").append(id).append(", name=").append(name).append("]"); - return builder.toString(); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/SkillTag.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/SkillTag.java deleted file mode 100644 index 0933a3e6af..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/SkillTag.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.Embeddable; - -@Embeddable -public class SkillTag { - private String name; - private int value; - - public SkillTag() { - } - - public SkillTag(String name, int value) { - super(); - this.name = name; - this.value = value; - } - - public int getValue() { - return value; - } - - public void setValue(int value) { - this.value = value; - } - - public String getName() { - return name; - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Store.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Store.java deleted file mode 100644 index 5b4b831cc7..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Store.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.baeldung.boot.domain; - -import java.util.ArrayList; -import java.util.List; - -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; - -@Entity -public class Store { - - private Boolean active; - @Id - private Long id; - @OneToMany(cascade = CascadeType.ALL) - @JoinColumn(name = "STORE_ID") - private List items = new ArrayList<>(); - private Long itemsSold; - - @ManyToOne - private Location location; - - private String name; - - public Boolean getActive() { - return active; - } - - public Long getId() { - return id; - } - - public List getItems() { - return items; - } - - public Long getItemsSold() { - return itemsSold; - } - - public Location getLocation() { - return location; - } - - public String getName() { - return name; - } - - public void setActive(Boolean active) { - this.active = active; - } - - public void setId(Long id) { - this.id = id; - } - - public void setItems(List items) { - this.items = items; - } - - public void setItemsSold(Long itemsSold) { - this.itemsSold = itemsSold; - } - - public void setLocation(Location location) { - this.location = location; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Student.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Student.java deleted file mode 100644 index 1003167cc7..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/Student.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.ElementCollection; -import javax.persistence.Entity; -import javax.persistence.Id; -import java.util.ArrayList; -import java.util.List; - -@Entity -public class Student { - - @Id - private long id; - private String name; - - @ElementCollection - private List tags = new ArrayList<>(); - - @ElementCollection - private List skillTags = new ArrayList<>(); - - @ElementCollection - private List kvTags = new ArrayList<>(); - - public Student() { - } - - public Student(long id, String name) { - super(); - this.id = id; - this.name = name; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getTags() { - return tags; - } - - public void setTags(List tags) { - this.tags.addAll(tags); - } - - public List getSkillTags() { - return skillTags; - } - - public void setSkillTags(List skillTags) { - this.skillTags.addAll(skillTags); - } - - public List getKVTags() { - return this.kvTags; - } - - public void setKVTags(List kvTags) { - this.kvTags.addAll(kvTags); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/User.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/User.java deleted file mode 100644 index cca00e52a2..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/domain/User.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.baeldung.boot.domain; - -import javax.persistence.*; - -import java.time.LocalDate; -import java.util.List; -import java.util.Objects; - -@Entity -@Table(name = "users") -public class User { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private int id; - private String name; - private LocalDate creationDate; - private LocalDate lastLoginDate; - private boolean active; - private int age; - @Column(unique = true, nullable = false) - private String email; - private Integer status; - @OneToMany - List possessionList; - - public User() { - super(); - } - - public User(String name, LocalDate creationDate,String email, Integer status) { - this.name = name; - this.creationDate = creationDate; - this.email = email; - this.status = status; - this.active = true; - } - - public int getId() { - return id; - } - - public void setId(final int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public String getEmail() { - return email; - } - - public void setEmail(final String email) { - this.email = email; - } - - public Integer getStatus() { - return status; - } - - public void setStatus(Integer status) { - this.status = status; - } - - public int getAge() { - return age; - } - - public void setAge(final int age) { - this.age = age; - } - - public LocalDate getCreationDate() { - return creationDate; - } - - public List getPossessionList() { - return possessionList; - } - - public void setPossessionList(List possessionList) { - this.possessionList = possessionList; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("User [name=").append(name).append(", id=").append(id).append("]"); - return builder.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - User user = (User) o; - return id == user.id && - age == user.age && - Objects.equals(name, user.name) && - Objects.equals(creationDate, user.creationDate) && - Objects.equals(email, user.email) && - Objects.equals(status, user.status); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, creationDate, age, email, status); - } - - public LocalDate getLastLoginDate() { - return lastLoginDate; - } - - public void setLastLoginDate(LocalDate lastLoginDate) { - this.lastLoginDate = lastLoginDate; - } - - public boolean isActive() { - return active; - } - - public void setActive(boolean active) { - this.active = active; - } - -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IBarService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IBarService.java deleted file mode 100644 index 8054cbba59..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IBarService.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.boot.services; - -import com.baeldung.boot.domain.Bar; - -public interface IBarService extends IOperations { - // -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IFooService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IFooService.java deleted file mode 100644 index 871cccdd45..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IFooService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.boot.services; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -import com.baeldung.boot.domain.Foo; - -public interface IFooService extends IOperations { - - Foo retrieveByName(String name); - - Page findPaginated(Pageable pageable); - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IOperations.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IOperations.java deleted file mode 100644 index ec2b866b6f..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/IOperations.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.boot.services; - -import org.springframework.data.domain.Page; - -import java.io.Serializable; -import java.util.List; - -public interface IOperations { - - T findOne(final long id); - - List findAll(); - - Page findPaginated(int page, int size); - - // write - - T create(final T entity); - - T update(final T entity); - - void delete(final T entity); - - void deleteById(final long entityId); - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractService.java deleted file mode 100644 index f88d018bbb..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractService.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.boot.services.impl; - -import com.baeldung.boot.services.IOperations; -import com.google.common.collect.Lists; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.repository.PagingAndSortingRepository; -import org.springframework.transaction.annotation.Transactional; - -import java.io.Serializable; -import java.util.List; - -@Transactional -public abstract class AbstractService implements IOperations { - - // read - one - - @Override - @Transactional(readOnly = true) - public T findOne(final long id) { - return getDao().findById(id).orElse(null); - } - - // read - all - - @Override - @Transactional(readOnly = true) - public List findAll() { - return Lists.newArrayList(getDao().findAll()); - } - - @Override - public Page findPaginated(final int page, final int size) { - return getDao().findAll(PageRequest.of(page, size)); - } - - // write - - @Override - public T create(final T entity) { - return getDao().save(entity); - } - - @Override - public T update(final T entity) { - return getDao().save(entity); - } - - @Override - public void delete(final T entity) { - getDao().delete(entity); - } - - @Override - public void deleteById(final long entityId) { - getDao().deleteById(entityId); - } - - protected abstract PagingAndSortingRepository getDao(); - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java deleted file mode 100644 index a73a6bd7fc..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/AbstractSpringDataJpaService.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.boot.services.impl; - -import com.baeldung.boot.services.IOperations; -import com.google.common.collect.Lists; -import org.springframework.data.repository.CrudRepository; -import org.springframework.transaction.annotation.Transactional; - -import java.io.Serializable; -import java.util.List; - -@Transactional(value = "transactionManager") -public abstract class AbstractSpringDataJpaService implements IOperations { - - @Override - public T findOne(final long id) { - return getDao().findById(id).orElse(null); - } - - @Override - public List findAll() { - return Lists.newArrayList(getDao().findAll()); - } - - @Override - public T create(final T entity) { - return getDao().save(entity); - } - - @Override - public T update(final T entity) { - return getDao().save(entity); - } - - @Override - public void delete(final T entity) { - getDao().delete(entity); - } - - @Override - public void deleteById(final long entityId) { - getDao().deleteById(entityId); - } - - protected abstract CrudRepository getDao(); -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java deleted file mode 100644 index 80568f2fd4..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/BarSpringDataJpaService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.boot.services.impl; - -import com.baeldung.boot.daos.IBarCrudRepository; -import com.baeldung.boot.domain.Bar; -import com.baeldung.boot.services.IBarService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.repository.CrudRepository; - -import java.io.Serializable; - -public class BarSpringDataJpaService extends AbstractSpringDataJpaService implements IBarService { - - @Autowired - private IBarCrudRepository dao; - - public BarSpringDataJpaService() { - super(); - } - - @Override - protected CrudRepository getDao() { - return dao; - } - - @Override - public Page findPaginated(int page, int size) { - throw new UnsupportedOperationException("Not implemented yet"); - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/FooService.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/FooService.java deleted file mode 100644 index 04eec63854..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/boot/services/impl/FooService.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.baeldung.boot.services.impl; - -import com.google.common.collect.Lists; -import com.baeldung.boot.daos.IFooDao; -import com.baeldung.boot.domain.Foo; -import com.baeldung.boot.services.IFooService; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.repository.PagingAndSortingRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@Service -@Transactional -public class FooService extends AbstractService implements IFooService { - - @Autowired - private IFooDao dao; - - public FooService() { - super(); - } - - // API - - @Override - protected PagingAndSortingRepository getDao() { - return dao; - } - - // custom methods - - @Override - public Foo retrieveByName(final String name) { - return dao.retrieveByName(name); - } - - // overridden to be secured - - @Override - @Transactional(readOnly = true) - public List findAll() { - return Lists.newArrayList(getDao().findAll()); - } - - @Override - public Page findPaginated(Pageable pageable) { - return dao.findAll(pageable); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java deleted file mode 100644 index 3b9aa2cc18..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/MultipleDbApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.multipledb; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class MultipleDbApplication { - - public static void main(String[] args) { - SpringApplication.run(MultipleDbApplication.class, args); - } - -} - diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java deleted file mode 100644 index a6f8f0829f..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductAutoConfiguration.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.baeldung.multipledb; - -import java.util.HashMap; - -import javax.sql.DataSource; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.PlatformTransactionManager; - -/** - * By default, the persistence-multiple-db.properties file is read for - * non auto configuration in PersistenceProductConfiguration. - *

- * If we need to use persistence-multiple-db-boot.properties and auto configuration - * then uncomment the below @Configuration class and comment out PersistenceProductConfiguration. - */ -//@Configuration -@PropertySource({"classpath:persistence-multiple-db-boot.properties"}) -@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.product", entityManagerFactoryRef = "productEntityManager", transactionManagerRef = "productTransactionManager") -@Profile("!tc") -public class PersistenceProductAutoConfiguration { - @Autowired - private Environment env; - - public PersistenceProductAutoConfiguration() { - super(); - } - - // - - @Bean - public LocalContainerEntityManagerFactoryBean productEntityManager() { - final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); - em.setDataSource(productDataSource()); - em.setPackagesToScan("com.baeldung.multipledb.model.product"); - - final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); - em.setJpaVendorAdapter(vendorAdapter); - final HashMap properties = new HashMap(); - properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); - em.setJpaPropertyMap(properties); - - return em; - } - - @Bean - @ConfigurationProperties(prefix="spring.second-datasource") - public DataSource productDataSource() { - return DataSourceBuilder.create().build(); - } - - @Bean - public PlatformTransactionManager productTransactionManager() { - final JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(productEntityManager().getObject()); - return transactionManager; - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java deleted file mode 100644 index bcf2cd84eb..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceProductConfiguration.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.baeldung.multipledb; - -import com.google.common.base.Preconditions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.PlatformTransactionManager; - -import javax.sql.DataSource; -import java.util.HashMap; - -@Configuration -@PropertySource({"classpath:persistence-multiple-db.properties"}) -@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.product", entityManagerFactoryRef = "productEntityManager", transactionManagerRef = "productTransactionManager") -@Profile("!tc") -public class PersistenceProductConfiguration { - @Autowired - private Environment env; - - public PersistenceProductConfiguration() { - super(); - } - - // - - @Bean - public LocalContainerEntityManagerFactoryBean productEntityManager() { - final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); - em.setDataSource(productDataSource()); - em.setPackagesToScan("com.baeldung.multipledb.model.product"); - - final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); - em.setJpaVendorAdapter(vendorAdapter); - final HashMap properties = new HashMap(); - properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); - em.setJpaPropertyMap(properties); - - return em; - } - - @Bean - public DataSource productDataSource() { - final DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); - dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("product.jdbc.url"))); - dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); - dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); - - return dataSource; - } - - @Bean - public PlatformTransactionManager productTransactionManager() { - final JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(productEntityManager().getObject()); - return transactionManager; - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java deleted file mode 100644 index e04a1621b2..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserAutoConfiguration.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.baeldung.multipledb; - -import java.util.HashMap; - -import javax.sql.DataSource; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.context.annotation.Profile; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.PlatformTransactionManager; - -/** - * By default, the persistence-multiple-db.properties file is read for - * non auto configuration in PersistenceUserConfiguration. - *

- * If we need to use persistence-multiple-db-boot.properties and auto configuration - * then uncomment the below @Configuration class and comment out PersistenceUserConfiguration. - */ -//@Configuration -@PropertySource({"classpath:persistence-multiple-db-boot.properties"}) -@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.user", entityManagerFactoryRef = "userEntityManager", transactionManagerRef = "userTransactionManager") -@Profile("!tc") -public class PersistenceUserAutoConfiguration { - @Autowired - private Environment env; - - public PersistenceUserAutoConfiguration() { - super(); - } - - // - - @Primary - @Bean - public LocalContainerEntityManagerFactoryBean userEntityManager() { - final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); - em.setDataSource(userDataSource()); - em.setPackagesToScan("com.baeldung.multipledb.model.user"); - - final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); - em.setJpaVendorAdapter(vendorAdapter); - final HashMap properties = new HashMap(); - properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); - em.setJpaPropertyMap(properties); - - return em; - } - - @Bean - @Primary - @ConfigurationProperties(prefix="spring.datasource") - public DataSource userDataSource() { - return DataSourceBuilder.create().build(); - } - - @Primary - @Bean - public PlatformTransactionManager userTransactionManager() { - final JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(userEntityManager().getObject()); - return transactionManager; - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java deleted file mode 100644 index 6b48455c0c..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/PersistenceUserConfiguration.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.baeldung.multipledb; - -import com.google.common.base.Preconditions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.*; -import org.springframework.core.env.Environment; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.PlatformTransactionManager; - -import javax.sql.DataSource; -import java.util.HashMap; - -@Configuration -@PropertySource({"classpath:persistence-multiple-db.properties"}) -@EnableJpaRepositories(basePackages = "com.baeldung.multipledb.dao.user", entityManagerFactoryRef = "userEntityManager", transactionManagerRef = "userTransactionManager") -@Profile("!tc") -public class PersistenceUserConfiguration { - @Autowired - private Environment env; - - public PersistenceUserConfiguration() { - super(); - } - - // - - @Primary - @Bean - public LocalContainerEntityManagerFactoryBean userEntityManager() { - System.out.println("loading config"); - final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); - em.setDataSource(userDataSource()); - em.setPackagesToScan("com.baeldung.multipledb.model.user"); - - final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); - em.setJpaVendorAdapter(vendorAdapter); - final HashMap properties = new HashMap(); - properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - properties.put("hibernate.dialect", env.getProperty("hibernate.dialect")); - em.setJpaPropertyMap(properties); - - return em; - } - - @Primary - @Bean - public DataSource userDataSource() { - final DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); - dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("user.jdbc.url"))); - dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); - dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); - - return dataSource; - } - - @Primary - @Bean - public PlatformTransactionManager userTransactionManager() { - final JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(userEntityManager().getObject()); - return transactionManager; - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java deleted file mode 100755 index f1256e2c72..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.multipledb.dao.product; - -import java.util.List; - -import org.springframework.data.domain.Pageable; -import org.springframework.data.repository.PagingAndSortingRepository; - -import com.baeldung.multipledb.model.product.Product; - -public interface ProductRepository extends PagingAndSortingRepository { - - - List findAllByPrice(double price, Pageable pageable); -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java deleted file mode 100644 index ae37fde20d..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/PossessionRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.multipledb.dao.user; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.baeldung.multipledb.model.user.PossessionMultipleDB; - -public interface PossessionRepository extends JpaRepository { - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java deleted file mode 100644 index 267a61a93f..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/dao/user/UserRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.multipledb.dao.user; - -import org.springframework.data.jpa.repository.JpaRepository; - -import com.baeldung.multipledb.model.user.UserMultipleDB; - -public interface UserRepository extends JpaRepository { -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/product/Product.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/product/Product.java deleted file mode 100755 index eaf471043c..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/product/Product.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung.multipledb.model.product; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(schema = "products") -public class Product { - - @Id - private int id; - - private String name; - - private double price; - - public Product() { - super(); - } - - private Product(int id, String name, double price) { - super(); - this.id = id; - this.name = name; - this.price = price; - } - - public static Product from(int id, String name, double price) { - return new Product(id, name, price); - } - - public int getId() { - return id; - } - - public void setId(final int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public double getPrice() { - return price; - } - - public void setPrice(final double price) { - this.price = price; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("Product [name=") - .append(name) - .append(", id=") - .append(id) - .append("]"); - return builder.toString(); - } -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java deleted file mode 100644 index a6a3c88bd0..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/PossessionMultipleDB.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.baeldung.multipledb.model.user; - -import javax.persistence.*; - -@Entity -@Table -public class PossessionMultipleDB { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - private String name; - - public PossessionMultipleDB() { - super(); - } - - public PossessionMultipleDB(final String name) { - super(); - - this.name = name; - } - - public long getId() { - return id; - } - - public void setId(final int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + (int) (id ^ (id >>> 32)); - result = (prime * result) + ((name == null) ? 0 : name.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final PossessionMultipleDB other = (PossessionMultipleDB) obj; - if (id != other.id) { - return false; - } - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - return true; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("Possesion [id=").append(id).append(", name=").append(name).append("]"); - return builder.toString(); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java deleted file mode 100644 index c7cd07f7a1..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/multipledb/model/user/UserMultipleDB.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.baeldung.multipledb.model.user; - -import javax.persistence.*; - -import java.util.List; - -@Entity -@Table(name = "users") -public class UserMultipleDB { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private int id; - private String name; - private int age; - @Column(unique = true, nullable = false) - private String email; - private Integer status; - - @OneToMany - List possessionList; - - public UserMultipleDB() { - super(); - } - - public UserMultipleDB(String name, String email, Integer status) { - this.name = name; - this.email = email; - this.status = status; - } - - public int getId() { - return id; - } - - public void setId(final int id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public String getEmail() { - return email; - } - - public void setEmail(final String email) { - this.email = email; - } - - public Integer getStatus() { - return status; - } - - public void setStatus(Integer status) { - this.status = status; - } - - public int getAge() { - return age; - } - - public void setAge(final int age) { - this.age = age; - } - - public List getPossessionList() { - return possessionList; - } - - public void setPossessionList(List possessionList) { - this.possessionList = possessionList; - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("User [name=").append(name).append(", id=").append(id).append("]"); - return builder.toString(); - } - -} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/resources/application.properties b/persistence-modules/spring-data-jpa/src/main/resources/application.properties deleted file mode 100644 index f127dd5e50..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -spring.main.allow-bean-definition-overriding=true - -spring.jpa.properties.hibernate.jdbc.batch_size=4 -spring.jpa.properties.hibernate.order_inserts=true -spring.jpa.properties.hibernate.order_updates=true -spring.jpa.properties.hibernate.generate_statistics=true diff --git a/persistence-modules/spring-data-jpa/src/main/resources/ddd.properties b/persistence-modules/spring-data-jpa/src/main/resources/ddd.properties deleted file mode 100644 index e5126b694b..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/resources/ddd.properties +++ /dev/null @@ -1 +0,0 @@ -spring.datasource.initialization-mode=never \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/resources/import_entities.sql b/persistence-modules/spring-data-jpa/src/main/resources/import_entities.sql deleted file mode 100644 index deb9d07f05..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/resources/import_entities.sql +++ /dev/null @@ -1,21 +0,0 @@ -insert into Article(id, publication_date, publication_time, creation_date_time) values(1, TO_DATE('01/01/2018', 'DD/MM/YYYY'), TO_DATE('15:00', 'HH24:MI'), TO_DATE('31/12/2017 07:30', 'DD/MM/YYYY HH24:MI')); -insert into Article(id, publication_date, publication_time, creation_date_time) values(2, TO_DATE('01/01/2018', 'DD/MM/YYYY'), TO_DATE('15:30', 'HH24:MI'), TO_DATE('15/12/2017 08:00', 'DD/MM/YYYY HH24:MI')); -insert into Article(id, publication_date, publication_time, creation_date_time) values(3, TO_DATE('15/12/2017', 'DD/MM/YYYY'), TO_DATE('16:00', 'HH24:MI'), TO_DATE('01/12/2017 13:45', 'DD/MM/YYYY HH24:MI')); - -insert into location (id, country, city) values (1, 'Country X', 'City One'); -insert into location (id, country, city) values (2, 'Country X', 'City Two'); -insert into location (id, country, city) values (3, 'Country X', 'City Three'); - -insert into store (id, name, location_id, items_sold, active) values (1, 'Store One', 3, 130000, true); -insert into store (id, name, location_id, items_sold, active) values (2, 'Store Two', 1, 170000, false); - -insert into item_type (id, name) values (1, 'Food'); -insert into item_type (id, name) values (2, 'Furniture'); -insert into item_type (id, name) values (3, 'Electronics'); - -insert into item (id, name, store_id, item_type_id, price, grade, color) values (1, 'Food Item One', 1, 1, 100, 'A', 'Color x'); -insert into item (id, name, store_id, item_type_id, price, grade, color) values (2, 'Furniture Item One', 1, 2, 2500, 'B', 'Color y'); -insert into item (id, name, store_id, item_type_id, price, grade, color) values (3, 'Food Item Two', 1, 1, 35, 'A', 'Color z'); -insert into item (id, name, store_id, item_type_id, price, grade, color) values (5, 'Furniture Item Two', 2, 2, 1600, 'A', 'Color w'); -insert into item (id, name, store_id, item_type_id, price, grade, color) values (6, 'Food Item Three', 2, 1, 5, 'B', 'Color a'); -insert into item (id, name, store_id, item_type_id, price, grade, color) values (7, 'Electronics Item One', 2, 3, 999, 'B', 'Color b'); diff --git a/persistence-modules/spring-data-jpa/src/main/resources/logback.xml b/persistence-modules/spring-data-jpa/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db-boot.properties b/persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db-boot.properties deleted file mode 100644 index ffca79b3f5..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db-boot.properties +++ /dev/null @@ -1,11 +0,0 @@ -hibernate.hbm2ddl.auto=create-drop -hibernate.cache.use_second_level_cache=false -hibernate.cache.use_query_cache=false - -spring.datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS -spring.datasource.username=sa -spring.datasource.password=sa - -spring.second-datasource.jdbcUrl=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS -spring.second-datasource.username=sa -spring.second-datasource.password=sa diff --git a/persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db.properties b/persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db.properties deleted file mode 100644 index 75534e8a54..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/resources/persistence-multiple-db.properties +++ /dev/null @@ -1,13 +0,0 @@ -# jdbc.X -jdbc.driverClassName=org.h2.Driver -user.jdbc.url=jdbc:h2:mem:spring_jpa_user;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS -product.jdbc.url=jdbc:h2:mem:spring_jpa_product;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS PRODUCTS -jdbc.user=sa -jdbc.pass=sa - -# hibernate.X -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=false -hibernate.hbm2ddl.auto=create-drop -hibernate.cache.use_second_level_cache=false -hibernate.cache.use_query_cache=false \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa/src/main/resources/persistence.properties b/persistence-modules/spring-data-jpa/src/main/resources/persistence.properties deleted file mode 100644 index 6bc83edf34..0000000000 --- a/persistence-modules/spring-data-jpa/src/main/resources/persistence.properties +++ /dev/null @@ -1,14 +0,0 @@ -# jdbc.X -jdbc.driverClassName=org.h2.Driver -jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS USERS -jdbc.user=sa -jdbc.pass=sa - -# hibernate.X -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop -hibernate.cache.use_second_level_cache=true -hibernate.cache.use_query_cache=true -hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory - diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/SpringContextTest.java deleted file mode 100644 index eaccf4acba..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/SpringContextTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.Application; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -public class SpringContextTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java deleted file mode 100644 index f3697bf39f..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/SpringJpaContextIntegrationTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.Application; -import com.baeldung.boot.config.PersistenceConfiguration; -import com.baeldung.multipledb.PersistenceProductConfiguration; -import com.baeldung.multipledb.PersistenceUserConfiguration; - -@RunWith(SpringRunner.class) -@DataJpaTest(excludeAutoConfiguration = { - PersistenceConfiguration.class, - PersistenceUserConfiguration.class, - PersistenceProductConfiguration.class }) -@ContextConfiguration(classes = Application.class) -public class SpringJpaContextIntegrationTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java deleted file mode 100644 index 20fc3cbeaf..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ArticleRepositoryIntegrationTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung.boot.daos; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.List; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.domain.Article; - -@RunWith(SpringRunner.class) -@DataJpaTest(properties="spring.datasource.data=classpath:import_entities.sql") -public class ArticleRepositoryIntegrationTest { - - @Autowired - private ArticleRepository repository; - - @Test - public void givenImportedArticlesWhenFindAllByPublicationDateThenArticles1And2Returned() - throws Exception { - List

result = repository.findAllByPublicationDate( - new SimpleDateFormat("yyyy-MM-dd").parse("2018-01-01") - ); - - assertEquals(2, result.size()); - assertTrue(result.stream() - .map(Article::getId) - .allMatch(id -> Arrays.asList(1, 2).contains(id)) - ); - } - - @Test - public void givenImportedArticlesWhenFindAllByPublicationTimeBetweenThenArticles2And3Returned() - throws Exception { - List
result = repository.findAllByPublicationTimeBetween( - new SimpleDateFormat("HH:mm").parse("15:15"), - new SimpleDateFormat("HH:mm").parse("16:30") - ); - - assertEquals(2, result.size()); - assertTrue(result.stream() - .map(Article::getId) - .allMatch(id -> Arrays.asList(2, 3).contains(id)) - ); - } - - @Test - public void givenImportedArticlesWhenFindAllWithCreationDateTimeBeforeThenArticles2And3Returned() throws Exception { - List
result = repository.findAllWithCreationDateTimeBefore( - new SimpleDateFormat("yyyy-MM-dd HH:mm").parse("2017-12-15 10:00") - ); - - assertEquals(2, result.size()); - assertTrue(result.stream() - .map(Article::getId) - .allMatch(id -> Arrays.asList(2, 3).contains(id)) - ); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java deleted file mode 100644 index 71f92c94ab..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/ExtendedStudentRepositoryIntegrationTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.boot.daos; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.List; - -import javax.annotation.Resource; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.Application; -import com.baeldung.boot.domain.Student; - -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = {Application.class}) -@DirtiesContext -public class ExtendedStudentRepositoryIntegrationTest { - @Resource - private ExtendedStudentRepository extendedStudentRepository; - - @Before - public void setup() { - Student student = new Student(1, "john"); - extendedStudentRepository.save(student); - Student student2 = new Student(2, "johnson"); - extendedStudentRepository.save(student2); - Student student3 = new Student(3, "tom"); - extendedStudentRepository.save(student3); - } - - @Test - public void givenStudents_whenFindByName_thenGetOk() { - List students = extendedStudentRepository.findByAttributeContainsText("name", "john"); - assertThat(students.size()).isEqualTo(2); - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java deleted file mode 100644 index 5d73e261a4..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/InventoryRepositoryIntegrationTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.boot.daos; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - -import java.math.BigDecimal; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.Application; -import com.baeldung.boot.domain.MerchandiseEntity; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes=Application.class) -public class InventoryRepositoryIntegrationTest { - - private static final String ORIGINAL_TITLE = "Pair of Pants"; - private static final String UPDATED_TITLE = "Branded Luxury Pants"; - private static final String UPDATED_BRAND = "Armani"; - private static final String ORIGINAL_SHORTS_TITLE = "Pair of Shorts"; - - @Autowired - private InventoryRepository repository; - - @Test - public void shouldCreateNewEntryInDB() { - MerchandiseEntity pants = new MerchandiseEntity(ORIGINAL_TITLE, BigDecimal.ONE); - pants = repository.save(pants); - - MerchandiseEntity shorts = new MerchandiseEntity(ORIGINAL_SHORTS_TITLE, new BigDecimal(3)); - shorts = repository.save(shorts); - - assertNotNull(pants.getId()); - assertNotNull(shorts.getId()); - assertNotEquals(pants.getId(), shorts.getId()); - } - - @Test - public void shouldUpdateExistingEntryInDB() { - MerchandiseEntity pants = new MerchandiseEntity(ORIGINAL_TITLE, BigDecimal.ONE); - pants = repository.save(pants); - - Long originalId = pants.getId(); - - pants.setTitle(UPDATED_TITLE); - pants.setPrice(BigDecimal.TEN); - pants.setBrand(UPDATED_BRAND); - - MerchandiseEntity result = repository.save(pants); - - assertEquals(originalId, result.getId()); - assertEquals(UPDATED_TITLE, result.getTitle()); - assertEquals(BigDecimal.TEN, result.getPrice()); - assertEquals(UPDATED_BRAND, result.getBrand()); - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java deleted file mode 100644 index 9e4b78dce3..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/JpaRepositoriesIntegrationTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.baeldung.boot.daos; - -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertNotNull; -import static junit.framework.TestCase.assertNull; -import static junit.framework.TestCase.assertTrue; - -import java.util.List; -import java.util.Optional; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.domain.Item; -import com.baeldung.boot.domain.ItemType; -import com.baeldung.boot.domain.Location; -import com.baeldung.boot.domain.Store; - -@RunWith(SpringRunner.class) -@DataJpaTest(properties="spring.datasource.data=classpath:import_entities.sql") -public class JpaRepositoriesIntegrationTest { - @Autowired - private LocationRepository locationRepository; - @Autowired - private StoreRepository storeRepository; - @Autowired - private ItemTypeRepository compositeRepository; - @Autowired - private ReadOnlyLocationRepository readOnlyRepository; - - @Test - public void whenSaveLocation_ThenGetSameLocation() { - Location location = new Location(); - location.setId(100L); - location.setCountry("Country H"); - location.setCity("City Hundred"); - location = locationRepository.saveAndFlush(location); - - Location otherLocation = locationRepository.getOne(location.getId()); - assertEquals("Country H", otherLocation.getCountry()); - assertEquals("City Hundred", otherLocation.getCity()); - - locationRepository.delete(otherLocation); - } - - @Test - public void givenLocationId_whenFindStores_thenGetStores() { - List stores = storeRepository.findStoreByLocationId(1L); - assertEquals(1, stores.size()); - } - - @Test - public void givenItemTypeId_whenDeleted_ThenItemTypeDeleted() { - Optional itemType = compositeRepository.findById(1L); - assertTrue(itemType.isPresent()); - compositeRepository.deleteCustom(itemType.get()); - itemType = compositeRepository.findById(1L); - assertFalse(itemType.isPresent()); - } - - @Test - public void givenItemId_whenUsingCustomRepo_ThenDeleteAppropriateEntity() { - Item item = compositeRepository.findItemById(1L); - assertNotNull(item); - compositeRepository.deleteCustom(item); - item = compositeRepository.findItemById(1L); - assertNull(item); - } - - @Test - public void givenItemAndItemType_WhenAmbiguousDeleteCalled_ThenItemTypeDeletedAndNotItem() { - Optional itemType = compositeRepository.findById(1L); - assertTrue(itemType.isPresent()); - Item item = compositeRepository.findItemById(2L); - assertNotNull(item); - - compositeRepository.findThenDelete(1L); - Optional sameItemType = compositeRepository.findById(1L); - assertFalse(sameItemType.isPresent()); - Item sameItem = compositeRepository.findItemById(2L); - assertNotNull(sameItem); - } - - @Test - public void whenCreatingReadOnlyRepo_thenHaveOnlyReadOnlyOperationsAvailable() { - Optional location = readOnlyRepository.findById(1L); - assertNotNull(location); - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java deleted file mode 100644 index b2581b8034..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryCommon.java +++ /dev/null @@ -1,545 +0,0 @@ -package com.baeldung.boot.daos; - -import org.junit.After; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.data.jpa.domain.JpaSort; -import org.springframework.data.mapping.PropertyReferenceException; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.boot.daos.user.UserRepository; -import com.baeldung.boot.domain.User; - -import javax.persistence.EntityManager; -import javax.persistence.Query; -import java.time.LocalDate; -import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; - -public class UserRepositoryCommon { - - final String USER_EMAIL = "email@example.com"; - final String USER_EMAIL2 = "email2@example.com"; - final String USER_EMAIL3 = "email3@example.com"; - final String USER_EMAIL4 = "email4@example.com"; - final Integer INACTIVE_STATUS = 0; - final Integer ACTIVE_STATUS = 1; - final String USER_EMAIL5 = "email5@example.com"; - final String USER_EMAIL6 = "email6@example.com"; - final String USER_NAME_ADAM = "Adam"; - final String USER_NAME_PETER = "Peter"; - - @Autowired - protected UserRepository userRepository; - @Autowired - private EntityManager entityManager; - - @Test - @Transactional - public void givenUsersWithSameNameInDB_WhenFindAllByName_ThenReturnStreamOfUsers() { - User user1 = new User(); - user1.setName(USER_NAME_ADAM); - user1.setEmail(USER_EMAIL); - userRepository.save(user1); - - User user2 = new User(); - user2.setName(USER_NAME_ADAM); - user2.setEmail(USER_EMAIL2); - userRepository.save(user2); - - User user3 = new User(); - user3.setName(USER_NAME_ADAM); - user3.setEmail(USER_EMAIL3); - userRepository.save(user3); - - User user4 = new User(); - user4.setName("SAMPLE"); - user4.setEmail(USER_EMAIL4); - userRepository.save(user4); - - try (Stream foundUsersStream = userRepository.findAllByName(USER_NAME_ADAM)) { - assertThat(foundUsersStream.count()).isEqualTo(3l); - } - } - - @Test - public void givenUsersInDB_WhenFindAllWithQueryAnnotation_ThenReturnCollectionWithActiveUsers() { - User user1 = new User(); - user1.setName(USER_NAME_ADAM); - user1.setEmail(USER_EMAIL); - user1.setStatus(ACTIVE_STATUS); - userRepository.save(user1); - - User user2 = new User(); - user2.setName(USER_NAME_ADAM); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User user3 = new User(); - user3.setName(USER_NAME_ADAM); - user3.setEmail(USER_EMAIL3); - user3.setStatus(INACTIVE_STATUS); - userRepository.save(user3); - - Collection allActiveUsers = userRepository.findAllActiveUsers(); - - assertThat(allActiveUsers.size()).isEqualTo(2); - } - - @Test - public void givenUsersInDB_WhenFindAllWithQueryAnnotationNative_ThenReturnCollectionWithActiveUsers() { - User user1 = new User(); - user1.setName(USER_NAME_ADAM); - user1.setEmail(USER_EMAIL); - user1.setStatus(ACTIVE_STATUS); - userRepository.save(user1); - - User user2 = new User(); - user2.setName(USER_NAME_ADAM); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User user3 = new User(); - user3.setName(USER_NAME_ADAM); - user3.setEmail(USER_EMAIL3); - user3.setStatus(INACTIVE_STATUS); - userRepository.save(user3); - - Collection allActiveUsers = userRepository.findAllActiveUsersNative(); - - assertThat(allActiveUsers.size()).isEqualTo(2); - } - - @Test - public void givenUserInDB_WhenFindUserByStatusWithQueryAnnotation_ThenReturnActiveUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByStatus(ACTIVE_STATUS); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUserInDB_WhenFindUserByStatusWithQueryAnnotationNative_ThenReturnActiveUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByStatusNative(ACTIVE_STATUS); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationIndexedParams_ThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByStatusAndName(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationNamedParams_ThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByStatusAndNameNamedParams(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationNativeNamedParams_ThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByStatusAndNameNamedParamsNative(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByStatusAndNameWithQueryAnnotationNamedParamsCustomNames_ThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setEmail(USER_EMAIL2); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByUserStatusAndUserName(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByNameLikeWithQueryAnnotationIndexedParams_ThenReturnUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByNameLike("Ad"); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByNameLikeWithQueryAnnotationNamedParams_ThenReturnUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByNameLikeNamedParam("Ad"); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindUserByNameLikeWithQueryAnnotationNative_ThenReturnUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setEmail(USER_EMAIL); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByNameLikeNative("Ad"); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindAllWithSortByName_ThenReturnUsersSorted() { - userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); - - List usersSortByName = userRepository.findAll(Sort.by(Sort.Direction.ASC, "name")); - - assertThat(usersSortByName.get(0) - .getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test(expected = PropertyReferenceException.class) - public void givenUsersInDB_WhenFindAllSortWithFunction_ThenThrowException() { - userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); - - userRepository.findAll(Sort.by(Sort.Direction.ASC, "name")); - - List usersSortByNameLength = userRepository.findAll(Sort.by("LENGTH(name)")); - - assertThat(usersSortByNameLength.get(0) - .getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindAllSortWithFunctionQueryAnnotationJPQL_ThenReturnUsersSorted() { - userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); - - userRepository.findAllUsers(Sort.by("name")); - - List usersSortByNameLength = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)")); - - assertThat(usersSortByNameLength.get(0) - .getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDB_WhenFindAllWithPageRequestQueryAnnotationJPQL_ThenReturnPageOfUsers() { - userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL4, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE2", LocalDate.now(), USER_EMAIL5, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL6, INACTIVE_STATUS)); - - Page usersPage = userRepository.findAllUsersWithPagination(PageRequest.of(1, 3)); - - assertThat(usersPage.getContent() - .get(0) - .getName()).isEqualTo("SAMPLE1"); - } - - @Test - public void givenUsersInDB_WhenFindAllWithPageRequestQueryAnnotationNative_ThenReturnPageOfUsers() { - userRepository.save(new User(USER_NAME_ADAM, LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL4, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE2", LocalDate.now(), USER_EMAIL5, INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL6, INACTIVE_STATUS)); - - Page usersSortByNameLength = userRepository.findAllUsersWithPaginationNative(PageRequest.of(1, 3)); - - assertThat(usersSortByNameLength.getContent() - .get(0) - .getName()).isEqualTo(USER_NAME_PETER); - } - - @Test - @Transactional - public void givenUsersInDB_WhenUpdateStatusForNameModifyingQueryAnnotationJPQL_ThenModifyMatchingUsers() { - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); - - int updatedUsersSize = userRepository.updateUserSetStatusForName(INACTIVE_STATUS, "SAMPLE"); - - assertThat(updatedUsersSize).isEqualTo(2); - } - - @Test - public void givenUsersInDB_WhenFindByEmailsWithDynamicQuery_ThenReturnCollection() { - - User user1 = new User(); - user1.setEmail(USER_EMAIL); - userRepository.save(user1); - - User user2 = new User(); - user2.setEmail(USER_EMAIL2); - userRepository.save(user2); - - User user3 = new User(); - user3.setEmail(USER_EMAIL3); - userRepository.save(user3); - - Set emails = new HashSet<>(); - emails.add(USER_EMAIL2); - emails.add(USER_EMAIL3); - - Collection usersWithEmails = userRepository.findUserByEmails(emails); - - assertThat(usersWithEmails.size()).isEqualTo(2); - } - - @Test - public void givenUsersInDBWhenFindByNameListReturnCollection() { - - User user1 = new User(); - user1.setName(USER_NAME_ADAM); - user1.setEmail(USER_EMAIL); - userRepository.save(user1); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setEmail(USER_EMAIL2); - userRepository.save(user2); - - List names = Arrays.asList(USER_NAME_ADAM, USER_NAME_PETER); - - List usersWithNames = userRepository.findUserByNameList(names); - - assertThat(usersWithNames.size()).isEqualTo(2); - } - - - @Test - @Transactional - public void whenInsertedWithQuery_ThenUserIsPersisted() { - userRepository.insertUser(USER_NAME_ADAM, 1, USER_EMAIL, ACTIVE_STATUS, true); - userRepository.insertUser(USER_NAME_PETER, 1, USER_EMAIL2, ACTIVE_STATUS, true); - - User userAdam = userRepository.findUserByNameLike(USER_NAME_ADAM); - User userPeter = userRepository.findUserByNameLike(USER_NAME_PETER); - - assertThat(userAdam).isNotNull(); - assertThat(userAdam.getEmail()).isEqualTo(USER_EMAIL); - assertThat(userPeter).isNotNull(); - assertThat(userPeter.getEmail()).isEqualTo(USER_EMAIL2); - } - - - @Test - @Transactional - public void givenTwoUsers_whenFindByNameUsr01_ThenUserUsr01() { - User usr01 = new User("usr01", LocalDate.now(), "usr01@baeldung.com", 1); - User usr02 = new User("usr02", LocalDate.now(), "usr02@baeldung.com", 1); - - userRepository.save(usr01); - userRepository.save(usr02); - - try (Stream users = userRepository.findAllByName("usr01")) { - assertTrue(users.allMatch(usr -> usr.equals(usr01))); - } - } - - @Test - @Transactional - public void givenTwoUsers_whenFindByNameUsr00_ThenNoUsers() { - User usr01 = new User("usr01", LocalDate.now(), "usr01@baeldung.com", 1); - User usr02 = new User("usr02", LocalDate.now(), "usr02@baeldung.com", 1); - - userRepository.save(usr01); - userRepository.save(usr02); - - try (Stream users = userRepository.findAllByName("usr00")) { - assertEquals(0, users.count()); - } - } - - @Test - public void givenTwoUsers_whenFindUsersWithGmailAddress_ThenUserUsr02() { - User usr01 = new User("usr01", LocalDate.now(), "usr01@baeldung.com", 1); - User usr02 = new User("usr02", LocalDate.now(), "usr02@gmail.com", 1); - - userRepository.save(usr01); - userRepository.save(usr02); - - List users = userRepository.findUsersWithGmailAddress(); - assertEquals(1, users.size()); - assertEquals(usr02, users.get(0)); - } - - @Test - @Transactional - public void givenTwoUsers_whenDeleteAllByCreationDateAfter_ThenOneUserRemains() { - User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); - User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.com", 1); - - userRepository.save(usr01); - userRepository.save(usr02); - - userRepository.deleteAllByCreationDateAfter(LocalDate.of(2018, 5, 1)); - - List users = userRepository.findAll(); - - assertEquals(1, users.size()); - assertEquals(usr01, users.get(0)); - } - - @Test - public void givenTwoUsers_whenFindAllUsersByPredicates_ThenUserUsr01() { - User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); - User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.org", 1); - - userRepository.save(usr01); - userRepository.save(usr02); - - List> predicates = new ArrayList<>(); - predicates.add(usr -> usr.getCreationDate().isAfter(LocalDate.of(2017, 12, 31))); - predicates.add(usr -> usr.getEmail().endsWith(".com")); - - List users = userRepository.findAllUsersByPredicates(predicates); - - assertEquals(1, users.size()); - assertEquals(usr01, users.get(0)); - } - - @Test - @Transactional - public void givenTwoUsers_whenDeactivateUsersNotLoggedInSince_ThenUserUsr02Deactivated() { - User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); - usr01.setLastLoginDate(LocalDate.now()); - User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.org", 1); - usr02.setLastLoginDate(LocalDate.of(2018, 7, 20)); - - userRepository.save(usr01); - userRepository.save(usr02); - - userRepository.deactivateUsersNotLoggedInSince(LocalDate.of(2018, 8, 1)); - - List users = userRepository.findAllUsers(Sort.by(Sort.Order.asc("name"))); - assertTrue(users.get(0).isActive()); - assertFalse(users.get(1).isActive()); - } - - @Test - @Transactional - public void givenTwoUsers_whenDeleteDeactivatedUsers_ThenUserUsr02Deleted() { - User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); - usr01.setLastLoginDate(LocalDate.now()); - User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.com", 0); - usr02.setLastLoginDate(LocalDate.of(2018, 7, 20)); - usr02.setActive(false); - - userRepository.save(usr01); - userRepository.save(usr02); - - int deletedUsersCount = userRepository.deleteDeactivatedUsers(); - - List users = userRepository.findAll(); - assertEquals(1, users.size()); - assertEquals(usr01, users.get(0)); - assertEquals(1, deletedUsersCount); - } - - @Test - @Transactional - public void givenTwoUsers_whenAddDeletedColumn_ThenUsersHaveDeletedColumn() { - User usr01 = new User("usr01", LocalDate.of(2018, 1, 1), "usr01@baeldung.com", 1); - usr01.setLastLoginDate(LocalDate.now()); - User usr02 = new User("usr02", LocalDate.of(2018, 6, 1), "usr02@baeldung.org", 1); - usr02.setLastLoginDate(LocalDate.of(2018, 7, 20)); - usr02.setActive(false); - - userRepository.save(usr01); - userRepository.save(usr02); - - userRepository.addDeletedColumn(); - - Query nativeQuery = entityManager.createNativeQuery("select deleted from USERS where NAME = 'usr01'"); - assertEquals(0, nativeQuery.getResultList().get(0)); - } - - @After - public void cleanUp() { - userRepository.deleteAll(); - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java deleted file mode 100644 index 1b1d264574..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryIntegrationTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.boot.daos; - -import com.baeldung.boot.Application; -import com.baeldung.boot.domain.User; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDate; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Created by adam. - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -@DirtiesContext -public class UserRepositoryIntegrationTest extends UserRepositoryCommon { - - @Test - @Transactional - public void givenUsersInDBWhenUpdateStatusForNameModifyingQueryAnnotationNativeThenModifyMatchingUsers() { - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); - userRepository.flush(); - - int updatedUsersSize = userRepository.updateUserSetStatusForNameNative(INACTIVE_STATUS, "SAMPLE"); - - assertThat(updatedUsersSize).isEqualTo(2); - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java deleted file mode 100644 index 99eabc8271..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCAutoLiveTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.boot.daos; - -import com.baeldung.boot.Application; -import com.baeldung.boot.domain.User; -import com.baeldung.util.BaeldungPostgresqlContainer; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; -import org.testcontainers.containers.PostgreSQLContainer; - -import java.time.LocalDate; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Created by adam. - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -@ActiveProfiles({"tc", "tc-auto"}) -public class UserRepositoryTCAutoLiveTest extends UserRepositoryCommon { - - @ClassRule - public static PostgreSQLContainer postgreSQLContainer = BaeldungPostgresqlContainer.getInstance(); - - @Test - @Transactional - public void givenUsersInDB_WhenUpdateStatusForNameModifyingQueryAnnotationNativePostgres_ThenModifyMatchingUsers() { - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); - userRepository.flush(); - - int updatedUsersSize = userRepository.updateUserSetStatusForNameNativePostgres(INACTIVE_STATUS, "SAMPLE"); - - assertThat(updatedUsersSize).isEqualTo(2); - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java deleted file mode 100644 index be8843c166..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/daos/UserRepositoryTCLiveTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.boot.daos; - -import com.baeldung.boot.Application; -import com.baeldung.boot.domain.User; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.util.TestPropertyValues; -import org.springframework.context.ApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; -import org.testcontainers.containers.PostgreSQLContainer; - -import java.time.LocalDate; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = Application.class) -@ActiveProfiles("tc") -@ContextConfiguration(initializers = {UserRepositoryTCLiveTest.Initializer.class}) -public class UserRepositoryTCLiveTest extends UserRepositoryCommon { - - @ClassRule - public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:11.1") - .withDatabaseName("integration-tests-db") - .withUsername("sa") - .withPassword("sa"); - - @Test - @Transactional - public void givenUsersInDB_WhenUpdateStatusForNameModifyingQueryAnnotationNative_ThenModifyMatchingUsers() { - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL4, ACTIVE_STATUS)); - userRepository.flush(); - - int updatedUsersSize = userRepository.updateUserSetStatusForNameNativePostgres(INACTIVE_STATUS, "SAMPLE"); - - assertThat(updatedUsersSize).isEqualTo(2); - } - - static class Initializer - implements ApplicationContextInitializer { - public void initialize(ConfigurableApplicationContext configurableApplicationContext) { - TestPropertyValues.of( - "spring.datasource.url=" + postgreSQLContainer.getJdbcUrl(), - "spring.datasource.username=" + postgreSQLContainer.getUsername(), - "spring.datasource.password=" + postgreSQLContainer.getPassword() - ).applyTo(configurableApplicationContext.getEnvironment()); - } - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java deleted file mode 100644 index e76b932cb9..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate2EventsIntegrationTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; - -import com.baeldung.boot.ddd.event.Aggregate2; -import com.baeldung.boot.ddd.event.Aggregate2Repository; -import com.baeldung.boot.ddd.event.DomainEvent; - -@SpringJUnitConfig -@SpringBootTest -class Aggregate2EventsIntegrationTest { - @MockBean - private TestEventHandler eventHandler; - @Autowired - private Aggregate2Repository repository; - - // @formatter:off - @DisplayName("given aggregate with @AfterDomainEventPublication," - + " when do domain operation and save twice," - + " then an event is published only for the first time") - // @formatter:on - @Test - void afterDomainEvents() { - // given - Aggregate2 aggregate = new Aggregate2(); - - // when - aggregate.domainOperation(); - repository.save(aggregate); - repository.save(aggregate); - - // then - verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class)); - } - - @BeforeEach - void beforeEach() { - repository.deleteAll(); - } - - // @formatter:off - @DisplayName("given aggregate with @DomainEvents," - + " when do domain operation and save," - + " then an event is published") - // @formatter:on - @Test - void domainEvents() { - // given - Aggregate2 aggregate = new Aggregate2(); - - // when - aggregate.domainOperation(); - repository.save(aggregate); - - // then - verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class)); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java deleted file mode 100644 index 4193e932ee..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/Aggregate3EventsIntegrationTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; - -import com.baeldung.boot.ddd.event.Aggregate3; -import com.baeldung.boot.ddd.event.Aggregate3Repository; -import com.baeldung.boot.ddd.event.DomainEvent; - -@SpringJUnitConfig -@SpringBootTest -class Aggregate3EventsIntegrationTest { - - @MockBean - private TestEventHandler eventHandler; - @Autowired - private Aggregate3Repository repository; - - // @formatter:off - @DisplayName("given aggregate extending AbstractAggregateRoot," - + " when do domain operation and save twice," - + " then an event is published only for the first time") - // @formatter:on - @Test - void afterDomainEvents() { - // given - Aggregate3 aggregate = new Aggregate3(); - - // when - aggregate.domainOperation(); - repository.save(aggregate); - repository.save(aggregate); - - // then - verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class)); - } - - // @formatter:off - @DisplayName("given aggregate extending AbstractAggregateRoot," - + " when do domain operation and save," - + " then an event is published") - // @formatter:on - @Test - void domainEvents() { - // given - Aggregate3 aggregate = new Aggregate3(); - - // when - aggregate.domainOperation(); - repository.save(aggregate); - - // then - verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class)); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java deleted file mode 100644 index ac607063b2..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/AggregateEventsIntegrationTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.baeldung.boot.ddd.event; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.context.annotation.Bean; -import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; - -import com.baeldung.boot.ddd.event.Aggregate; -import com.baeldung.boot.ddd.event.AggregateRepository; -import com.baeldung.boot.ddd.event.DomainEvent; -import com.baeldung.boot.ddd.event.DomainService; - -@SpringJUnitConfig -@SpringBootTest -class AggregateEventsIntegrationTest { - - @Autowired - private DomainService domainService; - - @MockBean - private TestEventHandler eventHandler; - @Autowired - private ApplicationEventPublisher eventPublisher; - @Autowired - private AggregateRepository repository; - - // @formatter:off - @DisplayName("given existing aggregate," - + " when do domain operation directly on aggregate," - + " then domain event is NOT published") - // @formatter:on - @Test - void aggregateEventsTest() { - Aggregate existingDomainEntity = new Aggregate(0, eventPublisher); - repository.save(existingDomainEntity); - - // when - repository.findById(existingDomainEntity.getId()) - .get() - .domainOperation(); - - // then - verifyZeroInteractions(eventHandler); - } - - @BeforeEach - void beforeEach() { - repository.deleteAll(); - } - - // @formatter:off - @DisplayName("given existing aggregate," - + " when do domain operation on service," - + " then domain event is published") - // @formatter:on - @Test - void serviceEventsTest() { - Aggregate existingDomainEntity = new Aggregate(1, eventPublisher); - repository.save(existingDomainEntity); - - // when - domainService.serviceDomainOperation(existingDomainEntity.getId()); - - // then - verify(eventHandler, times(1)).handleEvent(any(DomainEvent.class)); - } - - @TestConfiguration - public static class TestConfig { - @Bean - public DomainService domainService(AggregateRepository repository, ApplicationEventPublisher eventPublisher) { - return new DomainService(repository, eventPublisher); - } - } - -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java deleted file mode 100644 index 0f499834eb..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/ddd/event/TestEventHandler.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * - */ -package com.baeldung.boot.ddd.event; - -import org.springframework.transaction.event.TransactionalEventListener; - -import com.baeldung.boot.ddd.event.DomainEvent; - -interface TestEventHandler { - @TransactionalEventListener - void handleEvent(DomainEvent event); - -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java deleted file mode 100644 index bf0c85fca6..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/AbstractServicePersistenceIntegrationTest.java +++ /dev/null @@ -1,252 +0,0 @@ -package com.baeldung.boot.services; - -import com.baeldung.boot.domain.Foo; -import com.baeldung.boot.services.IOperations; -import com.baeldung.util.IDUtil; -import org.hamcrest.Matchers; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.dao.DataAccessException; - -import java.io.Serializable; -import java.util.List; - -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.*; - -public abstract class AbstractServicePersistenceIntegrationTest { - - // tests - - // find - one - - @Test - /**/public final void givenResourceDoesNotExist_whenResourceIsRetrieved_thenNoResourceIsReceived() { - // When - final Foo createdResource = getApi().findOne(IDUtil.randomPositiveLong()); - - // Then - assertNull(createdResource); - } - - @Test - public void givenResourceExists_whenResourceIsRetrieved_thenNoExceptions() { - final Foo existingResource = persistNewEntity(); - getApi().findOne(existingResource.getId()); - } - - @Test - public void givenResourceDoesNotExist_whenResourceIsRetrieved_thenNoExceptions() { - getApi().findOne(IDUtil.randomPositiveLong()); - } - - @Test - public void givenResourceExists_whenResourceIsRetrieved_thenTheResultIsNotNull() { - final Foo existingResource = persistNewEntity(); - final Foo retrievedResource = getApi().findOne(existingResource.getId()); - assertNotNull(retrievedResource); - } - - @Test - public void givenResourceExists_whenResourceIsRetrieved_thenResourceIsRetrievedCorrectly() { - final Foo existingResource = persistNewEntity(); - final Foo retrievedResource = getApi().findOne(existingResource.getId()); - assertEquals(existingResource, retrievedResource); - } - - // find - one - by name - - // find - all - - @Test - /**/public void whenAllResourcesAreRetrieved_thenNoExceptions() { - getApi().findAll(); - } - - @Test - /**/public void whenAllResourcesAreRetrieved_thenTheResultIsNotNull() { - final List resources = getApi().findAll(); - - assertNotNull(resources); - } - - @Test - /**/public void givenAtLeastOneResourceExists_whenAllResourcesAreRetrieved_thenRetrievedResourcesAreNotEmpty() { - persistNewEntity(); - - // When - final List allResources = getApi().findAll(); - - // Then - assertThat(allResources, not(Matchers. empty())); - } - - @Test - /**/public void givenAnResourceExists_whenAllResourcesAreRetrieved_thenTheExistingResourceIsIndeedAmongThem() { - final Foo existingResource = persistNewEntity(); - - final List resources = getApi().findAll(); - - assertThat(resources, hasItem(existingResource)); - } - - @Test - /**/public void whenAllResourcesAreRetrieved_thenResourcesHaveIds() { - persistNewEntity(); - - // When - final List allResources = getApi().findAll(); - - // Then - for (final Foo resource : allResources) { - assertNotNull(resource.getId()); - } - } - - // create - - @Test(expected = RuntimeException.class) - /**/public void whenNullResourceIsCreated_thenException() { - getApi().create(null); - } - - @Test - /**/public void whenResourceIsCreated_thenNoExceptions() { - persistNewEntity(); - } - - @Test - /**/public void whenResourceIsCreated_thenResourceIsRetrievable() { - final Foo existingResource = persistNewEntity(); - - assertNotNull(getApi().findOne(existingResource.getId())); - } - - @Test - /**/public void whenResourceIsCreated_thenSavedResourceIsEqualToOriginalResource() { - final Foo originalResource = createNewEntity(); - final Foo savedResource = getApi().create(originalResource); - - assertEquals(originalResource, savedResource); - } - - @Test(expected = RuntimeException.class) - public void whenResourceWithFailedConstraintsIsCreated_thenException() { - final Foo invalidResource = createNewEntity(); - invalidate(invalidResource); - - getApi().create(invalidResource); - } - - /** - * -- specific to the persistence engine - */ - @Test(expected = DataAccessException.class) - @Ignore("Hibernate simply ignores the id silently and still saved (tracking this)") - public void whenResourceWithIdIsCreated_thenDataAccessException() { - final Foo resourceWithId = createNewEntity(); - resourceWithId.setId(IDUtil.randomPositiveLong()); - - getApi().create(resourceWithId); - } - - // update - - @Test(expected = RuntimeException.class) - /**/public void whenNullResourceIsUpdated_thenException() { - getApi().update(null); - } - - @Test - /**/public void givenResourceExists_whenResourceIsUpdated_thenNoExceptions() { - // Given - final Foo existingResource = persistNewEntity(); - - // When - getApi().update(existingResource); - } - - /** - * - can also be the ConstraintViolationException which now occurs on the update operation will not be translated; as a consequence, it will be a TransactionSystemException - */ - @Test(expected = RuntimeException.class) - public void whenResourceIsUpdatedWithFailedConstraints_thenException() { - final Foo existingResource = persistNewEntity(); - invalidate(existingResource); - - getApi().update(existingResource); - } - - @Test - /**/public void givenResourceExists_whenResourceIsUpdated_thenUpdatesArePersisted() { - // Given - final Foo existingResource = persistNewEntity(); - - // When - change(existingResource); - getApi().update(existingResource); - - final Foo updatedResource = getApi().findOne(existingResource.getId()); - - // Then - assertEquals(existingResource, updatedResource); - } - - // delete - - // @Test(expected = RuntimeException.class) - // public void givenResourceDoesNotExists_whenResourceIsDeleted_thenException() { - // // When - // getApi().delete(IDUtil.randomPositiveLong()); - // } - // - // @Test(expected = RuntimeException.class) - // public void whenResourceIsDeletedByNegativeId_thenException() { - // // When - // getApi().delete(IDUtil.randomNegativeLong()); - // } - // - // @Test - // public void givenResourceExists_whenResourceIsDeleted_thenNoExceptions() { - // // Given - // final Foo existingResource = persistNewEntity(); - // - // // When - // getApi().delete(existingResource.getId()); - // } - // - // @Test - // /**/public final void givenResourceExists_whenResourceIsDeleted_thenResourceNoLongerExists() { - // // Given - // final Foo existingResource = persistNewEntity(); - // - // // When - // getApi().delete(existingResource.getId()); - // - // // Then - // assertNull(getApi().findOne(existingResource.getId())); - // } - - // template method - - protected Foo createNewEntity() { - return new Foo(randomAlphabetic(6)); - } - - protected abstract IOperations getApi(); - - private final void invalidate(final Foo entity) { - entity.setName(null); - } - - private final void change(final Foo entity) { - entity.setName(randomAlphabetic(6)); - } - - protected Foo persistNewEntity() { - return getApi().create(createNewEntity()); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java deleted file mode 100644 index 72de4918a2..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/FooServicePersistenceIntegrationTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.baeldung.boot.services; - -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; -import static org.junit.Assert.assertNotNull; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.Application; -import com.baeldung.boot.domain.Foo; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes=Application.class) -public class FooServicePersistenceIntegrationTest extends AbstractServicePersistenceIntegrationTest { - - @Autowired - private IFooService service; - - // tests - - @Test - public final void whenContextIsBootstrapped_thenNoExceptions() { - // - } - - @Test - public final void whenEntityIsCreated_thenNoExceptions() { - service.create(new Foo(randomAlphabetic(6))); - } - - @Test(expected = DataIntegrityViolationException.class) - public final void whenInvalidEntityIsCreated_thenDataException() { - service.create(new Foo()); - } - - @Test(expected = DataIntegrityViolationException.class) - public final void whenEntityWithLongNameIsCreated_thenDataException() { - service.create(new Foo(randomAlphabetic(2048))); - } - - // custom Query method - - @Test - public final void givenUsingCustomQuery_whenRetrievingEntity_thenFound() { - final String name = randomAlphabetic(6); - service.create(new Foo(name)); - - final Foo retrievedByName = service.retrieveByName(name); - assertNotNull(retrievedByName); - } - - // work in progress - - @Test(expected = InvalidDataAccessApiUsageException.class) - @Ignore("Right now, persist has saveOrUpdate semantics, so this will no longer fail") - public final void whenSameEntityIsCreatedTwice_thenDataException() { - final Foo entity = new Foo(randomAlphabetic(8)); - service.create(entity); - service.create(entity); - } - - // API - - @Override - protected final IOperations getApi() { - return service; - } - -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java deleted file mode 100644 index 644d1ec805..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/boot/services/SpringDataJPABarAuditIntegrationTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.baeldung.boot.services; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.context.junit4.SpringRunner; - -import com.baeldung.boot.Application; -import com.baeldung.boot.domain.Bar; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes=Application.class) -public class SpringDataJPABarAuditIntegrationTest { - - private static Logger logger = LoggerFactory.getLogger(SpringDataJPABarAuditIntegrationTest.class); - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - logger.info("setUpBeforeClass()"); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - logger.info("tearDownAfterClass()"); - } - - @Autowired - @Qualifier("barSpringDataJpaService") - private IBarService barService; - - @Autowired - private EntityManagerFactory entityManagerFactory; - - private EntityManager em; - - @Before - public void setUp() throws Exception { - logger.info("setUp()"); - em = entityManagerFactory.createEntityManager(); - } - - @After - public void tearDown() throws Exception { - logger.info("tearDown()"); - em.close(); - } - - @Test - @WithMockUser(username = "tutorialuser") - public final void whenBarsModified_thenBarsAudited() { - Bar bar = new Bar("BAR1"); - barService.create(bar); - assertEquals(bar.getCreatedDate(), bar.getModifiedDate()); - assertEquals("tutorialuser", bar.getCreatedBy(), bar.getModifiedBy()); - bar.setName("BAR2"); - bar = barService.update(bar); - assertTrue(bar.getCreatedDate() < bar.getModifiedDate()); - assertEquals("tutorialuser", bar.getCreatedBy(), bar.getModifiedBy()); - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java deleted file mode 100644 index a1f4a3fa2c..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/JpaMultipleDBIntegrationTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.baeldung.multipledb; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.Collections; -import java.util.Optional; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.EnableTransactionManagement; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.multipledb.dao.product.ProductRepository; -import com.baeldung.multipledb.dao.user.PossessionRepository; -import com.baeldung.multipledb.dao.user.UserRepository; -import com.baeldung.multipledb.model.product.Product; -import com.baeldung.multipledb.model.user.PossessionMultipleDB; -import com.baeldung.multipledb.model.user.UserMultipleDB; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes=MultipleDbApplication.class) -@EnableTransactionManagement -public class JpaMultipleDBIntegrationTest { - - @Autowired - private UserRepository userRepository; - - @Autowired - private PossessionRepository possessionRepository; - - @Autowired - private ProductRepository productRepository; - - // tests - - @Test - @Transactional("userTransactionManager") - public void whenCreatingUser_thenCreated() { - UserMultipleDB user = new UserMultipleDB(); - user.setName("John"); - user.setEmail("john@test.com"); - user.setAge(20); - PossessionMultipleDB p = new PossessionMultipleDB("sample"); - p = possessionRepository.save(p); - user.setPossessionList(Collections.singletonList(p)); - user = userRepository.save(user); - final Optional result = userRepository.findById(user.getId()); - assertTrue(result.isPresent()); - System.out.println(result.get().getPossessionList()); - assertEquals(1, result.get().getPossessionList().size()); - } - - @Test - @Transactional("userTransactionManager") - public void whenCreatingUsersWithSameEmail_thenRollback() { - UserMultipleDB user1 = new UserMultipleDB(); - user1.setName("John"); - user1.setEmail("john@test.com"); - user1.setAge(20); - user1 = userRepository.save(user1); - assertTrue(userRepository.findById(user1.getId()).isPresent()); - - UserMultipleDB user2 = new UserMultipleDB(); - user2.setName("Tom"); - user2.setEmail("john@test.com"); - user2.setAge(10); - try { - user2 = userRepository.save(user2); - userRepository.flush(); - fail("DataIntegrityViolationException should be thrown!"); - } catch (final DataIntegrityViolationException e) { - // Expected - } catch (final Exception e) { - fail("DataIntegrityViolationException should be thrown, instead got: " + e); - } - } - - @Test - @Transactional("productTransactionManager") - public void whenCreatingProduct_thenCreated() { - Product product = new Product(); - product.setName("Book"); - product.setId(2); - product.setPrice(20); - product = productRepository.save(product); - - assertTrue(productRepository.findById(product.getId()).isPresent()); - } - -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java deleted file mode 100644 index 9bfba61a3b..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java +++ /dev/null @@ -1,144 +0,0 @@ -package com.baeldung.multipledb; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.EnableTransactionManagement; -import org.springframework.transaction.annotation.Transactional; - -import com.baeldung.multipledb.PersistenceProductConfiguration; -import com.baeldung.multipledb.dao.product.ProductRepository; -import com.baeldung.multipledb.model.product.Product; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes=MultipleDbApplication.class) -@EnableTransactionManagement -public class ProductRepositoryIntegrationTest { - - @Autowired - private ProductRepository productRepository; - - @Before - @Transactional("productTransactionManager") - public void setUp() { - productRepository.save(Product.from(1001, "Book", 21)); - productRepository.save(Product.from(1002, "Coffee", 10)); - productRepository.save(Product.from(1003, "Jeans", 30)); - productRepository.save(Product.from(1004, "Shirt", 32)); - productRepository.save(Product.from(1005, "Bacon", 10)); - } - - @Test - public void whenRequestingFirstPageOfSizeTwo_ThenReturnFirstPage() { - Pageable pageRequest = PageRequest.of(0, 2); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(2)); - assertTrue(result.stream() - .map(Product::getId) - .allMatch(id -> Arrays.asList(1001, 1002) - .contains(id))); - } - - @Test - public void whenRequestingSecondPageOfSizeTwo_ThenReturnSecondPage() { - Pageable pageRequest = PageRequest.of(1, 2); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(2)); - assertTrue(result.stream() - .map(Product::getId) - .allMatch(id -> Arrays.asList(1003, 1004) - .contains(id))); - } - - @Test - public void whenRequestingLastPage_ThenReturnLastPageWithRemData() { - Pageable pageRequest = PageRequest.of(2, 2); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(1)); - assertTrue(result.stream() - .map(Product::getId) - .allMatch(id -> Arrays.asList(1005) - .contains(id))); - } - - @Test - public void whenSortingByNameAscAndPaging_ThenReturnSortedPagedResult() { - Pageable pageRequest = PageRequest.of(0, 3, Sort.by("name")); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(3)); - assertThat(result.getContent() - .stream() - .map(Product::getId) - .collect(Collectors.toList()), equalTo(Arrays.asList(1005, 1001, 1002))); - - } - - @Test - public void whenSortingByPriceDescAndPaging_ThenReturnSortedPagedResult() { - Pageable pageRequest = PageRequest.of(0, 3, Sort.by("price") - .descending()); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(3)); - assertThat(result.getContent() - .stream() - .map(Product::getId) - .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001))); - - } - - @Test - public void whenSortingByPriceDescAndNameAscAndPaging_ThenReturnSortedPagedResult() { - Pageable pageRequest = PageRequest.of(0, 5, Sort.by("price") - .descending() - .and(Sort.by("name"))); - - Page result = productRepository.findAll(pageRequest); - - assertThat(result.getContent(), hasSize(5)); - assertThat(result.getContent() - .stream() - .map(Product::getId) - .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001, 1005, 1002))); - - } - - @Test - public void whenRequestingFirstPageOfSizeTwoUsingCustomMethod_ThenReturnFirstPage() { - Pageable pageRequest = PageRequest.of(0, 2); - - List result = productRepository.findAllByPrice(10, pageRequest); - - assertThat(result, hasSize(2)); - assertTrue(result.stream() - .map(Product::getId) - .allMatch(id -> Arrays.asList(1002, 1005) - .contains(id))); - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java deleted file mode 100644 index e5ad2dd448..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/util/BaeldungPostgresqlContainer.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.util; - -import org.testcontainers.containers.PostgreSQLContainer; - -public class BaeldungPostgresqlContainer extends PostgreSQLContainer { - - private static final String IMAGE_VERSION = "postgres:11.1"; - - private static BaeldungPostgresqlContainer container; - - - private BaeldungPostgresqlContainer() { - super(IMAGE_VERSION); - } - - public static BaeldungPostgresqlContainer getInstance() { - if (container == null) { - container = new BaeldungPostgresqlContainer(); - } - return container; - } - - @Override - public void start() { - super.start(); - System.setProperty("DB_URL", container.getJdbcUrl()); - System.setProperty("DB_USERNAME", container.getUsername()); - System.setProperty("DB_PASSWORD", container.getPassword()); - } - - @Override - public void stop() { - //do nothing, JVM handles shut down - } -} diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/util/IDUtil.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/util/IDUtil.java deleted file mode 100644 index 45e72e046d..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/util/IDUtil.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.util; - -import java.util.Random; - -public final class IDUtil { - - private IDUtil() { - throw new AssertionError(); - } - - // API - - public static String randomPositiveLongAsString() { - return Long.toString(randomPositiveLong()); - } - - public static String randomNegativeLongAsString() { - return Long.toString(randomNegativeLong()); - } - - public static long randomPositiveLong() { - long id = new Random().nextLong() * 10000; - id = (id < 0) ? (-1 * id) : id; - return id; - } - - private static long randomNegativeLong() { - long id = new Random().nextLong() * 10000; - id = (id > 0) ? (-1 * id) : id; - return id; - } - -} diff --git a/persistence-modules/spring-data-jpa/src/test/resources/application-tc-auto.properties b/persistence-modules/spring-data-jpa/src/test/resources/application-tc-auto.properties deleted file mode 100644 index c3005d861f..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/resources/application-tc-auto.properties +++ /dev/null @@ -1,4 +0,0 @@ -# configuration for test containers testing -spring.datasource.url=${DB_URL} -spring.datasource.username=${DB_USERNAME} -spring.datasource.password=${DB_PASSWORD} diff --git a/persistence-modules/spring-data-jpa/src/test/resources/application-tc.properties b/persistence-modules/spring-data-jpa/src/test/resources/application-tc.properties deleted file mode 100644 index 3bf8693d53..0000000000 --- a/persistence-modules/spring-data-jpa/src/test/resources/application-tc.properties +++ /dev/null @@ -1,4 +0,0 @@ -# configuration for Test Containers testing -spring.datasource.driver-class-name=org.postgresql.Driver -spring.jpa.hibernate.ddl-auto=create-drop -spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false From 6298b6b64a97090252b3b6d3a13e8ca42fb60e56 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 19 Jul 2020 14:36:21 +0530 Subject: [PATCH 078/309] JAVA-66: parent module pom changes corresponding to module renaming --- persistence-modules/pom.xml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index f1154f203b..c598ad8805 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -59,11 +59,12 @@ spring-data-elasticsearch spring-data-gemfire spring-data-geode - spring-data-jpa - spring-data-jpa-2 - spring-data-jpa-3 - spring-data-jpa-4 - spring-data-jpa-5 + spring-data-jpa-annotations + spring-data-jpa-crud + spring-data-jpa-enterprise + spring-data-jpa-filtering + spring-data-jpa-query + spring-data-jpa-repo spring-data-keyvalue spring-data-mongodb spring-data-neo4j From 8309e562681e944970f2f7277d06f33258031cc7 Mon Sep 17 00:00:00 2001 From: developerDiv Date: Sun, 19 Jul 2020 15:44:48 +0100 Subject: [PATCH 079/309] Rename tests --- .../mockito/argumentcaptor/Credentials.java | 1 - .../argumentcaptor/EmailServiceUnitTest.java | 21 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Credentials.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Credentials.java index 5aec15505e..d5d60bb6fc 100644 --- a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Credentials.java +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/Credentials.java @@ -6,7 +6,6 @@ public class Credentials { private final String key; public Credentials(String name, String password, String key) { - this.name = name; this.password = password; this.key = key; diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java index cdae118e92..2208bc7c7b 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java @@ -32,7 +32,7 @@ public class EmailServiceUnitTest { public void whenDoesNotSupportHtml_expectTextOnlyEmailFormat() { String to = "info@baeldung.com"; String subject = "Using ArgumentCaptor"; - String body = "Article on using ArgumentCaptor"; + String body = "Hey, let'use ArgumentCaptor"; emailService.send(to, subject, body, false); @@ -42,10 +42,10 @@ public class EmailServiceUnitTest { } @Test - public void send_whenDoesSupportHtml_expectHTMLEmailFormat() { - String to = "baeldung@baeldung.com"; - String subject = "Great New Course!"; - String body = "Try out our new course."; + public void whenDoesSupportHtml_expectHTMLEmailFormat() { + String to = "info@baeldung.com"; + String subject = "Using ArgumentCaptor"; + String body = "Hey, let'use ArgumentCaptor"; emailService.send(to, subject, body, true); @@ -55,7 +55,7 @@ public class EmailServiceUnitTest { } @Test - public void getServiceStatus_whenServiceRunning_expectUpResponse() { + public void whenServiceRunning_expectUpResponse() { when(platform.getServiceStatus()).thenReturn("OK"); ServiceStatus serviceStatus = emailService.checkServiceStatus(); @@ -64,7 +64,7 @@ public class EmailServiceUnitTest { } @Test - public void getServiceStatus_whenServiceNotRunning_expectDownResponse() { + public void whenServiceNotRunning_expectDownResponse() { when(platform.getServiceStatus()).thenReturn("Error"); ServiceStatus serviceStatus = emailService.checkServiceStatus(); @@ -73,7 +73,7 @@ public class EmailServiceUnitTest { } @Test - public void usingArgumemtMatcher_whenAuthenticatedWithValidCredentials_expectTrue() { + public void usingArgumentMatcher_whenAuthenticatedWithValidCredentials_expectTrue() { Credentials credentials = new Credentials("baeldung", "correct_password", "correct_key"); when(platform.authenticate(eq(credentials))).thenReturn(AuthenticationStatus.AUTHENTICATED); @@ -90,11 +90,10 @@ public class EmailServiceUnitTest { } @Test - public void authenticate_whenNotAuthenticated_expectFalse() { + public void whenNotAuthenticated_expectFalse() { Credentials credentials = new Credentials("baeldung", "incorrect_password", "incorrect_key"); - when(platform.authenticate(credentialsCaptor.capture())).thenReturn(AuthenticationStatus.NOT_AUTHENTICATED); + when(platform.authenticate(eq(credentials))).thenReturn(AuthenticationStatus.NOT_AUTHENTICATED); assertFalse(emailService.authenticatedSuccessfully(credentials)); - assertEquals(credentials, credentialsCaptor.getValue()); } } \ No newline at end of file From 76b1717953685a4dfb72153084b4f5645527a015 Mon Sep 17 00:00:00 2001 From: Nguyen Nam Thai Date: Sun, 19 Jul 2020 22:07:57 +0700 Subject: [PATCH 080/309] BAEL-4113 Relocate the ExceptionBenchmark class --- performance-tests/pom.xml | 13 +++++++++++++ .../exception}/ExceptionBenchmark.java | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) rename {jmh/src/main/java/com/baeldung => performance-tests/src/main/java/com/baeldung/performancetests/exception}/ExceptionBenchmark.java (97%) diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml index 0dc38e56a4..c790dbbb16 100644 --- a/performance-tests/pom.xml +++ b/performance-tests/pom.xml @@ -120,6 +120,18 @@ + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + + com.baeldung.performancetests.MappingFrameworksPerformance + + + + @@ -178,6 +190,7 @@ 1.21 1.21 3.7.0 + 3.2.0 ]](../java-collections-conversions-2) \ No newline at end of file diff --git a/java-collections/pom.xml b/java-collections/pom.xml deleted file mode 100644 index 5e0ee42244..0000000000 --- a/java-collections/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - 4.0.0 - java-collections - 0.1.0-SNAPSHOT - java-collections - jar - - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../parent-java - - - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - org.hamcrest - hamcrest-all - ${hamcrest-all.version} - test - - - - - java-collections - - - src/main/resources - true - - - - - - 4.1 - - diff --git a/java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java b/java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java deleted file mode 100644 index db61807878..0000000000 --- a/java-collections/src/main/java/com/baeldung/comparingarrays/Plane.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.comparingarrays; - -import java.util.Objects; - -public class Plane { - - private final String name; - - private final String model; - - public Plane(String name, String model) { - - this.name = name; - this.model = model; - } - - public String getName() { - return name; - } - - public String getModel() { - return model; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - Plane plane = (Plane) o; - return Objects.equals(name, plane.name) && Objects.equals(model, plane.model); - } - - @Override - public int hashCode() { - return Objects.hash(name, model); - } -} diff --git a/java-collections/src/main/resources/logback.xml b/java-collections/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/java-collections/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java deleted file mode 100644 index f311d0e5c9..0000000000 --- a/java-collections/src/test/java/com/baeldung/DeepEqualsCompareUnitTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung; - -import com.baeldung.comparingarrays.Plane; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class DeepEqualsCompareUnitTest { - - @Test - public void givenArray1andArray2_whenSameContent_thenDeepEquals() { - final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, - new Plane[] { new Plane("Plane 2", "B738") } }; - final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, - new Plane[] { new Plane("Plane 2", "B738") } }; - - boolean result = Arrays.deepEquals(planes1, planes2); - assertTrue("Result is not true", result); - } - - @Test - public void givenArray1andArray2_whenNotSameContent_thenNotDeepEquals() { - final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, - new Plane[] { new Plane("Plane 2", "B738") } }; - final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 2", "B738") }, - new Plane[] { new Plane("Plane 1", "A320") } }; - - boolean result = Arrays.deepEquals(planes1, planes2); - assertFalse("Result is true", result); - } -} diff --git a/java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java deleted file mode 100644 index b56395a848..0000000000 --- a/java-collections/src/test/java/com/baeldung/EqualsCompareUnitTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung; - -import org.junit.jupiter.api.Test; - -import java.util.Arrays; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class EqualsCompareUnitTest { - - @Test - public void givenArray1andArray2_whenSameContent_thenEquals() { - final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - - boolean result = Arrays.equals(planes1, planes2); - assertTrue("Result is not true", result); - } - - @Test - public void givenArray1andArray2_whenSameContentOtherSort_thenNotEquals() { - final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - final String[] planes2 = new String[] { "B738", "A320", "A321", "A319", "B77W", "B737", "A333", "A332" }; - - boolean result = Arrays.equals(planes1, planes2); - assertFalse("Result is true", result); - } -} diff --git a/java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java deleted file mode 100644 index 8b3c90c427..0000000000 --- a/java-collections/src/test/java/com/baeldung/LengthsCompareUnitTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung; - -import org.junit.jupiter.api.Test; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize; -import static org.junit.Assert.assertThat; - -public class LengthsCompareUnitTest { - - @Test - public void givenArray1andArray2_whenSameSizes_thenSizeEqualsOk() { - final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - final Integer[] quantities = new Integer[] { 10, 12, 34, 45, 12, 43, 5, 2 }; - - assertThat(planes1, arrayWithSize(8)); - assertThat(quantities, arrayWithSize(8)); - assertThat(planes1.length, is(8)); - assertThat(quantities.length, is(8)); - } -} - diff --git a/java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java deleted file mode 100644 index 8be7251c05..0000000000 --- a/java-collections/src/test/java/com/baeldung/OrderCompareUnitTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung; - -import com.baeldung.comparingarrays.Plane; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; -import java.util.Comparator; - -import static org.junit.Assert.assertTrue; - -public class OrderCompareUnitTest { - @Test - public void givenArray1andArray2_whenNotSameContent_thenNotDeepEquals() { - final Plane[][] planes1 = new Plane[][] { - new Plane[] { new Plane("Plane 1", "A320"), new Plane("Plane 2", "B738") } }; - final Plane[][] planes2 = new Plane[][] { - new Plane[] { new Plane("Plane 2", "B738"), new Plane("Plane 1", "A320") } }; - - Comparator planeComparator = (o1, o2) -> { - if (o1.getName() - .equals(o2.getName())) { - return o2.getModel() - .compareTo(o1.getModel()); - } - return o2.getName() - .compareTo(o1.getName()); - }; - Arrays.sort(planes1[0], planeComparator); - Arrays.sort(planes2[0], planeComparator); - - boolean result = Arrays.deepEquals(planes1, planes2); - assertTrue("Result is false", result); - } -} diff --git a/java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java b/java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java deleted file mode 100644 index 9716a34607..0000000000 --- a/java-collections/src/test/java/com/baeldung/ReferenceCompareUnitTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung; - -import org.junit.jupiter.api.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; - -public class ReferenceCompareUnitTest { - - @Test - public void givenArray1andArray2_whenEquals_thenEqual() { - final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - final String[] planes2 = planes1; - - assertSame("Objects are not equal!", planes1, planes2); - - planes2[0] = "747"; - - assertSame("Objects are not same!", planes1, planes2); - assertEquals("Objects are not equal!", "747", planes2[0]); - assertEquals("Objects are not equal!", "747", planes1[0]); - } - - @Test - public void givenArray1andArray2_whenDifferentValues_thenNotEqual() { - final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - - assertNotSame("Objects are the same!", planes1, planes2); - assertNotEquals("Objects are equal!", planes1, planes2); - } -} From ad1d9b4b847270082314659ad2736c6ee0f2fe14 Mon Sep 17 00:00:00 2001 From: Joao Esperancinha Date: Tue, 21 Jul 2020 06:37:09 +0200 Subject: [PATCH 086/309] [BAEL-4281] moves example module --- .../java/com/baeldung/arraycompare/Plane.java | 39 +++++++++++++++++++ .../DeepEqualsCompareUnitTest.java | 33 ++++++++++++++++ .../arraycompare/EqualsCompareUnitTest.java | 29 ++++++++++++++ .../arraycompare/LengthsCompareUnitTest.java | 22 +++++++++++ .../arraycompare/OrderCompareUnitTest.java | 33 ++++++++++++++++ .../ReferenceCompareUnitTest.java | 34 ++++++++++++++++ 6 files changed, 190 insertions(+) create mode 100644 core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraycompare/Plane.java create mode 100644 core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java create mode 100644 core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java create mode 100644 core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java create mode 100644 core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java create mode 100644 core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraycompare/Plane.java b/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraycompare/Plane.java new file mode 100644 index 0000000000..1731578b76 --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraycompare/Plane.java @@ -0,0 +1,39 @@ +package com.baeldung.arraycompare; + +import java.util.Objects; + +public class Plane { + + private final String name; + + private final String model; + + public Plane(String name, String model) { + + this.name = name; + this.model = model; + } + + public String getName() { + return name; + } + + public String getModel() { + return model; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Plane plane = (Plane) o; + return Objects.equals(name, plane.name) && Objects.equals(model, plane.model); + } + + @Override + public int hashCode() { + return Objects.hash(name, model); + } +} diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java new file mode 100644 index 0000000000..ab7eaec127 --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.arraycompare; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class DeepEqualsCompareUnitTest { + + @Test + public void givenArray1andArray2_whenSameContent_thenDeepEquals() { + final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, + new Plane[] { new Plane("Plane 2", "B738") } }; + final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, + new Plane[] { new Plane("Plane 2", "B738") } }; + + boolean result = Arrays.deepEquals(planes1, planes2); + assertTrue("Result is not true", result); + } + + @Test + public void givenArray1andArray2_whenNotSameContent_thenNotDeepEquals() { + final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, + new Plane[] { new Plane("Plane 2", "B738") } }; + final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 2", "B738") }, + new Plane[] { new Plane("Plane 1", "A320") } }; + + boolean result = Arrays.deepEquals(planes1, planes2); + assertFalse("Result is true", result); + } +} diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java new file mode 100644 index 0000000000..dd74eb8f0a --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung.arraycompare; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class EqualsCompareUnitTest { + + @Test + public void givenArray1andArray2_whenSameContent_thenEquals() { + final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + + boolean result = Arrays.equals(planes1, planes2); + assertTrue("Result is not true", result); + } + + @Test + public void givenArray1andArray2_whenSameContentOtherSort_thenNotEquals() { + final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + final String[] planes2 = new String[] { "B738", "A320", "A321", "A319", "B77W", "B737", "A333", "A332" }; + + boolean result = Arrays.equals(planes1, planes2); + assertFalse("Result is true", result); + } +} diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java new file mode 100644 index 0000000000..ef22d69d90 --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.arraycompare; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize; +import static org.junit.Assert.assertThat; + +public class LengthsCompareUnitTest { + + @Test + public void givenArray1andArray2_whenSameSizes_thenSizeEqualsOk() { + final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + final Integer[] quantities = new Integer[] { 10, 12, 34, 45, 12, 43, 5, 2 }; + + assertThat(planes1, arrayWithSize(8)); + assertThat(quantities, arrayWithSize(8)); + assertThat(planes1.length, is(8)); + assertThat(quantities.length, is(8)); + } +} + diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java new file mode 100644 index 0000000000..77cc91092a --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.arraycompare; + +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.Comparator; + +import static org.junit.Assert.assertTrue; + +public class OrderCompareUnitTest { + @Test + public void givenArray1andArray2_whenNotSameContent_thenNotDeepEquals() { + final Plane[][] planes1 = new Plane[][] { + new Plane[] { new Plane("Plane 1", "A320"), new Plane("Plane 2", "B738") } }; + final Plane[][] planes2 = new Plane[][] { + new Plane[] { new Plane("Plane 2", "B738"), new Plane("Plane 1", "A320") } }; + + Comparator planeComparator = (o1, o2) -> { + if (o1.getName() + .equals(o2.getName())) { + return o2.getModel() + .compareTo(o1.getModel()); + } + return o2.getName() + .compareTo(o1.getName()); + }; + Arrays.sort(planes1[0], planeComparator); + Arrays.sort(planes2[0], planeComparator); + + boolean result = Arrays.deepEquals(planes1, planes2); + assertTrue("Result is false", result); + } +} diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java new file mode 100644 index 0000000000..8a26fc8e74 --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java @@ -0,0 +1,34 @@ +package com.baeldung.arraycompare; + +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; + +public class ReferenceCompareUnitTest { + + @Test + public void givenArray1andArray2_whenEquals_thenEqual() { + final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + final String[] planes2 = planes1; + + assertSame("Objects are not equal!", planes1, planes2); + + planes2[0] = "747"; + + assertSame("Objects are not same!", planes1, planes2); + assertEquals("Objects are not equal!", "747", planes2[0]); + assertEquals("Objects are not equal!", "747", planes1[0]); + } + + @Test + public void givenArray1andArray2_whenDifferentValues_thenNotEqual() { + final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; + + assertNotSame("Objects are the same!", planes1, planes2); + assertNotEquals("Objects are equal!", planes1, planes2); + } +} From cffc591b5cd84ef056bc90d5e3a3d087d8882850 Mon Sep 17 00:00:00 2001 From: Joao Esperancinha Date: Tue, 21 Jul 2020 06:55:28 +0200 Subject: [PATCH 087/309] [BAEL-4281] Naming convention and conversion to assertJ --- .../DeepEqualsCompareUnitTest.java | 13 +++++------- .../arraycompare/EqualsCompareUnitTest.java | 13 +++++------- .../arraycompare/LengthsCompareUnitTest.java | 12 ++++------- .../arraycompare/OrderCompareUnitTest.java | 6 +++--- .../ReferenceCompareUnitTest.java | 20 ++++++++----------- 5 files changed, 25 insertions(+), 39 deletions(-) diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java index ab7eaec127..c8ebafb26b 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java @@ -4,30 +4,27 @@ import org.junit.jupiter.api.Test; import java.util.Arrays; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class DeepEqualsCompareUnitTest { @Test - public void givenArray1andArray2_whenSameContent_thenDeepEquals() { + public void givenSameContents_whenDeepEquals_thenTrue() { final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, new Plane[] { new Plane("Plane 2", "B738") } }; final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, new Plane[] { new Plane("Plane 2", "B738") } }; - boolean result = Arrays.deepEquals(planes1, planes2); - assertTrue("Result is not true", result); + assertThat(Arrays.deepEquals(planes1, planes2)).isTrue(); } @Test - public void givenArray1andArray2_whenNotSameContent_thenNotDeepEquals() { + public void givenSameContentsWithDifferentOrder_whenDeepEquals_thenFalse() { final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") }, new Plane[] { new Plane("Plane 2", "B738") } }; final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 2", "B738") }, new Plane[] { new Plane("Plane 1", "A320") } }; - boolean result = Arrays.deepEquals(planes1, planes2); - assertFalse("Result is true", result); + assertThat(Arrays.deepEquals(planes1, planes2)).isFalse(); } } diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java index dd74eb8f0a..a022bf7082 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java @@ -4,26 +4,23 @@ import org.junit.jupiter.api.Test; import java.util.Arrays; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class EqualsCompareUnitTest { @Test - public void givenArray1andArray2_whenSameContent_thenEquals() { + public void givenSameContents_whenEquals_thenTrue() { final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - boolean result = Arrays.equals(planes1, planes2); - assertTrue("Result is not true", result); + assertThat(Arrays.equals(planes1, planes2)).isTrue(); } @Test - public void givenArray1andArray2_whenSameContentOtherSort_thenNotEquals() { + public void givenSameContentsDifferentOrder_whenEquals_thenFalse() { final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; final String[] planes2 = new String[] { "B738", "A320", "A321", "A319", "B77W", "B737", "A333", "A332" }; - boolean result = Arrays.equals(planes1, planes2); - assertFalse("Result is true", result); + assertThat(Arrays.equals(planes1, planes2)).isFalse(); } } diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java index ef22d69d90..23187b827c 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java @@ -2,21 +2,17 @@ package com.baeldung.arraycompare; import org.junit.jupiter.api.Test; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class LengthsCompareUnitTest { @Test - public void givenArray1andArray2_whenSameSizes_thenSizeEqualsOk() { + public void givenSameContent_whenSizeCompare_thenTrue() { final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; final Integer[] quantities = new Integer[] { 10, 12, 34, 45, 12, 43, 5, 2 }; - assertThat(planes1, arrayWithSize(8)); - assertThat(quantities, arrayWithSize(8)); - assertThat(planes1.length, is(8)); - assertThat(quantities.length, is(8)); + assertThat(planes1).hasSize(8); + assertThat(quantities).hasSize(8); } } diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java index 77cc91092a..4dd7964020 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java @@ -5,11 +5,12 @@ import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Comparator; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertTrue; public class OrderCompareUnitTest { @Test - public void givenArray1andArray2_whenNotSameContent_thenNotDeepEquals() { + public void givenSameContentDifferentOrder_whenSortedAndDeepEquals_thenTrue() { final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320"), new Plane("Plane 2", "B738") } }; final Plane[][] planes2 = new Plane[][] { @@ -27,7 +28,6 @@ public class OrderCompareUnitTest { Arrays.sort(planes1[0], planeComparator); Arrays.sort(planes2[0], planeComparator); - boolean result = Arrays.deepEquals(planes1, planes2); - assertTrue("Result is false", result); + assertThat(Arrays.deepEquals(planes1, planes2)).isTrue(); } } diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java index 8a26fc8e74..d8072a98e3 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java @@ -2,33 +2,29 @@ package com.baeldung.arraycompare; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; +import static org.assertj.core.api.Assertions.assertThat; public class ReferenceCompareUnitTest { @Test - public void givenArray1andArray2_whenEquals_thenEqual() { + public void givenSameReferences_whenSame_thenTrue() { final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; final String[] planes2 = planes1; - assertSame("Objects are not equal!", planes1, planes2); + assertThat(planes1).isSameAs(planes2); planes2[0] = "747"; - assertSame("Objects are not same!", planes1, planes2); - assertEquals("Objects are not equal!", "747", planes2[0]); - assertEquals("Objects are not equal!", "747", planes1[0]); + assertThat(planes1).isSameAs(planes2); + assertThat(planes2[0]).isEqualTo("747"); + assertThat(planes1[0]).isEqualTo("747"); } @Test - public void givenArray1andArray2_whenDifferentValues_thenNotEqual() { + public void givenSameContentDifferentReferences_whenSame_thenFalse() { final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" }; - assertNotSame("Objects are the same!", planes1, planes2); - assertNotEquals("Objects are equal!", planes1, planes2); + assertThat(planes1).isNotSameAs(planes2); } } From f9917c483f3a37b1db1617f85b71c24f5095ff03 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Tue, 21 Jul 2020 12:59:14 +0530 Subject: [PATCH 088/309] Delete index.html --- .../http-session-example/WebContent/index.html | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 spring-session/http-session-example/WebContent/index.html diff --git a/spring-session/http-session-example/WebContent/index.html b/spring-session/http-session-example/WebContent/index.html deleted file mode 100644 index 063d330854..0000000000 --- a/spring-session/http-session-example/WebContent/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - -Insert title here - - -
-Name:

- -
- - \ No newline at end of file From 75eba2fa7d17be3afe0b76b33b23c49dc1d84a4d Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Tue, 21 Jul 2020 12:59:32 +0530 Subject: [PATCH 089/309] Delete web.xml --- .../WebContent/WEB-INF/web.xml | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 spring-session/http-session-example/WebContent/WEB-INF/web.xml diff --git a/spring-session/http-session-example/WebContent/WEB-INF/web.xml b/spring-session/http-session-example/WebContent/WEB-INF/web.xml deleted file mode 100644 index 01b1b6f308..0000000000 --- a/spring-session/http-session-example/WebContent/WEB-INF/web.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - httpsessionexample - - index.html - - - -firstservlet -httpsessionexample.FirstServlet - - - -firstservlet -/firstservlet - - - -secondservlet -httpsessionexample.SecondServlet - - - -secondservlet -/secondservlet - - - - From 8b16479fd96f9888542d6a9d052fe0d5144e1b24 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Tue, 21 Jul 2020 12:59:53 +0530 Subject: [PATCH 090/309] Delete FirstServlet.java --- .../src/httpsessionexample/FirstServlet.java | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 spring-session/http-session-example/src/httpsessionexample/FirstServlet.java diff --git a/spring-session/http-session-example/src/httpsessionexample/FirstServlet.java b/spring-session/http-session-example/src/httpsessionexample/FirstServlet.java deleted file mode 100644 index d49c0f3e14..0000000000 --- a/spring-session/http-session-example/src/httpsessionexample/FirstServlet.java +++ /dev/null @@ -1,33 +0,0 @@ -package httpsessionexample; - -import java.io.PrintWriter; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -public class FirstServlet extends HttpServlet { - public void doGet(HttpServletRequest request, HttpServletResponse response) { - try { - HttpSession session = request.getSession(); - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); - - String name = request.getParameter("userName"); - out.print("Hi " + name); - - session.setAttribute("uname", name); - out.print("
"); - out.print("Session Id : " + session.getId()); - out.print("
"); - out.print("Second Servlet"); - - out.close(); - - } catch (Exception e) { - System.out.println(e); - } - } - -} From 7ff9bc6ac811d0ee2a6623d102bbb850ce09bc64 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Tue, 21 Jul 2020 13:00:09 +0530 Subject: [PATCH 091/309] Delete SecondServlet.java --- .../src/httpsessionexample/SecondServlet.java | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 spring-session/http-session-example/src/httpsessionexample/SecondServlet.java diff --git a/spring-session/http-session-example/src/httpsessionexample/SecondServlet.java b/spring-session/http-session-example/src/httpsessionexample/SecondServlet.java deleted file mode 100644 index ab0b9c34ad..0000000000 --- a/spring-session/http-session-example/src/httpsessionexample/SecondServlet.java +++ /dev/null @@ -1,31 +0,0 @@ -package httpsessionexample; - -import java.io.PrintWriter; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -public class SecondServlet extends HttpServlet { - - public void doGet(HttpServletRequest request, HttpServletResponse response) { - try { - - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); - - HttpSession session = request.getSession(true); - String name = (String) session.getAttribute("uname"); - out.print("Hi " + name); - out.print("
"); - out.print("Session Id : " + session.getId()); - out.print("
"); - out.close(); - - } catch (Exception e) { - System.out.println(e); - } - } - -} From ccfbdd3f9c990a644e03903ab67abeadfdc7835f Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Tue, 21 Jul 2020 13:00:59 +0530 Subject: [PATCH 092/309] Add files via upload --- spring-session/http-session-example/README.md | 5 +++ spring-session/http-session-example/pom.xml | 26 +++++++++++++++ .../baeldung/httpsession/FirstServlet.java | 33 +++++++++++++++++++ .../baeldung/httpsession/SecondServlet.java | 31 +++++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 33 +++++++++++++++++++ .../src/main/webapp/index.html | 12 +++++++ 6 files changed, 140 insertions(+) create mode 100644 spring-session/http-session-example/README.md create mode 100644 spring-session/http-session-example/pom.xml create mode 100644 spring-session/http-session-example/src/main/java/com/baeldung/httpsession/FirstServlet.java create mode 100644 spring-session/http-session-example/src/main/java/com/baeldung/httpsession/SecondServlet.java create mode 100644 spring-session/http-session-example/src/main/webapp/WEB-INF/web.xml create mode 100644 spring-session/http-session-example/src/main/webapp/index.html diff --git a/spring-session/http-session-example/README.md b/spring-session/http-session-example/README.md new file mode 100644 index 0000000000..95c7a41e2d --- /dev/null +++ b/spring-session/http-session-example/README.md @@ -0,0 +1,5 @@ +## HttpSession + +This module contains article about Difference Between request.getSession() and request.getSession(true) + +### Relevant Articles: diff --git a/spring-session/http-session-example/pom.xml b/spring-session/http-session-example/pom.xml new file mode 100644 index 0000000000..a77176fb4b --- /dev/null +++ b/spring-session/http-session-example/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + com.baeldung.httpsession + http-session-example + war + 0.0.1-SNAPSHOT + http-session-example Maven Webapp + http://maven.apache.org + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + javax.servlet + servlet-api + 2.5 + provided + + + diff --git a/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/FirstServlet.java b/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/FirstServlet.java new file mode 100644 index 0000000000..950bea2c07 --- /dev/null +++ b/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/FirstServlet.java @@ -0,0 +1,33 @@ +package com.baeldung.httpsession; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +public class FirstServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + HttpSession session = request.getSession(); + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + String name = request.getParameter("userName"); + session.setAttribute("uname", name); + out.println("Hi " + name + " Your Session Id is : " + session.getId() + " "); + + out.println("
Second Servlet"); + + out.close(); + + } catch (Exception e) { + System.out.println(e); + } + } + +} diff --git a/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/SecondServlet.java b/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/SecondServlet.java new file mode 100644 index 0000000000..6a5ef7e9a8 --- /dev/null +++ b/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/SecondServlet.java @@ -0,0 +1,31 @@ +package com.baeldung.httpsession; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +public class SecondServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + try { + + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + + HttpSession session = request.getSession(true); + String name = (String) session.getAttribute("uname"); + out.println("Hi " + name + " Your Session Id is : " + session.getId()); + + out.close(); + + } catch (Exception e) { + System.out.println(e); + } + } + +} diff --git a/spring-session/http-session-example/src/main/webapp/WEB-INF/web.xml b/spring-session/http-session-example/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..2c9a4c118b --- /dev/null +++ b/spring-session/http-session-example/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,33 @@ + + + + httpsession + + index.html + + + + + FirstServlet + com.baeldung.httpsession.FirstServlet + + + SecondServlet + com.baeldung.httpsession.SecondServlet + + + + + FirstServlet + /first + + + SecondServlet + /second + + + + \ No newline at end of file diff --git a/spring-session/http-session-example/src/main/webapp/index.html b/spring-session/http-session-example/src/main/webapp/index.html new file mode 100644 index 0000000000..0e5889f21a --- /dev/null +++ b/spring-session/http-session-example/src/main/webapp/index.html @@ -0,0 +1,12 @@ + + + + + + +
+ Name:

+
+ + \ No newline at end of file From f673723619daeb0c4184d7b6a6af991c0e819525 Mon Sep 17 00:00:00 2001 From: Adrian Maghear Date: Tue, 21 Jul 2020 17:08:30 +0200 Subject: [PATCH 093/309] [BAEL-4288] address comments after review --- persistence-modules/flyway-repair/README.MD | 1 - 1 file changed, 1 deletion(-) diff --git a/persistence-modules/flyway-repair/README.MD b/persistence-modules/flyway-repair/README.MD index ca029e8299..7d843af9ea 100644 --- a/persistence-modules/flyway-repair/README.MD +++ b/persistence-modules/flyway-repair/README.MD @@ -1,2 +1 @@ ### Relevant Articles: -- [Flyway Repair With Spring Boot](http://www.baeldung.com/flyway-repair-with-spring-boot) From 4c4b784d02397a299896961304dbb279160a5eaa Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Tue, 21 Jul 2020 20:24:51 +0200 Subject: [PATCH 094/309] JAVA-1649: Get rid of the overriden spring-boot.version property --- spring-security-modules/spring-security-oidc/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spring-security-modules/spring-security-oidc/pom.xml b/spring-security-modules/spring-security-oidc/pom.xml index 91e4641450..b9a4b340a3 100644 --- a/spring-security-modules/spring-security-oidc/pom.xml +++ b/spring-security-modules/spring-security-oidc/pom.xml @@ -26,8 +26,4 @@ - - 2.2.1.RELEASE - - From ab755bf0988833e15380c4c1c8c1fb89cea1b984 Mon Sep 17 00:00:00 2001 From: developerDiv Date: Tue, 21 Jul 2020 21:32:40 +0100 Subject: [PATCH 095/309] Add static class to 'eq' and 'when' for greater readability. --- .../argumentcaptor/EmailServiceUnitTest.java | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java index 2208bc7c7b..9d18957b2e 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java @@ -2,16 +2,10 @@ package com.baeldung.mockito.argumentcaptor; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.InjectMocks; -import org.mockito.Mock; +import org.mockito.*; import org.mockito.junit.MockitoJUnitRunner; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class EmailServiceUnitTest { @@ -36,7 +30,7 @@ public class EmailServiceUnitTest { emailService.send(to, subject, body, false); - verify(platform).send(emailCaptor.capture()); + Mockito.verify(platform).send(emailCaptor.capture()); Email emailCaptorValue = emailCaptor.getValue(); assertEquals(Format.TEXT_ONLY, emailCaptorValue.getFormat()); } @@ -49,14 +43,14 @@ public class EmailServiceUnitTest { emailService.send(to, subject, body, true); - verify(platform).send(emailCaptor.capture()); + Mockito.verify(platform).send(emailCaptor.capture()); Email value = emailCaptor.getValue(); assertEquals(Format.HTML, value.getFormat()); } @Test public void whenServiceRunning_expectUpResponse() { - when(platform.getServiceStatus()).thenReturn("OK"); + Mockito.when(platform.getServiceStatus()).thenReturn("OK"); ServiceStatus serviceStatus = emailService.checkServiceStatus(); @@ -65,7 +59,7 @@ public class EmailServiceUnitTest { @Test public void whenServiceNotRunning_expectDownResponse() { - when(platform.getServiceStatus()).thenReturn("Error"); + Mockito.when(platform.getServiceStatus()).thenReturn("Error"); ServiceStatus serviceStatus = emailService.checkServiceStatus(); @@ -75,15 +69,15 @@ public class EmailServiceUnitTest { @Test public void usingArgumentMatcher_whenAuthenticatedWithValidCredentials_expectTrue() { Credentials credentials = new Credentials("baeldung", "correct_password", "correct_key"); - when(platform.authenticate(eq(credentials))).thenReturn(AuthenticationStatus.AUTHENTICATED); + Mockito.when(platform.authenticate(Mockito.eq(credentials))).thenReturn(AuthenticationStatus.AUTHENTICATED); assertTrue(emailService.authenticatedSuccessfully(credentials)); } @Test - public void usingArgumentCapture_whenAuthenticatedWithValidCredentials_expectTrue() { + public void usingArgumentCaptor_whenAuthenticatedWithValidCredentials_expectTrue() { Credentials credentials = new Credentials("baeldung", "correct_password", "correct_key"); - when(platform.authenticate(credentialsCaptor.capture())).thenReturn(AuthenticationStatus.AUTHENTICATED); + Mockito.when(platform.authenticate(credentialsCaptor.capture())).thenReturn(AuthenticationStatus.AUTHENTICATED); assertTrue(emailService.authenticatedSuccessfully(credentials)); assertEquals(credentials, credentialsCaptor.getValue()); @@ -92,7 +86,7 @@ public class EmailServiceUnitTest { @Test public void whenNotAuthenticated_expectFalse() { Credentials credentials = new Credentials("baeldung", "incorrect_password", "incorrect_key"); - when(platform.authenticate(eq(credentials))).thenReturn(AuthenticationStatus.NOT_AUTHENTICATED); + Mockito.when(platform.authenticate(Mockito.eq(credentials))).thenReturn(AuthenticationStatus.NOT_AUTHENTICATED); assertFalse(emailService.authenticatedSuccessfully(credentials)); } From a72f2f144cbd2d446e16860b72995f5f048b5e2c Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 22 Jul 2020 19:43:35 +0430 Subject: [PATCH 096/309] Switching the For Blocks! --- .../collections/bitset/BitSetUnitTest.java | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/bitset/BitSetUnitTest.java b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/bitset/BitSetUnitTest.java index 74aa224a49..d9340f45c1 100644 --- a/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/bitset/BitSetUnitTest.java +++ b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/bitset/BitSetUnitTest.java @@ -32,14 +32,18 @@ public class BitSetUnitTest { assertThat(bitSet.get(10)).isTrue(); bitSet.set(20, 30); - for (int i = 20; i <= 29; i++) assertThat(bitSet.get(i)).isTrue(); + for (int i = 20; i <= 29; i++) { + assertThat(bitSet.get(i)).isTrue(); + } assertThat(bitSet.get(30)).isFalse(); bitSet.set(10, false); assertThat(bitSet.get(10)).isFalse(); bitSet.set(20, 30, false); - for (int i = 20; i <= 30; i++) assertThat(bitSet.get(i)).isFalse(); + for (int i = 20; i <= 30; i++) { + assertThat(bitSet.get(i)).isFalse(); + } } @Test @@ -52,14 +56,20 @@ public class BitSetUnitTest { assertThat(bitSet.get(42)).isFalse(); bitSet.set(10, 20); - for (int i = 10; i < 20; i++) assertThat(bitSet.get(i)).isTrue(); + for (int i = 10; i < 20; i++) { + assertThat(bitSet.get(i)).isTrue(); + } bitSet.clear(10, 20); - for (int i = 10; i < 20; i++) assertThat(bitSet.get(i)).isFalse(); + for (int i = 10; i < 20; i++) { + assertThat(bitSet.get(i)).isFalse(); + } bitSet.set(10, 20); bitSet.clear(); - for (int i = 0; i < 100; i++) assertThat(bitSet.get(i)).isFalse(); + for (int i = 0; i < 100; i++) { + assertThat(bitSet.get(i)).isFalse(); + } } @Test @@ -72,7 +82,9 @@ public class BitSetUnitTest { bitSet.set(10, 20); BitSet newBitSet = bitSet.get(10, 20); - for (int i = 0; i < 10; i++) assertThat(newBitSet.get(i)).isTrue(); + for (int i = 0; i < 10; i++) { + assertThat(newBitSet.get(i)).isTrue(); + } } @Test @@ -86,7 +98,9 @@ public class BitSetUnitTest { assertThat(bitSet.get(12)).isTrue(); bitSet.flip(30, 40); - for (int i = 30; i < 40; i++) assertThat(bitSet.get(i)).isTrue(); + for (int i = 30; i < 40; i++) { + assertThat(bitSet.get(i)).isTrue(); + } } @Test @@ -130,8 +144,12 @@ public class BitSetUnitTest { first.set(5, 10); first.xor(second); - for (int i = 5; i < 7; i++) assertThat(first.get(i)).isTrue(); - for (int i = 10; i < 15; i++) assertThat(first.get(i)).isTrue(); + for (int i = 5; i < 7; i++) { + assertThat(first.get(i)).isTrue(); + } + for (int i = 10; i < 15; i++) { + assertThat(first.get(i)).isTrue(); + } } @Test From adc586c566c65f256bb9d84c25416f01c4d73e9c Mon Sep 17 00:00:00 2001 From: helga_sh Date: Tue, 21 Jul 2020 16:24:31 +0300 Subject: [PATCH 097/309] CNN example with Deeplearning4j in Java --- deeplearning4j/pom.xml | 10 ++ .../deeplearning4j/cnn/CnnExample.java | 21 +++ .../cnn/domain/network/CnnModel.java | 120 ++++++++++++++++++ .../domain/network/CnnModelProperties.java | 13 ++ .../service/dataset/CifarDataSetService.java | 46 +++++++ .../cnn/service/dataset/IDataSetService.java | 16 +++ 6 files changed, 226 insertions(+) create mode 100644 deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnExample.java create mode 100644 deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModel.java create mode 100644 deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModelProperties.java create mode 100644 deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/CifarDataSetService.java create mode 100644 deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/IDataSetService.java diff --git a/deeplearning4j/pom.xml b/deeplearning4j/pom.xml index c8fa18cbd4..d88c877aa4 100644 --- a/deeplearning4j/pom.xml +++ b/deeplearning4j/pom.xml @@ -37,6 +37,16 @@ deeplearning4j-nn ${dl4j.version} + + org.slf4j + slf4j-api + 1.7.5 + + + org.slf4j + slf4j-log4j12 + 1.7.5 + org.datavec diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnExample.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnExample.java new file mode 100644 index 0000000000..2e2d4392b8 --- /dev/null +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnExample.java @@ -0,0 +1,21 @@ +package com.baeldung.deeplearning4j.cnn; + + +import com.baeldung.deeplearning4j.cnn.domain.network.CnnModel; +import com.baeldung.deeplearning4j.cnn.domain.network.CnnModelProperties; +import com.baeldung.deeplearning4j.cnn.service.dataset.CifarDataSetService; +import lombok.extern.slf4j.Slf4j; +import org.deeplearning4j.eval.Evaluation; + +@Slf4j +public class CnnExample { + + public static void main(String... args) { + CnnModel network = new CnnModel(new CifarDataSetService(), new CnnModelProperties()); + + network.train(); + Evaluation evaluation = network.evaluate(); + + log.info(evaluation.stats()); + } +} diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModel.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModel.java new file mode 100644 index 0000000000..037d14529c --- /dev/null +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModel.java @@ -0,0 +1,120 @@ +package com.baeldung.deeplearning4j.cnn.domain.network; + +import com.baeldung.deeplearning4j.cnn.service.dataset.IDataSetService; +import lombok.extern.slf4j.Slf4j; +import org.deeplearning4j.eval.Evaluation; +import org.deeplearning4j.nn.api.OptimizationAlgorithm; +import org.deeplearning4j.nn.conf.MultiLayerConfiguration; +import org.deeplearning4j.nn.conf.NeuralNetConfiguration; +import org.deeplearning4j.nn.conf.layers.ConvolutionLayer; +import org.deeplearning4j.nn.conf.layers.OutputLayer; +import org.deeplearning4j.nn.conf.layers.SubsamplingLayer; +import org.deeplearning4j.nn.multilayer.MultiLayerNetwork; +import org.deeplearning4j.nn.weights.WeightInit; +import org.nd4j.linalg.activations.Activation; +import org.nd4j.linalg.lossfunctions.LossFunctions; + +import java.util.stream.IntStream; + +@Slf4j +public class CnnModel { + + private final IDataSetService dataSetService; + + private MultiLayerNetwork network; + + private final CnnModelProperties properties; + + public CnnModel(IDataSetService dataSetService, CnnModelProperties properties) { + + this.dataSetService = dataSetService; + this.properties = properties; + + MultiLayerConfiguration configuration = new NeuralNetConfiguration.Builder() + .seed(1611) + .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) + .learningRate(properties.getLearningRate()) + .regularization(true) + .updater(properties.getOptimizer()) + .list() + .layer(0, conv5x5()) + .layer(1, pooling2x2Stride2()) + .layer(2, conv3x3Stride1Padding2()) + .layer(3, pooling2x2Stride1()) + .layer(4, conv3x3Stride1Padding1()) + .layer(5, pooling2x2Stride1()) + .layer(6, dense()) + .pretrain(false) + .backprop(true) + .setInputType(dataSetService.inputType()) + .build(); + + network = new MultiLayerNetwork(configuration); + } + + public void train() { + network.init(); + int epochsNum = properties.getEpochsNum(); + IntStream.range(1, epochsNum + 1).forEach(epoch -> { + log.info(String.format("Epoch %d?%d", epoch, epochsNum)); + network.fit(dataSetService.trainIterator()); + }); + } + + public Evaluation evaluate() { + return network.evaluate(dataSetService.testIterator()); + } + + private ConvolutionLayer conv5x5() { + return new ConvolutionLayer.Builder(5, 5) + .nIn(3) + .nOut(16) + .stride(1, 1) + .padding(1, 1) + .weightInit(WeightInit.XAVIER_UNIFORM) + .activation(Activation.RELU) + .build(); + } + + private SubsamplingLayer pooling2x2Stride2() { + return new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX) + .kernelSize(2, 2) + .stride(2, 2) + .build(); + } + + private ConvolutionLayer conv3x3Stride1Padding2() { + return new ConvolutionLayer.Builder(3, 3) + .nOut(32) + .stride(1, 1) + .padding(2, 2) + .weightInit(WeightInit.XAVIER_UNIFORM) + .activation(Activation.RELU) + .build(); + } + + private SubsamplingLayer pooling2x2Stride1() { + return new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX) + .kernelSize(2,2) + .stride(1, 1) + .build(); + } + + private ConvolutionLayer conv3x3Stride1Padding1() { + return new ConvolutionLayer.Builder(3, 3) + .nOut(64) + .stride(1, 1) + .padding(1, 1) + .weightInit(WeightInit.XAVIER_UNIFORM) + .activation(Activation.RELU) + .build(); + } + + private OutputLayer dense() { + return new OutputLayer.Builder(LossFunctions.LossFunction.MEAN_SQUARED_LOGARITHMIC_ERROR) + .activation(Activation.SOFTMAX) + .weightInit(WeightInit.XAVIER_UNIFORM) + .nOut(dataSetService.labels().size() - 1) + .build(); + } +} diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModelProperties.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModelProperties.java new file mode 100644 index 0000000000..7ea3a71363 --- /dev/null +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModelProperties.java @@ -0,0 +1,13 @@ +package com.baeldung.deeplearning4j.cnn.domain.network; + +import lombok.Value; +import org.deeplearning4j.nn.conf.Updater; + +@Value +public class CnnModelProperties { + private final int epochsNum = 512; + + private final double learningRate = 0.001; + + private final Updater optimizer = Updater.ADAM; +} diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/CifarDataSetService.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/CifarDataSetService.java new file mode 100644 index 0000000000..cb69d0c818 --- /dev/null +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/CifarDataSetService.java @@ -0,0 +1,46 @@ +package com.baeldung.deeplearning4j.cnn.service.dataset; + +import lombok.Getter; +import org.deeplearning4j.datasets.iterator.impl.CifarDataSetIterator; +import org.deeplearning4j.nn.conf.inputs.InputType; +import org.nd4j.linalg.dataset.api.iterator.DataSetIterator; + +import java.util.List; + +@Getter +public class CifarDataSetService implements IDataSetService { + + private CifarDataSetIterator trainIterator; + private CifarDataSetIterator testIterator; + + private final InputType inputType = InputType.convolutional(32,32,3); + private final int trainImagesNum = 512; + private final int testImagesNum = 128; + private final int trainBatch = 16; + private final int testBatch = 8; + + public CifarDataSetService() { + trainIterator = new CifarDataSetIterator(trainBatch, trainImagesNum, true); + testIterator = new CifarDataSetIterator(testBatch, testImagesNum, false); + } + + @Override + public DataSetIterator trainIterator() { + return trainIterator; + } + + @Override + public DataSetIterator testIterator() { + return testIterator; + } + + @Override + public InputType inputType() { + return inputType; + } + + @Override + public List labels() { + return trainIterator.getLabels(); + } +} diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/IDataSetService.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/IDataSetService.java new file mode 100644 index 0000000000..c27e566076 --- /dev/null +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/IDataSetService.java @@ -0,0 +1,16 @@ +package com.baeldung.deeplearning4j.cnn.service.dataset; + +import org.deeplearning4j.nn.conf.inputs.InputType; +import org.nd4j.linalg.dataset.api.iterator.DataSetIterator; + +import java.util.List; + +public interface IDataSetService { + DataSetIterator trainIterator(); + + DataSetIterator testIterator(); + + InputType inputType(); + + List labels(); +} From 0df52dda7ca2109906fcbc49390be76275e825c0 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:03:11 +0800 Subject: [PATCH 098/309] Update README.md --- core-java-modules/core-java-exceptions-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-exceptions-2/README.md b/core-java-modules/core-java-exceptions-2/README.md index 7c5db06a55..e6441c2c12 100644 --- a/core-java-modules/core-java-exceptions-2/README.md +++ b/core-java-modules/core-java-exceptions-2/README.md @@ -13,3 +13,4 @@ This module contains articles about core java exceptions - [Java Global Exception Handler](https://www.baeldung.com/java-global-exception-handler) - [How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause) - [Java IOException “Too many open files”](https://www.baeldung.com/java-too-many-open-files) +- [When Does Java Throw the ExceptionInInitializerError?](https://www.baeldung.com/java-exceptionininitializererror) From 2bc4c93e7b29c96eb91d8d66a0026949a3509fff Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:06:51 +0800 Subject: [PATCH 099/309] Update README.md --- testing-modules/selenium-junit-testng/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/selenium-junit-testng/README.md b/testing-modules/selenium-junit-testng/README.md index 8baddd3449..aa3f0e8005 100644 --- a/testing-modules/selenium-junit-testng/README.md +++ b/testing-modules/selenium-junit-testng/README.md @@ -4,3 +4,4 @@ - [Testing with Selenium/WebDriver and the Page Object Pattern](http://www.baeldung.com/selenium-webdriver-page-object) - [Using Cookies With Selenium WebDriver in Java](https://www.baeldung.com/java-selenium-webdriver-cookies) - [Clicking Elements in Selenium using JavaScript](https://www.baeldung.com/java-selenium-javascript) +- [Taking Screenshots With Selenium WebDriver](https://www.baeldung.com/java-selenium-screenshots) From 9bee8e34ec397aa6bdff9366c9ac9a44d01e2943 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:09:08 +0800 Subject: [PATCH 100/309] Update README.md --- java-numbers-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-numbers-3/README.md b/java-numbers-3/README.md index 9c323a6c6a..ab0bbd995d 100644 --- a/java-numbers-3/README.md +++ b/java-numbers-3/README.md @@ -13,4 +13,5 @@ This module contains articles about numbers in Java. - [Guide to the Number Class in Java](https://www.baeldung.com/java-number-class) - [Print an Integer in Binary Format in Java](https://www.baeldung.com/java-print-integer-binary) - [Number Formatting in Java](https://www.baeldung.com/java-number-formatting) +- [Division by Zero in Java: Exception, Infinity, or Not a Number](https://www.baeldung.com/java-division-by-zero) - More articles: [[<-- prev]](/java-numbers-2) From 5be7937077fb270bb812cafa1edfb734c0799197 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:12:46 +0800 Subject: [PATCH 101/309] Update README.md --- image-processing/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/image-processing/README.md b/image-processing/README.md index 50129bb994..afe92466c1 100644 --- a/image-processing/README.md +++ b/image-processing/README.md @@ -6,3 +6,4 @@ This module contains articles about image processing. - [Working with Images in Java](https://www.baeldung.com/java-images) - [Intro to OpenCV with Java](https://www.baeldung.com/java-opencv) - [Optical Character Recognition with Tesseract](https://www.baeldung.com/java-ocr-tesseract) +- [How Can I Resize an Image Using Java?](https://www.baeldung.com/java-resize-image) From 51f1fc9b1e07d5bd342b583b750b66bcabf13838 Mon Sep 17 00:00:00 2001 From: helga_sh Date: Thu, 23 Jul 2020 16:17:04 +0300 Subject: [PATCH 102/309] CNN example with Deeplearning4j in Java: refactor --- deeplearning4j/pom.xml | 5 +++-- .../dataset => }/CifarDataSetService.java | 15 ++++++------- .../deeplearning4j/cnn/CnnExample.java | 5 +---- .../cnn/{domain/network => }/CnnModel.java | 21 +++++++++---------- .../network => }/CnnModelProperties.java | 4 ++-- .../dataset => }/IDataSetService.java | 4 ++-- 6 files changed, 26 insertions(+), 28 deletions(-) rename deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/{service/dataset => }/CifarDataSetService.java (79%) rename deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/{domain/network => }/CnnModel.java (86%) rename deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/{domain/network => }/CnnModelProperties.java (70%) rename deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/{service/dataset => }/IDataSetService.java (74%) diff --git a/deeplearning4j/pom.xml b/deeplearning4j/pom.xml index d88c877aa4..e1e4998c98 100644 --- a/deeplearning4j/pom.xml +++ b/deeplearning4j/pom.xml @@ -40,12 +40,12 @@ org.slf4j slf4j-api - 1.7.5 + ${sl4j.version} org.slf4j slf4j-log4j12 - 1.7.5 + ${sl4j.version} @@ -63,6 +63,7 @@ 0.9.1 4.3.5 + 1.7.5 diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/CifarDataSetService.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CifarDataSetService.java similarity index 79% rename from deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/CifarDataSetService.java rename to deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CifarDataSetService.java index cb69d0c818..70348a6d9e 100644 --- a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/CifarDataSetService.java +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CifarDataSetService.java @@ -1,4 +1,4 @@ -package com.baeldung.deeplearning4j.cnn.service.dataset; +package com.baeldung.deeplearning4j.cnn; import lombok.Getter; import org.deeplearning4j.datasets.iterator.impl.CifarDataSetIterator; @@ -8,18 +8,19 @@ import org.nd4j.linalg.dataset.api.iterator.DataSetIterator; import java.util.List; @Getter -public class CifarDataSetService implements IDataSetService { +class CifarDataSetService implements IDataSetService { - private CifarDataSetIterator trainIterator; - private CifarDataSetIterator testIterator; - - private final InputType inputType = InputType.convolutional(32,32,3); + private final InputType inputType = InputType.convolutional(32, 32, 3); private final int trainImagesNum = 512; private final int testImagesNum = 128; private final int trainBatch = 16; private final int testBatch = 8; - public CifarDataSetService() { + private final CifarDataSetIterator trainIterator; + + private final CifarDataSetIterator testIterator; + + CifarDataSetService() { trainIterator = new CifarDataSetIterator(trainBatch, trainImagesNum, true); testIterator = new CifarDataSetIterator(testBatch, testImagesNum, false); } diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnExample.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnExample.java index 2e2d4392b8..224062c388 100644 --- a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnExample.java +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnExample.java @@ -1,14 +1,11 @@ package com.baeldung.deeplearning4j.cnn; -import com.baeldung.deeplearning4j.cnn.domain.network.CnnModel; -import com.baeldung.deeplearning4j.cnn.domain.network.CnnModelProperties; -import com.baeldung.deeplearning4j.cnn.service.dataset.CifarDataSetService; import lombok.extern.slf4j.Slf4j; import org.deeplearning4j.eval.Evaluation; @Slf4j -public class CnnExample { +class CnnExample { public static void main(String... args) { CnnModel network = new CnnModel(new CifarDataSetService(), new CnnModelProperties()); diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModel.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnModel.java similarity index 86% rename from deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModel.java rename to deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnModel.java index 037d14529c..bd87709c0e 100644 --- a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModel.java +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnModel.java @@ -1,6 +1,5 @@ -package com.baeldung.deeplearning4j.cnn.domain.network; +package com.baeldung.deeplearning4j.cnn; -import com.baeldung.deeplearning4j.cnn.service.dataset.IDataSetService; import lombok.extern.slf4j.Slf4j; import org.deeplearning4j.eval.Evaluation; import org.deeplearning4j.nn.api.OptimizationAlgorithm; @@ -17,15 +16,15 @@ import org.nd4j.linalg.lossfunctions.LossFunctions; import java.util.stream.IntStream; @Slf4j -public class CnnModel { +class CnnModel { private final IDataSetService dataSetService; - private MultiLayerNetwork network; + private final MultiLayerNetwork network; private final CnnModelProperties properties; - public CnnModel(IDataSetService dataSetService, CnnModelProperties properties) { + CnnModel(IDataSetService dataSetService, CnnModelProperties properties) { this.dataSetService = dataSetService; this.properties = properties; @@ -52,17 +51,17 @@ public class CnnModel { network = new MultiLayerNetwork(configuration); } - public void train() { + void train() { network.init(); int epochsNum = properties.getEpochsNum(); IntStream.range(1, epochsNum + 1).forEach(epoch -> { - log.info(String.format("Epoch %d?%d", epoch, epochsNum)); + log.info("Epoch {} / {}", epoch, epochsNum); network.fit(dataSetService.trainIterator()); }); } - public Evaluation evaluate() { - return network.evaluate(dataSetService.testIterator()); + Evaluation evaluate() { + return network.evaluate(dataSetService.testIterator()); } private ConvolutionLayer conv5x5() { @@ -84,7 +83,7 @@ public class CnnModel { } private ConvolutionLayer conv3x3Stride1Padding2() { - return new ConvolutionLayer.Builder(3, 3) + return new ConvolutionLayer.Builder(3, 3) .nOut(32) .stride(1, 1) .padding(2, 2) @@ -95,7 +94,7 @@ public class CnnModel { private SubsamplingLayer pooling2x2Stride1() { return new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX) - .kernelSize(2,2) + .kernelSize(2, 2) .stride(1, 1) .build(); } diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModelProperties.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnModelProperties.java similarity index 70% rename from deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModelProperties.java rename to deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnModelProperties.java index 7ea3a71363..d010d789c8 100644 --- a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/domain/network/CnnModelProperties.java +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnModelProperties.java @@ -1,10 +1,10 @@ -package com.baeldung.deeplearning4j.cnn.domain.network; +package com.baeldung.deeplearning4j.cnn; import lombok.Value; import org.deeplearning4j.nn.conf.Updater; @Value -public class CnnModelProperties { +class CnnModelProperties { private final int epochsNum = 512; private final double learningRate = 0.001; diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/IDataSetService.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/IDataSetService.java similarity index 74% rename from deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/IDataSetService.java rename to deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/IDataSetService.java index c27e566076..ea88bf550c 100644 --- a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/service/dataset/IDataSetService.java +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/IDataSetService.java @@ -1,11 +1,11 @@ -package com.baeldung.deeplearning4j.cnn.service.dataset; +package com.baeldung.deeplearning4j.cnn; import org.deeplearning4j.nn.conf.inputs.InputType; import org.nd4j.linalg.dataset.api.iterator.DataSetIterator; import java.util.List; -public interface IDataSetService { +interface IDataSetService { DataSetIterator trainIterator(); DataSetIterator testIterator(); From 8d04aa3205dc308dd58e745c55057054d3be3438 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:18:07 +0800 Subject: [PATCH 103/309] Create README.md --- maven-modules/version-collision/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 maven-modules/version-collision/README.md diff --git a/maven-modules/version-collision/README.md b/maven-modules/version-collision/README.md new file mode 100644 index 0000000000..a71cfdb0b4 --- /dev/null +++ b/maven-modules/version-collision/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [How to Resolve a Version Collision of Artifacts in Maven](https://www.baeldung.com/maven-version-collision) From 38af7ca655a60b80aaaea15facefc2ddc2490ec9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:21:28 +0800 Subject: [PATCH 104/309] Update README.md --- core-java-modules/core-java-lang-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-3/README.md b/core-java-modules/core-java-lang-3/README.md index d735937a02..9ce49da868 100644 --- a/core-java-modules/core-java-lang-3/README.md +++ b/core-java-modules/core-java-lang-3/README.md @@ -3,4 +3,5 @@ This module contains articles about core features in the Java language - [Class.isInstance vs Class.isAssignableFrom](https://www.baeldung.com/java-isinstance-isassignablefrom) +- [Converting a Java String Into a Boolean](https://www.baeldung.com/java-string-to-boolean) - [[<-- Prev]](/core-java-modules/core-java-lang-2) From 0423acd0d2a231bb6bc6f1f7522c3906f6e46816 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:24:48 +0800 Subject: [PATCH 105/309] Update README.md --- core-java-modules/core-java-concurrency-basic-2/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java-modules/core-java-concurrency-basic-2/README.md b/core-java-modules/core-java-concurrency-basic-2/README.md index c7143baf36..a8daf14ea9 100644 --- a/core-java-modules/core-java-concurrency-basic-2/README.md +++ b/core-java-modules/core-java-concurrency-basic-2/README.md @@ -3,10 +3,12 @@ This module contains articles about basic Java concurrency ### Relevant Articles: + - [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution) - [wait and notify() Methods in Java](https://www.baeldung.com/java-wait-notify) - [Difference Between Wait and Sleep in Java](https://www.baeldung.com/java-wait-and-sleep) - [Guide to the Synchronized Keyword in Java](https://www.baeldung.com/java-synchronized) - [Life Cycle of a Thread in Java](https://www.baeldung.com/java-thread-lifecycle) - [Guide to AtomicMarkableReference](https://www.baeldung.com/java-atomicmarkablereference) +- [Why are Local Variables Thread-Safe in Java](https://www.baeldung.com/java-local-variables-thread-safe) - [[<-- Prev]](/core-java-modules/core-java-concurrency-basic) From 5b354924745fdbf2a011f6f3791cff27dc27e9a6 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:28:59 +0800 Subject: [PATCH 106/309] Update README.md --- image-processing/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/image-processing/README.md b/image-processing/README.md index afe92466c1..eba23f83eb 100644 --- a/image-processing/README.md +++ b/image-processing/README.md @@ -7,3 +7,4 @@ This module contains articles about image processing. - [Intro to OpenCV with Java](https://www.baeldung.com/java-opencv) - [Optical Character Recognition with Tesseract](https://www.baeldung.com/java-ocr-tesseract) - [How Can I Resize an Image Using Java?](https://www.baeldung.com/java-resize-image) +- [Adding Text to an Image in Java](https://www.baeldung.com/java-add-text-to-image) From 60ca1bc31b28c5a33c8e7d2eb7d541bf4340dda1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:31:26 +0800 Subject: [PATCH 107/309] Update README.md --- spring-boot-modules/spring-boot-properties-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-properties-2/README.md b/spring-boot-modules/spring-boot-properties-2/README.md index 4e03a4125c..c81ad50e40 100644 --- a/spring-boot-modules/spring-boot-properties-2/README.md +++ b/spring-boot-modules/spring-boot-properties-2/README.md @@ -10,4 +10,5 @@ This module contains articles about Properties in Spring Boot. - [@PropertySource with YAML Files in Spring Boot](https://www.baeldung.com/spring-yaml-propertysource) - [Inject Arrays and Lists From Spring Properties Files](https://www.baeldung.com/spring-inject-arrays-lists) - [Inject a Map from a YAML File with Spring](https://www.baeldung.com/spring-yaml-inject-map) +- [YAML to List of Objects in Spring Boot](https://www.baeldung.com/spring-boot-yaml-list) - More articles: [[<-- prev]](../spring-boot-properties) From 88b1d2661a29a448abadf27c60b8ffc25d0a1e07 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:33:56 +0800 Subject: [PATCH 108/309] Update README.md --- persistence-modules/core-java-persistence/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/core-java-persistence/README.md b/persistence-modules/core-java-persistence/README.md index f5d3f12d7a..88442a94c8 100644 --- a/persistence-modules/core-java-persistence/README.md +++ b/persistence-modules/core-java-persistence/README.md @@ -10,3 +10,4 @@ - [Guide to the JDBC ResultSet Interface](https://www.baeldung.com/jdbc-resultset) - [Types of SQL Joins](https://www.baeldung.com/sql-joins) - [Returning the Generated Keys in JDBC](https://www.baeldung.com/jdbc-returning-generated-keys) +- [Loading JDBC Drivers](https://www.baeldung.com/java-jdbc-loading-drivers) From 09441449d7997956a22feadff459b761c96f495e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:36:52 +0800 Subject: [PATCH 109/309] Update README.md --- apache-shiro/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apache-shiro/README.md b/apache-shiro/README.md index ed63c569da..3a0088072f 100644 --- a/apache-shiro/README.md +++ b/apache-shiro/README.md @@ -6,4 +6,4 @@ This module contains articles about Apache Shiro - [Introduction to Apache Shiro](https://www.baeldung.com/apache-shiro) - [Permissions-Based Access Control with Apache Shiro](https://www.baeldung.com/apache-shiro-access-control) - +- [Spring Security vs Apache Shiro](https://www.baeldung.com/spring-security-vs-apache-shiro) From bf922cb955eedc299360667fef4d2e23ce018bd6 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:39:16 +0800 Subject: [PATCH 110/309] Update README.md --- core-java-modules/core-java-collections-3/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java-modules/core-java-collections-3/README.md b/core-java-modules/core-java-collections-3/README.md index fb983d9abc..4349ef6be3 100644 --- a/core-java-modules/core-java-collections-3/README.md +++ b/core-java-modules/core-java-collections-3/README.md @@ -3,6 +3,7 @@ ## Core Java Collections Cookbooks and Examples ### Relevant Articles: + - [Time Comparison of Arrays.sort(Object[]) and Arrays.sort(int[])](https://www.baeldung.com/arrays-sortobject-vs-sortint) - [Java ArrayList vs Vector](https://www.baeldung.com/java-arraylist-vs-vector) - [Differences Between HashMap and Hashtable](https://www.baeldung.com/hashmap-hashtable-differences) @@ -10,3 +11,4 @@ - [Performance of contains() in a HashSet vs ArrayList](https://www.baeldung.com/java-hashset-arraylist-contains-performance) - [Fail-Safe Iterator vs Fail-Fast Iterator](https://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator) - [Quick Guide to the Java Stack](https://www.baeldung.com/java-stack) +- [Convert an Array of Primitives to a List](https://www.baeldung.com/java-primitive-array-to-list) From 19a50da589b381ed9311c4d2980fe94b77967367 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:48:24 +0800 Subject: [PATCH 111/309] Update README.md --- core-java-modules/core-java-jvm-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-jvm-2/README.md b/core-java-modules/core-java-jvm-2/README.md index 7a189ceec5..7206a9eef7 100644 --- a/core-java-modules/core-java-jvm-2/README.md +++ b/core-java-modules/core-java-jvm-2/README.md @@ -9,4 +9,5 @@ This module contains articles about working with the Java Virtual Machine (JVM). - [Adding Shutdown Hooks for JVM Applications](https://www.baeldung.com/jvm-shutdown-hooks) - [boolean and boolean[] Memory Layout in the JVM](https://www.baeldung.com/jvm-boolean-memory-layout) - [Where Is the Array Length Stored in JVM?](https://www.baeldung.com/java-jvm-array-length) +- [Memory Address of Objects in Java](https://www.baeldung.com/java-object-memory-address) - More articles: [[<-- prev]](/core-java-modules/core-java-jvm) From 95c6b906211f862c762810eb72ee4719373ddf42 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:57:49 +0800 Subject: [PATCH 112/309] Update README.md --- algorithms-miscellaneous-6/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/algorithms-miscellaneous-6/README.md b/algorithms-miscellaneous-6/README.md index 6e435e3741..6ddae75f43 100644 --- a/algorithms-miscellaneous-6/README.md +++ b/algorithms-miscellaneous-6/README.md @@ -8,4 +8,5 @@ - [Introduction to Greedy Algorithms with Java](https://www.baeldung.com/java-greedy-algorithms) - [The Caesar Cipher in Java](https://www.baeldung.com/java-caesar-cipher) - [Implementing a 2048 Solver in Java](https://www.baeldung.com/2048-java-solver) +- [Finding Top K Elements in an Array](https://www.baeldung.com/java-array-top-elements) - More articles: [[<-- prev]](/../algorithms-miscellaneous-5) From af79698c0bc19d157d7d0c69f4f35182e0554af3 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:02:12 +0800 Subject: [PATCH 113/309] Update README.md --- patterns/solid/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/patterns/solid/README.md b/patterns/solid/README.md index f5146732a0..41e986f544 100644 --- a/patterns/solid/README.md +++ b/patterns/solid/README.md @@ -3,3 +3,4 @@ - [A Solid Guide to Solid Principles](https://www.baeldung.com/solid-principles) - [Single Responsibility Principle in Java](https://www.baeldung.com/java-single-responsibility-principle) - [Open/Closed Principle in Java](https://www.baeldung.com/java-open-closed-principle) +- [Interface Segregation Principle in Java](https://www.baeldung.com/java-interface-segregation) From 66ac0239bd165bfdacd7da1ff7d3b0264701e393 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:04:14 +0800 Subject: [PATCH 114/309] Update README.md --- persistence-modules/core-java-persistence/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/persistence-modules/core-java-persistence/README.md b/persistence-modules/core-java-persistence/README.md index 88442a94c8..a760489480 100644 --- a/persistence-modules/core-java-persistence/README.md +++ b/persistence-modules/core-java-persistence/README.md @@ -3,6 +3,7 @@ ## Core Java Persistence Examples ### Relevant Articles: + - [Introduction to JDBC](http://www.baeldung.com/java-jdbc) - [Batch Processing in JDBC](http://www.baeldung.com/jdbc-batch-processing) - [Introduction to the JDBC RowSet Interface in Java](http://www.baeldung.com/java-jdbc-rowset) @@ -11,3 +12,4 @@ - [Types of SQL Joins](https://www.baeldung.com/sql-joins) - [Returning the Generated Keys in JDBC](https://www.baeldung.com/jdbc-returning-generated-keys) - [Loading JDBC Drivers](https://www.baeldung.com/java-jdbc-loading-drivers) +- [Difference Between Statement and PreparedStatement](https://www.baeldung.com/java-statement-preparedstatement) From daae6b63eecca1b7929fcf5ebd7f295bc36245fc Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:06:39 +0800 Subject: [PATCH 115/309] Update README.md --- spring-core-4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-core-4/README.md b/spring-core-4/README.md index 706c330f39..83b5c4933d 100644 --- a/spring-core-4/README.md +++ b/spring-core-4/README.md @@ -11,4 +11,5 @@ This module contains articles about core Spring functionality - [Using @Autowired in Abstract Classes](https://www.baeldung.com/spring-autowired-abstract-class) - [Running Setup Data on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) - [Constructor Injection in Spring with Lombok](https://www.baeldung.com/spring-injection-lombok) +- [The Spring ApplicationContext](https://www.baeldung.com/spring-application-context) - More articles: [[<-- prev]](/spring-core-3) From 6427ac176edd94377058d01d97283917e3f88289 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:10:10 +0800 Subject: [PATCH 116/309] Update README.md --- jmh/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jmh/README.md b/jmh/README.md index 3a5370c9f2..41bf16d6bb 100644 --- a/jmh/README.md +++ b/jmh/README.md @@ -5,4 +5,4 @@ This module contains articles about the Java Microbenchmark Harness (JMH). ### Relevant articles: - [Microbenchmarking with Java](https://www.baeldung.com/java-microbenchmark-harness) - +- [A Guide to False Sharing and @Contended](https://www.baeldung.com/java-false-sharing-contended) From cb9e7920a0651cd7c0dc3f5a6e0f92b4ce0fb17a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:11:49 +0800 Subject: [PATCH 117/309] Update README.md --- testing-modules/testing-libraries/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/testing-libraries/README.md b/testing-modules/testing-libraries/README.md index b1e1575e63..4db7fb8e7a 100644 --- a/testing-modules/testing-libraries/README.md +++ b/testing-modules/testing-libraries/README.md @@ -10,3 +10,4 @@ - [Cucumber Data Tables](https://www.baeldung.com/cucumber-data-tables) - [Cucumber Background](https://www.baeldung.com/java-cucumber-background) - [Cucumber Hooks](https://www.baeldung.com/java-cucumber-hooks) +- [Unit Testing of System.out.println() with JUnit](https://www.baeldung.com/java-testing-system-out-println) From 77f89e8b5b9f49bc4e9acbd4cbf8a6306d123aa8 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:17:28 +0800 Subject: [PATCH 118/309] Update README.md --- maven-modules/maven-properties/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-modules/maven-properties/README.md b/maven-modules/maven-properties/README.md index 65d976189c..52ac8506b3 100644 --- a/maven-modules/maven-properties/README.md +++ b/maven-modules/maven-properties/README.md @@ -5,4 +5,4 @@ have their own dedicated modules. ### Relevant Articles -- [Accessing Maven Properties in Java] \ No newline at end of file +- [Accessing Maven Properties in Java](https://www.baeldung.com/java-accessing-maven-properties) From 43d6584d8bb50d6937fdf9e0cb27fca9bab963a6 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:19:29 +0800 Subject: [PATCH 119/309] Update README.md --- core-java-modules/core-java-io-3/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java-modules/core-java-io-3/README.md b/core-java-modules/core-java-io-3/README.md index 39752346d3..61a040c1ce 100644 --- a/core-java-modules/core-java-io-3/README.md +++ b/core-java-modules/core-java-io-3/README.md @@ -3,5 +3,7 @@ This module contains articles about core Java input and output (IO) ### Relevant Articles: + - [Java – Create a File](https://www.baeldung.com/java-how-to-create-a-file) +- [Check If a Directory Is Empty in Java](https://www.baeldung.com/java-check-empty-directory) - [[<-- Prev]](/core-java-modules/core-java-io-2) From 06a10e83536d815e2775944a11780051a8d2dcaf Mon Sep 17 00:00:00 2001 From: helga_sh Date: Thu, 23 Jul 2020 17:33:06 +0300 Subject: [PATCH 120/309] CNN example with Deeplearning4j in Java: add missing letter in pom --- deeplearning4j/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeplearning4j/pom.xml b/deeplearning4j/pom.xml index e1e4998c98..8ec335b184 100644 --- a/deeplearning4j/pom.xml +++ b/deeplearning4j/pom.xml @@ -63,7 +63,7 @@ 0.9.1 4.3.5 - 1.7.5 + 1.7.5 From c67658322b281f5eff5ff9b7556f0119df607b20 Mon Sep 17 00:00:00 2001 From: helga_sh Date: Thu, 23 Jul 2020 17:33:31 +0300 Subject: [PATCH 121/309] CNN example with Deeplearning4j in Java: add missing letter in pom --- deeplearning4j/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deeplearning4j/pom.xml b/deeplearning4j/pom.xml index 8ec335b184..af65aa7e03 100644 --- a/deeplearning4j/pom.xml +++ b/deeplearning4j/pom.xml @@ -40,12 +40,12 @@ org.slf4j slf4j-api - ${sl4j.version} + ${slf4j.version} org.slf4j slf4j-log4j12 - ${sl4j.version} + ${slf4j.version} From 9af44b328372b1d33474feaa2a46dc6092500f19 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:41:33 +0800 Subject: [PATCH 122/309] Update README.md --- core-kotlin-modules/core-kotlin-collections/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-kotlin-modules/core-kotlin-collections/README.md b/core-kotlin-modules/core-kotlin-collections/README.md index dcf2743577..2ebb748cba 100644 --- a/core-kotlin-modules/core-kotlin-collections/README.md +++ b/core-kotlin-modules/core-kotlin-collections/README.md @@ -3,6 +3,7 @@ This module contains articles about core Kotlin collections. ### Relevant articles: + - [Split a List Into Parts in Kotlin](https://www.baeldung.com/kotlin-split-list-into-parts) - [Finding an Element in a List Using Kotlin](https://www.baeldung.com/kotlin-finding-element-in-list) - [Overview of Kotlin Collections API](https://www.baeldung.com/kotlin-collections-api) @@ -12,3 +13,4 @@ This module contains articles about core Kotlin collections. - [Difference between fold and reduce in Kotlin](https://www.baeldung.com/kotlin/fold-vs-reduce) - [Guide to Sorting in Kotlin](https://www.baeldung.com/kotlin-sort) - [Working With Lists in Kotlin](https://www.baeldung.com/kotlin/lists) +- [Iterating Collections by Index in Kotlin](https://www.baeldung.com/kotlin/iterating-collections-by-index) From 04d72f9b0bbc064f69cf95a065c5c442d4578a94 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:42:52 +0800 Subject: [PATCH 123/309] Update README.md --- core-kotlin-modules/core-kotlin-lang-oop-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/README.md b/core-kotlin-modules/core-kotlin-lang-oop-2/README.md index 27536273dc..a62a25c01d 100644 --- a/core-kotlin-modules/core-kotlin-lang-oop-2/README.md +++ b/core-kotlin-modules/core-kotlin-lang-oop-2/README.md @@ -7,4 +7,5 @@ This module contains articles about Object-Oriented Programming in Kotlin - [Generics in Kotlin](https://www.baeldung.com/kotlin-generics) - [Delegated Properties in Kotlin](https://www.baeldung.com/kotlin-delegated-properties) - [Delegation Pattern in Kotlin](https://www.baeldung.com/kotlin-delegation-pattern) +- [Anonymous Inner Classes in Kotlin](https://www.baeldung.com/kotlin/anonymous-inner-classes) - [[<-- Prev]](/core-kotlin-modules/core-kotlin-lang-oop) From 2127c7935452ca7556b65f913c598bcf36513f24 Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Thu, 23 Jul 2020 19:00:08 +0200 Subject: [PATCH 124/309] BAEL-4289 --- .../baeldung/screenshot/ScreenshotTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java new file mode 100644 index 0000000000..3df31897e1 --- /dev/null +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java @@ -0,0 +1,54 @@ +import javax.imageio.ImageIO; +import java.awt.Component; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.image.BufferedImage; +import java.io.File; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class ScreenshotTest { + + @Test + public void takeScreenshotOfMainScreen() throws Exception { + Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); + BufferedImage capture = new Robot().createScreenCapture(screenRect); + File imageFile = new File("single-screen.bmp"); + ImageIO.write(capture, "bmp", imageFile); + assertTrue(imageFile.exists()); + imageFile.delete(); + } + + @Test + public void takeScreenshotOfAllScreens() throws Exception { + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] screens = ge.getScreenDevices(); + Rectangle allScreenBounds = new Rectangle(); + for (GraphicsDevice screen : screens) { + Rectangle screenBounds = screen.getDefaultConfiguration().getBounds(); + allScreenBounds.width += screenBounds.width; + allScreenBounds.height = Math.max(allScreenBounds.height, screenBounds.height); + } + BufferedImage capture = new Robot().createScreenCapture(allScreenBounds); + File imageFile = new File("all-screens.bmp"); + ImageIO.write(capture, "bmp", imageFile); + assertTrue(imageFile.exists()); + imageFile.delete(); + } + + @Test + public void makeScreenshot(Component component) throws Exception { + Rectangle componentRect = component.getBounds(); + BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB); + component.paint(bufferedImage.getGraphics()); + File imageFile = new File("component-screenshot.bmp"); + ImageIO.write(bufferedImage, "bmp", imageFile); + assertTrue(imageFile.exists()); + imageFile.delete(); + } + +} \ No newline at end of file From 9c0eba409e86db1e7b609bb53db075b914cd5ec6 Mon Sep 17 00:00:00 2001 From: mdabrowski-eu Date: Thu, 23 Jul 2020 19:29:59 +0200 Subject: [PATCH 125/309] BAEL-4405 Probability in Java --- .../probability/MaleHeightGenerator.java | 17 +++++++++++++ .../baeldung/probability/RandomInvoker.java | 19 +++++++++++++++ .../probability/RandomInvokerUnitTest.java | 24 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 java-numbers-3/src/main/java/com/baeldung/probability/MaleHeightGenerator.java create mode 100644 java-numbers-3/src/main/java/com/baeldung/probability/RandomInvoker.java create mode 100644 java-numbers-3/src/test/java/com/baeldung/probability/RandomInvokerUnitTest.java diff --git a/java-numbers-3/src/main/java/com/baeldung/probability/MaleHeightGenerator.java b/java-numbers-3/src/main/java/com/baeldung/probability/MaleHeightGenerator.java new file mode 100644 index 0000000000..ed3fb8a578 --- /dev/null +++ b/java-numbers-3/src/main/java/com/baeldung/probability/MaleHeightGenerator.java @@ -0,0 +1,17 @@ +package com.baeldung.probability; + +import org.apache.commons.math3.distribution.NormalDistribution; + +public class MaleHeightGenerator { + private static final double MEAN_HEIGHT = 176.02; + private static final double STANDARD_DEVIATION = 7.11; + private static NormalDistribution distribution = new NormalDistribution(MEAN_HEIGHT, STANDARD_DEVIATION); + + public static double generateNormalHeight() { + return distribution.sample(); + } + + public static double probabilityOfHeightBetween(double heightLowerExclusive, double heightUpperInclusive) { + return distribution.probability(heightLowerExclusive, heightUpperInclusive); + } +} diff --git a/java-numbers-3/src/main/java/com/baeldung/probability/RandomInvoker.java b/java-numbers-3/src/main/java/com/baeldung/probability/RandomInvoker.java new file mode 100644 index 0000000000..30be5725ab --- /dev/null +++ b/java-numbers-3/src/main/java/com/baeldung/probability/RandomInvoker.java @@ -0,0 +1,19 @@ +package com.baeldung.probability; + +import io.vavr.Lazy; + +import java.util.SplittableRandom; +import java.util.function.Supplier; + +public class RandomInvoker { + private final Lazy random = Lazy.of(SplittableRandom::new); + + public T withProbability(Supplier supplier1, Supplier supplier2, int probability) { + SplittableRandom random = this.random.get(); + if (random.nextInt(1, 101) <= probability) { + return supplier1.get(); + } else { + return supplier2.get(); + } + } +} diff --git a/java-numbers-3/src/test/java/com/baeldung/probability/RandomInvokerUnitTest.java b/java-numbers-3/src/test/java/com/baeldung/probability/RandomInvokerUnitTest.java new file mode 100644 index 0000000000..b08c086e30 --- /dev/null +++ b/java-numbers-3/src/test/java/com/baeldung/probability/RandomInvokerUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.probability; + +import org.assertj.core.data.Offset; +import org.junit.Test; + +import java.util.stream.Stream; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RandomInvokerUnitTest { + @Test + public void givenProbability_whenInvoked_invokeWithProbability() { + RandomInvoker randomInvoker = new RandomInvoker(); + + int numberOfSamples = 1_000_000; + int probability = 10; + int howManyTimesInvoked = Stream.generate(() -> randomInvoker.withProbability(() -> 1, () -> 0, probability)) + .limit(numberOfSamples) + .mapToInt(e -> e).sum(); + int monteCarloProbability = (howManyTimesInvoked * 100) / numberOfSamples; + + assertThat(monteCarloProbability).isCloseTo(probability, Offset.offset(1)); + } +} From c4770ac40f83ee773426004fd8a4168b57a37aa5 Mon Sep 17 00:00:00 2001 From: karan Date: Fri, 24 Jul 2020 01:08:45 -0400 Subject: [PATCH 126/309] add another defaultpathvariable method --- .../pathvariable/PathVariableAnnotationController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java b/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java index 624ba2d105..37e104f354 100644 --- a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java +++ b/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java @@ -66,6 +66,16 @@ public class PathVariableAnnotationController { } } + @GetMapping(value = { "/api/defaultemployeeswithoptional", "/api/defaultemployeeswithoptional/{id}" }) + @ResponseBody + public String getDefaultEmployeesByIdWithOptional(@PathVariable Optional id) { + if (id.isPresent()) { + return "ID: " + id.get(); + } else { + return "ID: Default Employee"; + } + } + @GetMapping(value = { "/api/employeeswithmap/{id}", "/api/employeeswithmap" }) @ResponseBody public String getEmployeesByIdWithMap(@PathVariable Map pathVarsMap) { From 9057d216f25eeee3dccf7c839ba212bd480136f0 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Fri, 24 Jul 2020 13:24:43 +0800 Subject: [PATCH 127/309] Update README.md --- core-java-modules/core-java-security-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md index 24a821bd4d..ba8cce46a0 100644 --- a/core-java-modules/core-java-security-2/README.md +++ b/core-java-modules/core-java-security-2/README.md @@ -9,4 +9,5 @@ This module contains articles about core Java Security - [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing) - [SHA-256 and SHA3-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java) - [Checksums in Java](https://www.baeldung.com/java-checksums) +- [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys) - More articles: [[<-- prev]](/core-java-modules/core-java-security) From b1a9ee6282ff3f4661b415325880568d293d67c0 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Fri, 24 Jul 2020 13:26:05 +0800 Subject: [PATCH 128/309] Update README.md --- libraries-security/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-security/README.md b/libraries-security/README.md index 580ebdeab0..5ec85a15e9 100644 --- a/libraries-security/README.md +++ b/libraries-security/README.md @@ -10,3 +10,4 @@ This module contains articles about security libraries. - [Introduction to BouncyCastle with Java](https://www.baeldung.com/java-bouncy-castle) - [Intro to Jasypt](https://www.baeldung.com/jasypt) - [Digital Signatures in Java](https://www.baeldung.com/java-digital-signature) +- [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys) From 41c8fa83ef69a11fa8d5ba63d03e1cd6e0a6e825 Mon Sep 17 00:00:00 2001 From: rdevarakonda Date: Sat, 25 Jul 2020 10:43:52 +0100 Subject: [PATCH 129/309] BAEL-4006 | Liskov Substitution Principle in Java (#9431) * BAEL-4006 | Liskov Substitution Principle in Java * BAEL-4006 | UNDO unintentional commit to pom.xml * BAEL-4006 | Code review feedback implementation * BAEL-4006 | Changes made to support the article review feedback implementation * BAEL-4006 | Minor change to a comment --- .../java/com/baeldung/l/advanced/Account.java | 17 +++++++++++ .../advanced/BankingAppWithdrawalService.java | 15 ++++++++++ .../java/com/baeldung/l/advanced/Bar.java | 27 ++++++++++++++++++ .../java/com/baeldung/l/advanced/Car.java | 26 +++++++++++++++++ .../baeldung/l/advanced/CurrentAccount.java | 15 ++++++++++ .../com/baeldung/l/advanced/ElectricCar.java | 23 +++++++++++++++ .../baeldung/l/advanced/FilePurgingJob.java | 18 ++++++++++++ .../com/baeldung/l/advanced/FileSystem.java | 10 +++++++ .../l/advanced/FixedTermDepositAccount.java | 15 ++++++++++ .../java/com/baeldung/l/advanced/Foo.java | 22 +++++++++++++++ .../com/baeldung/l/advanced/HybridCar.java | 28 +++++++++++++++++++ .../com/baeldung/l/advanced/MotorCar.java | 25 +++++++++++++++++ .../l/advanced/ReadOnlyFileSystem.java | 16 +++++++++++ .../baeldung/l/advanced/SavingsAccount.java | 15 ++++++++++ .../java/com/baeldung/l/advanced/ToyCar.java | 24 ++++++++++++++++ .../l/advanced/refactored/Account.java | 7 +++++ .../BankingAppWithdrawalService.java | 17 +++++++++++ .../l/advanced/refactored/CurrentAccount.java | 13 +++++++++ .../refactored/FixedTermDepositAccount.java | 9 ++++++ .../l/advanced/refactored/SavingsAccount.java | 13 +++++++++ .../refactored/WithdrawableAccount.java | 14 ++++++++++ 21 files changed, 369 insertions(+) create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/Account.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/BankingAppWithdrawalService.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/Bar.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/Car.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/CurrentAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/ElectricCar.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/FilePurgingJob.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/FileSystem.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/FixedTermDepositAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/Foo.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/HybridCar.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/MotorCar.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/ReadOnlyFileSystem.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/SavingsAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/ToyCar.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/Account.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/BankingAppWithdrawalService.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/CurrentAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/FixedTermDepositAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/SavingsAccount.java create mode 100644 patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/WithdrawableAccount.java diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/Account.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/Account.java new file mode 100644 index 0000000000..3a8260924b --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/Account.java @@ -0,0 +1,17 @@ +package com.baeldung.l.advanced; + +import java.math.BigDecimal; + +public abstract class Account { + protected abstract void deposit(BigDecimal amount); + + /** + * Reduces the account balance by the specified amount + * provided given amount > 0 and account meets minimum available + * balance criteria. + * + * @param amount + */ + protected abstract void withdraw(BigDecimal amount); + +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/BankingAppWithdrawalService.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/BankingAppWithdrawalService.java new file mode 100644 index 0000000000..6689b1dc8c --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/BankingAppWithdrawalService.java @@ -0,0 +1,15 @@ +package com.baeldung.l.advanced; + +import java.math.BigDecimal; + +public class BankingAppWithdrawalService { + private Account account; + + public BankingAppWithdrawalService(Account account) { + this.account = account; + } + + public void withdraw(BigDecimal amount) { + account.withdraw(amount); + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/Bar.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/Bar.java new file mode 100644 index 0000000000..8f421cebaa --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/Bar.java @@ -0,0 +1,27 @@ +package com.baeldung.l.advanced; + +public class Bar extends Foo { + + @Override + // precondition: 0 < num <= 10 + public void doStuff(int num) { + if (num <= 0 || num > 10) { + throw new IllegalArgumentException("Input out of range 1-10"); + } + // some logic here... + } + + @Override + // precondition: 0 < num <= 3 + public void doOtherStuff(int num) { + if (num <= 0 || num > 3) { + throw new IllegalArgumentException("Input out of range 1-3"); + } + // some logic here... + } + + @Override + public Integer generateNumber() { + return new Integer(10); + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/Car.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/Car.java new file mode 100644 index 0000000000..48688d9a45 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/Car.java @@ -0,0 +1,26 @@ +package com.baeldung.l.advanced; + +public abstract class Car { + protected int limit; + + // invariant: speed < limit; + protected int speed; + + // Allowed to be set once at the time of creation. + // Value can only increment thereafter. + // Value cannot be reset. + protected int mileage; + + public Car(int mileage) { + this.mileage = mileage; + } + + protected abstract void turnOnEngine(); + + // postcondition: speed < limit + protected abstract void accelerate(); + + // postcondition: speed must reduce + protected abstract void brake(); + +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/CurrentAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/CurrentAccount.java new file mode 100644 index 0000000000..7187582126 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/CurrentAccount.java @@ -0,0 +1,15 @@ +package com.baeldung.l.advanced; + +import java.math.BigDecimal; + +public class CurrentAccount extends Account { + @Override + protected void deposit(BigDecimal amount) { + // Deposit into CurrentAccount + } + + @Override + protected void withdraw(BigDecimal amount) { + // Withdraw from CurrentAccount + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/ElectricCar.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/ElectricCar.java new file mode 100644 index 0000000000..ca78af633f --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/ElectricCar.java @@ -0,0 +1,23 @@ +package com.baeldung.l.advanced; + +public class ElectricCar extends Car { + + public ElectricCar(int mileage) { + super(mileage); + } + + @Override + protected void turnOnEngine() { + throw new AssertionError("I am an Electric Car. I don't have an engine!"); + } + + @Override + protected void accelerate() { + // this acceleration is crazy! + } + + @Override + protected void brake() { + // Apply ElectricCar brake + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/FilePurgingJob.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/FilePurgingJob.java new file mode 100644 index 0000000000..57334696b0 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/FilePurgingJob.java @@ -0,0 +1,18 @@ +package com.baeldung.l.advanced; + +import java.io.IOException; + +public class FilePurgingJob { + private FileSystem fileSystem; + + public FilePurgingJob(FileSystem fileSystem) { + this.fileSystem = fileSystem; + } + + public void purgeOldestFile(String path) throws IOException { + if (!(fileSystem instanceof ReadOnlyFileSystem)) { + // code to detect oldest file + fileSystem.deleteFile(path); + } + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/FileSystem.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/FileSystem.java new file mode 100644 index 0000000000..00a8fb8ec7 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/FileSystem.java @@ -0,0 +1,10 @@ +package com.baeldung.l.advanced; + +import java.io.File; +import java.io.IOException; + +public interface FileSystem { + File[] listFiles(String path); + + void deleteFile(String path) throws IOException; +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/FixedTermDepositAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/FixedTermDepositAccount.java new file mode 100644 index 0000000000..50dd4f3d17 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/FixedTermDepositAccount.java @@ -0,0 +1,15 @@ +package com.baeldung.l.advanced; + +import java.math.BigDecimal; + +public class FixedTermDepositAccount extends Account { + @Override + protected void deposit(BigDecimal amount) { + // Deposit into this account + } + + @Override + protected void withdraw(BigDecimal amount) { + throw new UnsupportedOperationException("Withdrawals are not supported by FixedTermDepositAccount!!"); + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/Foo.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/Foo.java new file mode 100644 index 0000000000..f61577c18f --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/Foo.java @@ -0,0 +1,22 @@ +package com.baeldung.l.advanced; + +public abstract class Foo { + + // precondition: 0 < num <=5 + public void doStuff(int num) { + if (num <= 0 || num > 5) { + throw new IllegalArgumentException("Input out of range 1-5"); + } + // some logic here... + } + + // precondition: 0 < num <=5 + public void doOtherStuff(int num) { + if (num <= 0 || num > 5) { + throw new IllegalArgumentException("Input out of range 1-5"); + } + // some logic here... + } + + public abstract Number generateNumber(); +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/HybridCar.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/HybridCar.java new file mode 100644 index 0000000000..ea643a7419 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/HybridCar.java @@ -0,0 +1,28 @@ +package com.baeldung.l.advanced; + +public class HybridCar extends Car { + // invariant: charge >= 0; + private int charge; + + public HybridCar(int mileage) { + super(mileage); + } + + @Override + protected void turnOnEngine() { + // Start HybridCar + } + + @Override + // postcondition: speed < limit + protected void accelerate() { + // Accelerate HybridCar speed < limit + } + + @Override + // postcondition: speed must reduce + // postcondition: charge must increase + protected void brake() { + // Apply HybridCar brake + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/MotorCar.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/MotorCar.java new file mode 100644 index 0000000000..68a54966cc --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/MotorCar.java @@ -0,0 +1,25 @@ +package com.baeldung.l.advanced; + +public class MotorCar extends Car { + + public MotorCar(int mileage) { + super(mileage); + } + + @Override + protected void turnOnEngine() { + // Start MotorCar + } + + @Override + // postcondition: speed < limit + protected void accelerate() { + // Accelerate MotorCar + } + + @Override + // postcondition: speed must reduce + protected void brake() { + // Apply MotorCar brake + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/ReadOnlyFileSystem.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/ReadOnlyFileSystem.java new file mode 100644 index 0000000000..6ba3d9770d --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/ReadOnlyFileSystem.java @@ -0,0 +1,16 @@ +package com.baeldung.l.advanced; + +import java.io.File; +import java.io.IOException; + +public class ReadOnlyFileSystem implements FileSystem { + public File[] listFiles(String path) { + // code to list files + return new File[0]; + } + + public void deleteFile(String path) throws IOException { + // Do nothing. + // deleteFile operation is not supported on a read-only file system + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/SavingsAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/SavingsAccount.java new file mode 100644 index 0000000000..8dbb5eb4d4 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/SavingsAccount.java @@ -0,0 +1,15 @@ +package com.baeldung.l.advanced; + +import java.math.BigDecimal; + +public class SavingsAccount extends Account { + @Override + protected void deposit(BigDecimal amount) { + // Deposit into SavingsAccount + } + + @Override + protected void withdraw(BigDecimal amount) { + // Withdraw from SavingsAccount + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/ToyCar.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/ToyCar.java new file mode 100644 index 0000000000..a41694deef --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/ToyCar.java @@ -0,0 +1,24 @@ +package com.baeldung.l.advanced; + +public class ToyCar extends Car { + + public ToyCar(int mileage) { + super(mileage); + } + + protected void turnOnEngine() { + + } + + protected void accelerate() { + + } + + protected void brake() { + + } + + public void reset() { + mileage = 0; + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/Account.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/Account.java new file mode 100644 index 0000000000..cb950df164 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/Account.java @@ -0,0 +1,7 @@ +package com.baeldung.l.advanced.refactored; + +import java.math.BigDecimal; + +public abstract class Account { + protected abstract void deposit(BigDecimal amount); +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/BankingAppWithdrawalService.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/BankingAppWithdrawalService.java new file mode 100644 index 0000000000..cbb375dd52 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/BankingAppWithdrawalService.java @@ -0,0 +1,17 @@ +package com.baeldung.l.advanced.refactored; + +import com.baeldung.l.advanced.Account; + +import java.math.BigDecimal; + +public class BankingAppWithdrawalService { + private WithdrawableAccount withdrawableAccount; + + public BankingAppWithdrawalService(WithdrawableAccount withdrawableAccount) { + this.withdrawableAccount = withdrawableAccount; + } + + public void withdraw(BigDecimal amount) { + withdrawableAccount.withdraw(amount); + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/CurrentAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/CurrentAccount.java new file mode 100644 index 0000000000..5b5b9efe04 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/CurrentAccount.java @@ -0,0 +1,13 @@ +package com.baeldung.l.advanced.refactored; + +import java.math.BigDecimal; + +public class CurrentAccount extends WithdrawableAccount { + protected void deposit(BigDecimal amount) { + // Deposit into CurrentAccount + } + + protected void withdraw(BigDecimal amount) { + // Withdraw from CurrentAccount + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/FixedTermDepositAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/FixedTermDepositAccount.java new file mode 100644 index 0000000000..14461b85a3 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/FixedTermDepositAccount.java @@ -0,0 +1,9 @@ +package com.baeldung.l.advanced.refactored; + +import java.math.BigDecimal; + +public class FixedTermDepositAccount extends Account { + protected void deposit(BigDecimal amount) { + // Deposit into this account + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/SavingsAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/SavingsAccount.java new file mode 100644 index 0000000000..45c50079bf --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/SavingsAccount.java @@ -0,0 +1,13 @@ +package com.baeldung.l.advanced.refactored; + +import java.math.BigDecimal; + +public class SavingsAccount extends WithdrawableAccount { + protected void deposit(BigDecimal amount) { + // Deposit into SavingsAccount + } + + protected void withdraw(BigDecimal amount) { + // Withdraw from SavingsAccount + } +} diff --git a/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/WithdrawableAccount.java b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/WithdrawableAccount.java new file mode 100644 index 0000000000..b3c7606cb7 --- /dev/null +++ b/patterns/solid/src/main/java/com/baeldung/l/advanced/refactored/WithdrawableAccount.java @@ -0,0 +1,14 @@ +package com.baeldung.l.advanced.refactored; + +import java.math.BigDecimal; + +public abstract class WithdrawableAccount extends Account { + /** + * Reduces the account balance by the specified amount + * provided given amount > 0 and account meets minimum available + * balance criteria. + * + * @param amount + */ + protected abstract void withdraw(BigDecimal amount); +} From 4128525f001c44f716d67971e3a6ff746a6cd7b0 Mon Sep 17 00:00:00 2001 From: Roger <587230+rojyates@users.noreply.github.com> Date: Sat, 25 Jul 2020 23:45:41 +1000 Subject: [PATCH 130/309] BAEL-1258 Added example code for Jess and JSR94 (#9693) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * BAEL-1258 Added example code for Jess and JSR94 * BAEL-1258 Relocate to rule-modules * BAEL-1258 Remove README as per PR review * šBAEL-1258 Declared exceptions and replace System.out.println with log statements * BAEL-1258 Removed Lombok * BAEL-1258 Removed Lombok * BAEL-1258 Rename artifactId to match directory name --- rule-engines/jess/pom.xml | 25 +++++ .../com/baeldung/rules/jess/JessHello.java | 17 ++++ .../com/baeldung/rules/jess/JessWithData.java | 42 ++++++++ .../baeldung/rules/jess/JessWithJsr94.java | 98 +++++++++++++++++++ .../com/baeldung/rules/jess/model/Answer.java | 31 ++++++ .../baeldung/rules/jess/model/Question.java | 32 ++++++ .../jess/src/main/resources/bonus.clp | 8 ++ .../jess/src/main/resources/helloJess.clp | 3 + 8 files changed, 256 insertions(+) create mode 100644 rule-engines/jess/pom.xml create mode 100644 rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessHello.java create mode 100644 rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithData.java create mode 100644 rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithJsr94.java create mode 100644 rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Answer.java create mode 100644 rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Question.java create mode 100644 rule-engines/jess/src/main/resources/bonus.clp create mode 100644 rule-engines/jess/src/main/resources/helloJess.clp diff --git a/rule-engines/jess/pom.xml b/rule-engines/jess/pom.xml new file mode 100644 index 0000000000..40d50fae70 --- /dev/null +++ b/rule-engines/jess/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + com.baeldung.rules.jess + jess + 1.0-SNAPSHOT + + + + + jsr94 + jsr94 + 1.1 + + + gov.sandia + jess + 7.1p2 + + + + \ No newline at end of file diff --git a/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessHello.java b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessHello.java new file mode 100644 index 0000000000..1462996a4c --- /dev/null +++ b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessHello.java @@ -0,0 +1,17 @@ +package com.baeldung.rules.jess; + +import jess.JessException; +import jess.Rete; + +public class JessHello { + public static final String RULES_FILE = "helloJess.clp"; + + public static void main(String[] args) throws JessException { + Rete engine = new Rete(); + engine.reset(); + + engine.batch(RULES_FILE); + + engine.run(); + } +} diff --git a/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithData.java b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithData.java new file mode 100644 index 0000000000..5d5dc9b983 --- /dev/null +++ b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithData.java @@ -0,0 +1,42 @@ +package com.baeldung.rules.jess; + +import com.baeldung.rules.jess.model.Answer; +import com.baeldung.rules.jess.model.Question; +import jess.Filter; +import jess.JessException; +import jess.Rete; + +import java.util.Iterator; +import java.util.logging.Logger; + +public class JessWithData { + public static final String RULES_BONUS_FILE = "bonus.clp"; + private static Logger log = Logger.getLogger("JessWithData"); + + public static void main(String[] args) throws JessException { + Rete engine = new Rete(); + engine.reset(); + + engine.batch(RULES_BONUS_FILE); + + prepareData(engine); + + engine.run(); + + checkResults(engine); + } + + private static void checkResults(Rete engine) { + Iterator results = engine.getObjects(new Filter.ByClass(Answer.class)); + while (results.hasNext()) { + Answer answer = (Answer) results.next(); + log.info(answer.toString()); + } + } + + private static void prepareData(Rete engine) throws JessException { + Question question = new Question("Can I have a bonus?", -5); + log.info(question.toString()); + engine.add(question); + } +} diff --git a/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithJsr94.java b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithJsr94.java new file mode 100644 index 0000000000..f07bf10a7a --- /dev/null +++ b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/JessWithJsr94.java @@ -0,0 +1,98 @@ +package com.baeldung.rules.jess; + +import com.baeldung.rules.jess.model.Answer; +import com.baeldung.rules.jess.model.Question; + +import javax.rules.*; +import javax.rules.admin.RuleAdministrator; +import javax.rules.admin.RuleExecutionSet; +import javax.rules.admin.RuleExecutionSetCreateException; +import javax.rules.admin.RuleExecutionSetRegisterException; +import java.io.IOException; +import java.io.InputStream; +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.logging.Logger; + +public class JessWithJsr94 { + public static final String RULES_BONUS_FILE = "/bonus.clp"; + public static final String RULES_URI = "com/baeldung/rules/bonus"; + private static final String RULE_SERVICE_PROVIDER = "jess.jsr94"; + private static Logger log = Logger.getLogger("JessWithData"); + + public static void main(String[] args) throws Exception { + RuleServiceProvider ruleServiceProvider = instantiateJessInstance(); + + // load our rules and register them with the rules provider + registerRules(RULES_BONUS_FILE, RULES_URI, ruleServiceProvider); + + runRules(RULES_URI, ruleServiceProvider); + } + + private static RuleServiceProvider instantiateJessInstance() throws ClassNotFoundException, ConfigurationException { + // Load the rule service provider of the reference implementation. + // Loading this class will automatically register this provider with the provider manager. + Class.forName(RULE_SERVICE_PROVIDER + ".RuleServiceProviderImpl"); + + // Get the rule service provider from the provider manager. + return RuleServiceProviderManager.getRuleServiceProvider(RULE_SERVICE_PROVIDER); + } + + private static void runRules(String rulesURI, RuleServiceProvider ruleServiceProvider) + throws ConfigurationException, RuleSessionTypeUnsupportedException, RuleSessionCreateException, RuleExecutionSetNotFoundException, RemoteException, InvalidRuleSessionException { + // Get a RuleRuntime and invoke the rule engine. + RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime(); + + //Create a statelessRuleSession. + StatelessRuleSession statelessRuleSession = (StatelessRuleSession) ruleRuntime.createRuleSession(rulesURI, new HashMap(), RuleRuntime.STATELESS_SESSION_TYPE); + + calculateResults(statelessRuleSession); + + statelessRuleSession.release(); + } + + private static void calculateResults(StatelessRuleSession statelessRuleSession) throws InvalidRuleSessionException, RemoteException { + List data = prepareData(); + + // execute the rules + List results = statelessRuleSession.executeRules(data); + + checkResults(results); + } + + private static List prepareData() { + List data = new ArrayList(); + data.add(new Question("Can I have a bonus?", -5)); + return data; + } + + private static void checkResults(List results) { + Iterator itr = results.iterator(); + while (itr.hasNext()) { + Object obj = itr.next(); + if (obj instanceof Answer) { + log.info(obj.toString()); + } + } + } + + private static void registerRules(String rulesFile, String rulesURI, RuleServiceProvider serviceProvider) throws ConfigurationException, RuleExecutionSetCreateException, IOException, RuleExecutionSetRegisterException { + // Get the rule administrator. + RuleAdministrator ruleAdministrator = serviceProvider.getRuleAdministrator(); + + // load the rules + InputStream ruleInput = JessWithJsr94.class.getResourceAsStream(rulesFile); + HashMap vendorProperties = new HashMap(); + + // Create the RuleExecutionSet + RuleExecutionSet ruleExecutionSet = ruleAdministrator + .getLocalRuleExecutionSetProvider(vendorProperties) + .createRuleExecutionSet(ruleInput, vendorProperties); + + // Register the rule execution set. + ruleAdministrator.registerRuleExecutionSet(rulesURI, ruleExecutionSet, vendorProperties); + } +} \ No newline at end of file diff --git a/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Answer.java b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Answer.java new file mode 100644 index 0000000000..d690d04e13 --- /dev/null +++ b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Answer.java @@ -0,0 +1,31 @@ +package com.baeldung.rules.jess.model; + +public class Answer { + private String answer; + private int newBalance; + + public Answer(String answer, int newBalance) { + this.answer = answer; + this.newBalance = newBalance; + } + + public int getNewBalance() { + return newBalance; + } + + public void setNewBalance(int newBalance) { + this.newBalance = newBalance; + } + + public String getAnswer() { + return answer; + } + + public void setAnswer(String answer) { + this.answer = answer; + } + + public String toString() { + return "Answer(answer=" + answer + ", newBalance=" + newBalance + ")"; + } +} diff --git a/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Question.java b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Question.java new file mode 100644 index 0000000000..499113d0fc --- /dev/null +++ b/rule-engines/jess/src/main/java/com/baeldung/rules/jess/model/Question.java @@ -0,0 +1,32 @@ +package com.baeldung.rules.jess.model; + +public class Question { + private String question; + private int balance; + + public Question(String question, int balance) { + this.question = question; + this.balance = balance; + } + + public String getQuestion() { + return question; + } + + public void setQuestion(String question) { + this.question = question; + } + + public int getBalance() { + return balance; + } + + public void setBalance(int balance) { + this.balance = balance; + } + + public String toString() { + return "Question(question=" + question + ", balance=" + balance + ")"; + } + +} diff --git a/rule-engines/jess/src/main/resources/bonus.clp b/rule-engines/jess/src/main/resources/bonus.clp new file mode 100644 index 0000000000..7f430bc43f --- /dev/null +++ b/rule-engines/jess/src/main/resources/bonus.clp @@ -0,0 +1,8 @@ +(import com.baeldung.rules.jess.model.*) +(deftemplate Question (declare (from-class Question))) +(deftemplate Answer (declare (from-class Answer))) + +(defrule avoid-overdraft "Give $50 to anyone overdrawn" + ?q <- (Question { balance < 0 }) + => + (add (new Answer "Overdrawn bonus" (+ ?q.balance 50)))) diff --git a/rule-engines/jess/src/main/resources/helloJess.clp b/rule-engines/jess/src/main/resources/helloJess.clp new file mode 100644 index 0000000000..547294eca6 --- /dev/null +++ b/rule-engines/jess/src/main/resources/helloJess.clp @@ -0,0 +1,3 @@ +;; Hello, world in Jess! + +(printout t "Hello from Jess!" crlf) From d52bb494e113a545faaf657d81531ae6c9fa0f7e Mon Sep 17 00:00:00 2001 From: Jordan Simpson Date: Sat, 25 Jul 2020 11:41:20 -0500 Subject: [PATCH 131/309] Added project hierarchy to exemplify the tag. --- maven-modules/optional-dependencies/README.md | 3 +++ .../main-project/pom.xml | 18 ++++++++++++++++++ .../optional-project/pom.xml | 10 ++++++++++ maven-modules/optional-dependencies/pom.xml | 18 ++++++++++++++++++ .../project-with-optionals/pom.xml | 19 +++++++++++++++++++ maven-modules/pom.xml | 1 + 6 files changed, 69 insertions(+) create mode 100644 maven-modules/optional-dependencies/README.md create mode 100644 maven-modules/optional-dependencies/main-project/pom.xml create mode 100644 maven-modules/optional-dependencies/optional-project/pom.xml create mode 100644 maven-modules/optional-dependencies/pom.xml create mode 100644 maven-modules/optional-dependencies/project-with-optionals/pom.xml diff --git a/maven-modules/optional-dependencies/README.md b/maven-modules/optional-dependencies/README.md new file mode 100644 index 0000000000..6b4d3e7647 --- /dev/null +++ b/maven-modules/optional-dependencies/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- Optional Dependency in Maven \ No newline at end of file diff --git a/maven-modules/optional-dependencies/main-project/pom.xml b/maven-modules/optional-dependencies/main-project/pom.xml new file mode 100644 index 0000000000..6a42683779 --- /dev/null +++ b/maven-modules/optional-dependencies/main-project/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + com.baeldung + main-project + 0.0.1-SNAPSHOT + pom + + + + com.baeldung + project-with-optionals + 0.0.1-SNAPSHOT + + + \ No newline at end of file diff --git a/maven-modules/optional-dependencies/optional-project/pom.xml b/maven-modules/optional-dependencies/optional-project/pom.xml new file mode 100644 index 0000000000..9ad4376c8d --- /dev/null +++ b/maven-modules/optional-dependencies/optional-project/pom.xml @@ -0,0 +1,10 @@ + + + 4.0.0 + com.baeldung + optional-project + 0.0.1-SNAPSHOT + pom + \ No newline at end of file diff --git a/maven-modules/optional-dependencies/pom.xml b/maven-modules/optional-dependencies/pom.xml new file mode 100644 index 0000000000..c1bfc6fb59 --- /dev/null +++ b/maven-modules/optional-dependencies/pom.xml @@ -0,0 +1,18 @@ + + + + maven-modules + com.baeldung + 0.0.1-SNAPSHOT + + 4.0.0 + + optional-dependencies + + optional-project + project-with-optionals + main-project + + \ No newline at end of file diff --git a/maven-modules/optional-dependencies/project-with-optionals/pom.xml b/maven-modules/optional-dependencies/project-with-optionals/pom.xml new file mode 100644 index 0000000000..6a14f3260d --- /dev/null +++ b/maven-modules/optional-dependencies/project-with-optionals/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + com.baeldung + project-with-optionals + 0.0.1-SNAPSHOT + pom + + + + com.baeldung + optional-project + 0.0.1-SNAPSHOT + true + + + \ No newline at end of file diff --git a/maven-modules/pom.xml b/maven-modules/pom.xml index 528f44bddc..86a7d5756c 100644 --- a/maven-modules/pom.xml +++ b/maven-modules/pom.xml @@ -26,6 +26,7 @@ maven-properties versions-maven-plugin version-collision + optional-dependencies From c1a9c42194d7945b8c5162de41d6c92410437247 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 25 Jul 2020 18:23:39 +0000 Subject: [PATCH 132/309] Review - II Kevin Gilmore --- .../customLoader/ClassLoaderInfo.java | 11 ------- .../customLoader/CustomClassLoader.java | 32 ------------------- 2 files changed, 43 deletions(-) delete mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java delete mode 100644 core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/CustomClassLoader.java diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java deleted file mode 100644 index 2574394c13..0000000000 --- a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/ClassLoaderInfo.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.loadedclasslisting.customLoader; - -import java.util.ArrayList; - -public class ClassLoaderInfo { - - public void printClassLoaders() throws ClassNotFoundException { - System.out.println("Classloader of this class:" + ClassLoaderInfo.class.getClassLoader()); - System.out.println("Classloader of ArrayList:" + ArrayList.class.getClassLoader()); - } -} diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/CustomClassLoader.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/CustomClassLoader.java deleted file mode 100644 index a5f293f605..0000000000 --- a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/customLoader/CustomClassLoader.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.loadedclasslisting.customLoader; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -public class CustomClassLoader extends ClassLoader { - - @Override - public Class findClass(String name) throws ClassNotFoundException { - byte[] b = loadClassFromFile(name); - return defineClass(name, b, 0, b.length); - } - - private byte[] loadClassFromFile(String fileName) { - InputStream inputStream = getClass().getClassLoader() - .getResourceAsStream(fileName.replace('.', File.separatorChar) + ".class"); - byte[] buffer; - ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); - int nextValue = 0; - try { - while ((nextValue = inputStream.read()) != -1) { - byteStream.write(nextValue); - } - } catch (IOException e) { - e.printStackTrace(); - } - buffer = byteStream.toByteArray(); - return buffer; - } -} From 1299a22eb52b302b9585e369e5109d552a11ef44 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 25 Jul 2020 18:28:28 +0000 Subject: [PATCH 133/309] Review - II Kevin Gilmore Changes --- .../baeldung/loadedclasslisting/Launcher.java | 39 +++---------------- .../ListLoadedClassesAgent.java | 24 ++++-------- 2 files changed, 12 insertions(+), 51 deletions(-) diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java index e1851275c9..30db6b0bb7 100644 --- a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java @@ -1,48 +1,19 @@ package com.baeldung.loadedclasslisting; -import java.lang.reflect.Method; import java.util.Arrays; -import com.baeldung.loadedclasslisting.ListLoadedClassesAgent.ClassLoaderType; -import com.baeldung.loadedclasslisting.customLoader.ClassLoaderInfo; -import com.baeldung.loadedclasslisting.customLoader.CustomClassLoader; - public class Launcher { - private static ClassLoader customClassLoader; - public static void main(String[] args) { - printClassesLoadedBy(ClassLoaderType.BOOTSTRAP); - printClassesLoadedBy(ClassLoaderType.SYSTEM); - printClassesLoadedBy(ClassLoaderType.EXTENSION); - printClassesLoadedBy(ClassLoaderType.CUSTOM); + printClassesLoadedBy("BOOTSTRAP"); + printClassesLoadedBy("SYSTEM"); + printClassesLoadedBy("EXTENSION"); } - private static void printClassesLoadedBy(ClassLoaderType classLoaderType) { - Class[] classes; - if (classLoaderType.equals(ClassLoaderType.CUSTOM)) { - customClassLoader = customClassLoading(); - classes = ListLoadedClassesAgent.listLoadedClasses(customClassLoader); - } else { - classes = ListLoadedClassesAgent.listLoadedClasses(classLoaderType); - } + private static void printClassesLoadedBy(String classLoaderType) { + Class[] classes = ListLoadedClassesAgent.listLoadedClasses(classLoaderType); Arrays.asList(classes) .forEach(clazz -> System.out.println( classLoaderType + " ClassLoader : " + clazz.getCanonicalName())); } - - private static CustomClassLoader customClassLoading() { - CustomClassLoader customClassLoader = new CustomClassLoader(); - Class c; - try { - c = customClassLoader.findClass(ClassLoaderInfo.class.getName()); - Object ob = c.getDeclaredConstructor() - .newInstance(); - Method md = c.getMethod("printClassLoaders"); - md.invoke(ob); - } catch (Exception e) { - e.printStackTrace(); - } - return customClassLoader; - } } diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java index 8f4b8ebd41..337214a664 100644 --- a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java @@ -4,17 +4,13 @@ import java.lang.instrument.Instrumentation; public class ListLoadedClassesAgent { - public enum ClassLoaderType { - SYSTEM, EXTENSION, BOOTSTRAP, CUSTOM , PLATFORM - } - private static Instrumentation instrumentation; public static void premain(String agentArgs, Instrumentation instrumentation) { ListLoadedClassesAgent.instrumentation = instrumentation; } - public static Class[] listLoadedClasses(ClassLoaderType classLoaderType) { + public static Class[] listLoadedClasses(String classLoaderType) { if (instrumentation == null) { throw new IllegalStateException( "ListLoadedClassesAgent is not initialized."); @@ -23,24 +19,18 @@ public class ListLoadedClassesAgent { getClassLoader(classLoaderType)); } - public static Class[] listLoadedClasses(ClassLoader classLoader) { - if (instrumentation == null) { - throw new IllegalStateException( - "ListLoadedClassesAgent is not initialized."); - } - return instrumentation.getInitiatedClasses(classLoader); - } - - private static ClassLoader getClassLoader(ClassLoaderType classLoaderType) { + private static ClassLoader getClassLoader(String classLoaderType) { ClassLoader classLoader = null; switch (classLoaderType) { - case SYSTEM: + case "SYSTEM": classLoader = ClassLoader.getSystemClassLoader(); break; - case EXTENSION: + case "EXTENSION": classLoader = ClassLoader.getSystemClassLoader().getParent(); break; - case BOOTSTRAP: + // passing a null value to the Instrumentation : getInitiatedClasses method + // defaults to the bootstrap class loader + case "BOOTSTRAP": break; default: break; From cd4f74779a383e131bc9d2a234c0f07ab637fef3 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 26 Jul 2020 06:43:57 +0300 Subject: [PATCH 134/309] Update pom.xml (#9767) --- rule-engines/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/rule-engines/pom.xml b/rule-engines/pom.xml index d3d3127ce0..27748a5c3e 100644 --- a/rule-engines/pom.xml +++ b/rule-engines/pom.xml @@ -16,6 +16,7 @@ easy-rules openl-tablets rulebook + From 94555a4510b8bd3f7e19dd3a91ce943fed092c29 Mon Sep 17 00:00:00 2001 From: TJ Date: Sun, 26 Jul 2020 09:29:54 +0530 Subject: [PATCH 135/309] BAEL-4403 (#9740) * Hexagonal architecture in Java * BAEL-4403 * Revert "Hexagonal architecture in Java" This reverts commit 7ba4c9dcbd99ca418c070a73bd9ab9f6c956d185. * Updated code to use only Console * Added System.out * Created seaprate method for each functionality * Added Unit Test Case for ConsoleAndOut class Co-authored-by: Tarun Jain --- .../baeldung/consoleout/ConsoleAndOut.java | 31 +++++++++++++++++++ .../consoleout/ConsoleAndOutUnitTest.java | 27 ++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java create mode 100644 core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java diff --git a/core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java b/core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java new file mode 100644 index 0000000000..082a5219c9 --- /dev/null +++ b/core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java @@ -0,0 +1,31 @@ +package com.baeldung.consoleout; + +import java.io.Console; + +public class ConsoleAndOut { + public static void main(String[] args) { + try { + printConsoleObject(); + readPasswordFromConsole(); + } catch (Exception ex) { + // Eating NullPointerExcpetion which will occur when this + // program will be run from mediums other than console + } + printSysOut(); + } + + static void printConsoleObject() { + Console console = System.console(); + console.writer().print(console); + } + + static void readPasswordFromConsole() { + Console console = System.console(); + char[] password = console.readPassword("Enter password: "); + console.printf(String.valueOf(password)); + } + + static void printSysOut() { + System.out.println(System.out); + } +} diff --git a/core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java b/core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java new file mode 100644 index 0000000000..619a65a1fc --- /dev/null +++ b/core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.consoleout; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +class ConsoleAndOutUnitTest { + + @Test + void whenRetreivingConsole_thenPrintConsoleObject() { + assertThrows(NullPointerException.class, () -> { + ConsoleAndOut.printConsoleObject(); + }); + } + + @Test + void whenReadingPassword_thenReadPassword() { + assertThrows(NullPointerException.class, () -> { + ConsoleAndOut.readPasswordFromConsole(); + }); + } + + @Test + void whenRetrievingSysOut_thenPrintSysOutObject() { + ConsoleAndOut.printSysOut(); + } +} From e3999c9112a8aa46173aa7c09ea72626a44f1113 Mon Sep 17 00:00:00 2001 From: mdhtr Date: Mon, 20 Jul 2020 21:14:49 +0200 Subject: [PATCH 136/309] Changes based on editor review - extract Person classes from test classes - shorten test name of one test - fix one warning --- .../JacksonDeserializationUnitTest.java | 4 ++-- .../HydraJsonldSerializationUnitTest.java | 12 ------------ .../serialization/hydrajsonld/Person.java | 15 +++++++++++++++ .../JacksonJsonLdSerializationUnitTest.java | 17 ----------------- .../serialization/jacksonjsonld/Person.java | 19 +++++++++++++++++++ 5 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/Person.java create mode 100644 json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/Person.java diff --git a/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java index 35a2613957..df09a98f76 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java +++ b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java @@ -16,11 +16,11 @@ import com.github.jsonldjava.utils.JsonUtils; public class JacksonDeserializationUnitTest { @Test - void givenAJsonLdObject_whenCompactIsUsedWithEmptyContext_thenItCanBeDeserializedIntoAJacksonAnnotatedJavaObject() throws IOException { + void givenAJsonLdObject_whenCompactIsUsedWithEmptyContext_thenItCanBeDeserializedWithJackson() throws IOException { String inputJsonLd = "{\"@context\":{\"@vocab\":\"http://schema.org/\",\"knows\":{\"@type\":\"@id\"}},\"@type\":\"Person\",\"@id\":\"http://example.com/person/1234\",\"name\":\"Example Name\",\"knows\":\"http://example.com/person/2345\"}"; Object jsonObject = JsonUtils.fromString(inputJsonLd); - Object compact = JsonLdProcessor.compact(jsonObject, new HashMap(), new JsonLdOptions()); + Object compact = JsonLdProcessor.compact(jsonObject, new HashMap<>(), new JsonLdOptions()); String compactContent = JsonUtils.toString(compact); assertEquals("{\"@id\":\"http://example.com/person/1234\",\"@type\":\"http://schema.org/Person\",\"http://schema.org/knows\":{\"@id\":\"http://example.com/person/2345\"},\"http://schema.org/name\":\"Example Name\"}", compactContent); diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java index e5d1e35236..308987a0bd 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java @@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.BeanDescription; import com.fasterxml.jackson.databind.JsonSerializer; @@ -15,20 +14,9 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.BeanSerializerModifier; import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; -import de.escalon.hypermedia.hydra.mapping.Expose; -import de.escalon.hypermedia.hydra.mapping.Vocab; import de.escalon.hypermedia.hydra.serialize.JacksonHydraSerializer; public class HydraJsonldSerializationUnitTest { - @Vocab("http://example.com/vocab/") - @Expose("person") - static class Person { - @JsonProperty("@id") - public String id; - @Expose("fullName") - public String name; - } - @Test void givenAHydraJsonldAnnotatedObject_whenJacksonHydraSerializerIsUsed_thenAJsonLdDocumentIsGenerated() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/Person.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/Person.java new file mode 100644 index 0000000000..87587d02ac --- /dev/null +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/Person.java @@ -0,0 +1,15 @@ +package com.baeldung.jsonld.serialization.hydrajsonld; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import de.escalon.hypermedia.hydra.mapping.Expose; +import de.escalon.hypermedia.hydra.mapping.Vocab; + +@Vocab("http://example.com/vocab/") +@Expose("person") +public class Person { + @JsonProperty("@id") + public String id; + @Expose("fullName") + public String name; +} diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java index b539c73608..07e44b4981 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java @@ -8,25 +8,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import ioinformarics.oss.jackson.module.jsonld.JsonldModule; -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldId; -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldLink; -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldNamespace; -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldProperty; -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldResource; -import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldType; public class JacksonJsonLdSerializationUnitTest { - @JsonldResource - @JsonldNamespace(name = "s", uri = "http://schema.org/") - @JsonldType("s:Person") - @JsonldLink(rel = "s:knows", name = "knows", href = "http://example.com/person/2345") - static class Person { - @JsonldId - public String id = "http://example.com/person/1234"; - @JsonldProperty("s:name") - public String name = "Example Name"; - } - @Test void givenAJacksonJsonldAnnotatedObject_whenJsonldModuleIsUsed_thenAJsonLdDocumentIsGenerated() throws JsonProcessingException { ObjectMapper objectMapper = new ObjectMapper(); diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/Person.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/Person.java new file mode 100644 index 0000000000..d0c9e4f111 --- /dev/null +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/Person.java @@ -0,0 +1,19 @@ +package com.baeldung.jsonld.serialization.jacksonjsonld; + +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldId; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldLink; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldNamespace; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldProperty; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldResource; +import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldType; + +@JsonldResource +@JsonldNamespace(name = "s", uri = "http://schema.org/") +@JsonldType("s:Person") +@JsonldLink(rel = "s:knows", name = "knows", href = "http://example.com/person/2345") +public class Person { + @JsonldId + public String id = "http://example.com/person/1234"; + @JsonldProperty("s:name") + public String name = "Example Name"; +} From f83f670bf757954f82f5ee688a025d9302656242 Mon Sep 17 00:00:00 2001 From: mdhtr Date: Sun, 26 Jul 2020 09:44:17 +0200 Subject: [PATCH 137/309] Format inline JSON objects by hand --- .../JacksonDeserializationUnitTest.java | 18 ++++++++++++++++-- .../HydraJsonldSerializationUnitTest.java | 10 +++++++++- .../JacksonJsonLdSerializationUnitTest.java | 14 +++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java index df09a98f76..9c6b6f976a 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java +++ b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java @@ -17,13 +17,27 @@ public class JacksonDeserializationUnitTest { @Test void givenAJsonLdObject_whenCompactIsUsedWithEmptyContext_thenItCanBeDeserializedWithJackson() throws IOException { - String inputJsonLd = "{\"@context\":{\"@vocab\":\"http://schema.org/\",\"knows\":{\"@type\":\"@id\"}},\"@type\":\"Person\",\"@id\":\"http://example.com/person/1234\",\"name\":\"Example Name\",\"knows\":\"http://example.com/person/2345\"}"; + String inputJsonLd = "{" + + "\"@context\":{" + + "\"@vocab\":\"http://schema.org/\"," + + "\"knows\":{\"@type\":\"@id\"}" + + "}," + + "\"@type\":\"Person\"," + + "\"@id\":\"http://example.com/person/1234\"," + + "\"name\":\"Example Name\"," + + "\"knows\":\"http://example.com/person/2345\"" + + "}"; Object jsonObject = JsonUtils.fromString(inputJsonLd); Object compact = JsonLdProcessor.compact(jsonObject, new HashMap<>(), new JsonLdOptions()); String compactContent = JsonUtils.toString(compact); - assertEquals("{\"@id\":\"http://example.com/person/1234\",\"@type\":\"http://schema.org/Person\",\"http://schema.org/knows\":{\"@id\":\"http://example.com/person/2345\"},\"http://schema.org/name\":\"Example Name\"}", compactContent); + assertEquals("{" + + "\"@id\":\"http://example.com/person/1234\"," + + "\"@type\":\"http://schema.org/Person\"," + + "\"http://schema.org/knows\":{\"@id\":\"http://example.com/person/2345\"}," + + "\"http://schema.org/name\":\"Example Name\"" + + "}", compactContent); ObjectMapper objectMapper = new ObjectMapper(); Person person = objectMapper.readValue(compactContent, Person.class); diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java index 308987a0bd..06105d579e 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java @@ -29,7 +29,15 @@ public class HydraJsonldSerializationUnitTest { String personJsonLd = objectMapper.writeValueAsString(person); - assertEquals("{\"@context\":{\"@vocab\":\"http://example.com/vocab/\",\"name\":\"fullName\"},\"@type\":\"person\",\"name\":\"Example Name\",\"@id\":\"http://example.com/person/1234\"}", personJsonLd); + assertEquals("{" + + "\"@context\":{" + + "\"@vocab\":\"http://example.com/vocab/\"," + + "\"name\":\"fullName\"" + + "}," + + "\"@type\":\"person\"," + + "\"name\":\"Example Name\"," + + "\"@id\":\"http://example.com/person/1234\"" + + "}", personJsonLd); } static SimpleModule getJacksonHydraSerializerModule() { diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java index 07e44b4981..cd41989a53 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java @@ -18,8 +18,16 @@ public class JacksonJsonLdSerializationUnitTest { Person person = new Person(); String personJsonLd = objectMapper.writeValueAsString(person); - assertEquals( - "{\"@type\":\"s:Person\",\"@context\":{\"s\":\"http://schema.org/\",\"name\":\"s:name\",\"knows\":{\"@id\":\"s:knows\",\"@type\":\"@id\"}},\"name\":\"Example Name\",\"@id\":\"http://example.com/person/1234\",\"knows\":\"http://example.com/person/2345\"}", - personJsonLd); + assertEquals("{" + + "\"@type\":\"s:Person\"," + + "\"@context\":{" + + "\"s\":\"http://schema.org/\"," + + "\"name\":\"s:name\"," + + "\"knows\":{\"@id\":\"s:knows\",\"@type\":\"@id\"}" + + "}," + + "\"name\":\"Example Name\"," + + "\"@id\":\"http://example.com/person/1234\"," + + "\"knows\":\"http://example.com/person/2345\"" + + "}", personJsonLd); } } From c95dbf8135c7eb1cd42a3f28d13be22978a0a5c7 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sun, 26 Jul 2020 16:51:40 +0530 Subject: [PATCH 138/309] BAEL-4025:Spring Data Azure Cosmos DB --- .../spring-data-cosmosdb/pom.xml | 48 +++++++++++++++ .../cosmosdb/AzurecosmodbApplication.java | 44 ++++++++++++++ .../controller/ProductController.java | 54 +++++++++++++++++ .../spring/data/cosmosdb/entity/Product.java | 58 +++++++++++++++++++ .../repository/ProductRepository.java | 15 +++++ .../data/cosmosdb/service/ProductService.java | 39 +++++++++++++ .../src/main/resources/application.properties | 4 ++ ...zurecosmodbApplicationIntegrationTest.java | 40 +++++++++++++ 8 files changed, 302 insertions(+) create mode 100644 persistence-modules/spring-data-cosmosdb/pom.xml create mode 100644 persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplication.java create mode 100644 persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java create mode 100644 persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java create mode 100644 persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java create mode 100644 persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java create mode 100644 persistence-modules/spring-data-cosmosdb/src/main/resources/application.properties create mode 100644 persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationIntegrationTest.java diff --git a/persistence-modules/spring-data-cosmosdb/pom.xml b/persistence-modules/spring-data-cosmosdb/pom.xml new file mode 100644 index 0000000000..8bb103879d --- /dev/null +++ b/persistence-modules/spring-data-cosmosdb/pom.xml @@ -0,0 +1,48 @@ + + + 4.0.0 + spring-data-cosmosdb + spring-data-cosmos-db + tutorial for spring-data-cosmosdb + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + com.microsoft.azure + spring-data-cosmosdb + 2.3.0 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplication.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplication.java new file mode 100644 index 0000000000..2b145d14cd --- /dev/null +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplication.java @@ -0,0 +1,44 @@ +package com.baeldung.spring.data.cosmosdb; + +import com.azure.data.cosmos.CosmosKeyCredential; +import com.baeldung.spring.data.cosmosdb.repository.ProductRepository; +import com.microsoft.azure.spring.data.cosmosdb.config.AbstractCosmosConfiguration; +import com.microsoft.azure.spring.data.cosmosdb.config.CosmosDBConfig; +import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableCosmosRepositories; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +@EnableCosmosRepositories(basePackageClasses = ProductRepository.class) +public class AzurecosmodbApplication extends AbstractCosmosConfiguration { + + public static void main(String[] args) { + SpringApplication.run(AzurecosmodbApplication.class, args); + } + + @Value("${azure.cosmosdb.uri}") + private String uri; + + @Value("${azure.cosmosdb.key}") + private String key; + + @Value("${azure.cosmosdb.secondaryKey}") + private String secondaryKey; + + @Value("${azure.cosmosdb.database}") + private String dbName; + + private CosmosKeyCredential cosmosKeyCredential; + + @Bean + public CosmosDBConfig getConfig() { + this.cosmosKeyCredential = new CosmosKeyCredential(key); + CosmosDBConfig cosmosdbConfig = CosmosDBConfig.builder(uri, this.cosmosKeyCredential, dbName) + .build(); + return cosmosdbConfig; + } + +} diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java new file mode 100644 index 0000000000..c1e38c9601 --- /dev/null +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java @@ -0,0 +1,54 @@ +package com.baeldung.spring.data.cosmosdb.controller; + +import com.baeldung.spring.data.cosmosdb.entity.Product; +import com.baeldung.spring.data.cosmosdb.service.ProductService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Optional; + +@RestController +@RequestMapping("/products") +public class ProductController { + + @Autowired + private ProductService productService; + + @PostMapping + @ResponseStatus(HttpStatus.CREATED) + public void create(@RequestBody Product product) { + productService.saveProduct(product); + } + + @GetMapping(value = "/{id}/category/{category}") + public Optional get(@PathVariable String id, @PathVariable String category) { + return productService.findById(id, category); + } + + @DeleteMapping(value = "/{id}/category/{category}") + public void delete(@PathVariable String id, @PathVariable String category) { + productService.delete(id, category); + } + + @GetMapping + public List getByName(@RequestParam String name) { + return productService.findProductByName(name); + } + + @GetMapping(value = "/category/{category}") + public List getByCategory(@PathVariable String category) { + return productService.getProductsOfCategory(category); + } + +} diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java new file mode 100644 index 0000000000..07bb8889f5 --- /dev/null +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java @@ -0,0 +1,58 @@ +package com.baeldung.spring.data.cosmosdb.entity; + +import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document; +import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey; + +import org.springframework.data.annotation.Id; + +@Document(collection = "products") +public class Product { + + @Id + private String productid; + + private String productName; + + private double price; + + @PartitionKey + private String productCategory; + + public String getProductid() { + return productid; + } + + public void setProductid(String productid) { + this.productid = productid; + } + + public String getProductName() { + return productName; + } + + public void setProductName(String productName) { + this.productName = productName; + } + + public String getProductCategory() { + return productCategory; + } + + public void setProductCategory(String productCategory) { + this.productCategory = productCategory; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + @Override + public String toString() { + return "Product [productid=" + productid + ", productName=" + productName + ", price=" + price + ", productCategory=" + productCategory + "]"; + } + +} diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java new file mode 100644 index 0000000000..29dc85a2cf --- /dev/null +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java @@ -0,0 +1,15 @@ +package com.baeldung.spring.data.cosmosdb.repository; + +import com.baeldung.spring.data.cosmosdb.entity.Product; +import com.microsoft.azure.spring.data.cosmosdb.repository.CosmosRepository; + +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface ProductRepository extends CosmosRepository { + List findByProductName(String productName); + + List findByProductCategory(String category); +} diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java new file mode 100644 index 0000000000..6846d5205c --- /dev/null +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java @@ -0,0 +1,39 @@ +package com.baeldung.spring.data.cosmosdb.service; + +import com.azure.data.cosmos.PartitionKey; +import com.baeldung.spring.data.cosmosdb.entity.Product; +import com.baeldung.spring.data.cosmosdb.repository.ProductRepository; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class ProductService { + + @Autowired + private ProductRepository repository; + + public List findProductByName(String productName) { + return repository.findByProductName(productName); + } + + public Optional findById(String productId, String category) { + return repository.findById(productId, new PartitionKey(category)); + } + + public List getProductsOfCategory(String category) { + List products = repository.findByProductCategory(category); + return products; + } + + public void saveProduct(Product product) { + repository.save(product); + } + + public void delete(String productId, String category) { + repository.deleteById(productId, new PartitionKey(category)); + } +} diff --git a/persistence-modules/spring-data-cosmosdb/src/main/resources/application.properties b/persistence-modules/spring-data-cosmosdb/src/main/resources/application.properties new file mode 100644 index 0000000000..ba99ea2e6e --- /dev/null +++ b/persistence-modules/spring-data-cosmosdb/src/main/resources/application.properties @@ -0,0 +1,4 @@ +azure.cosmosdb.uri=cosmodb-uri +azure.cosmosdb.key=cosmodb-primary-key +azure.cosmosdb.secondaryKey=cosmodb-second-key +azure.cosmosdb.database=cosmodb-name \ No newline at end of file diff --git a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationIntegrationTest.java b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationIntegrationTest.java new file mode 100644 index 0000000000..0ef6af15e1 --- /dev/null +++ b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationIntegrationTest.java @@ -0,0 +1,40 @@ +package com.baeldung.spring.data.cosmosdb; + +import com.azure.data.cosmos.PartitionKey; +import com.baeldung.spring.data.cosmosdb.entity.Product; +import com.baeldung.spring.data.cosmosdb.repository.ProductRepository; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.util.Assert; + +import java.util.Optional; + +//Uncomment this when configured URI and keys for Azure Cosmos DB in application.properties +//to run the integration test +//@SpringBootTest +public class AzurecosmodbApplicationIntegrationTest { + + @Autowired + ProductRepository productRepository; + + // Uncomment this when configured URI and keys for Azure Cosmos DB in application.properties + // to run the integration test + // @Test + public void givenProductIsCreated_whenCallFindById_thenProductIsFound() { + Product product = new Product(); + product.setProductid("1001"); + product.setProductCategory("Shirt"); + product.setPrice(110.0); + product.setProductName("Blue Shirt"); + + // Uncomment these lines when configured URI and keys for Azure Cosmos DB in application.properties + // to run the integration test + // productRepository.save(product); + // Optional retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt")); + // Assert.notNull(retrievedProduct, "Retrieved Product is Null"); + + } + +} From b5eef05476b6c946c9f4c97fe9b8eef9dfb5f28b Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sun, 26 Jul 2020 16:59:27 +0530 Subject: [PATCH 139/309] cleaning up unnecessary changes --- spring-caching/src/main/resources/schema.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-caching/src/main/resources/schema.sql b/spring-caching/src/main/resources/schema.sql index 7d5cb36d66..35d02bb916 100644 --- a/spring-caching/src/main/resources/schema.sql +++ b/spring-caching/src/main/resources/schema.sql @@ -1,6 +1,7 @@ DROP TABLE ORDERDETAIL IF EXISTS; DROP TABLE ITEM IF EXISTS; DROP TABLE CUSTOMER IF EXISTS; + CREATE TABLE CUSTOMER( CUSTOMERID INT PRIMARY KEY, CUSTOMERNAME VARCHAR(250) NOT NULL From 55d15037c0825efd94e48048a8d1889bdbbf4563 Mon Sep 17 00:00:00 2001 From: developerDiv Date: Sun, 26 Jul 2020 17:08:44 +0100 Subject: [PATCH 140/309] Rename DeliveryPlatform send method to 'deliver' to aid readability and avoiding confusion with EmailService.send method Re-arrange order of mocks and inject mocks Rename argument matcher and captor tests --- .../mockito/argumentcaptor/DeliveryPlatform.java | 2 +- .../mockito/argumentcaptor/EmailService.java | 2 +- .../argumentcaptor/EmailServiceUnitTest.java | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/DeliveryPlatform.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/DeliveryPlatform.java index dbad1e1bcf..6cbaf7b97c 100644 --- a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/DeliveryPlatform.java +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/DeliveryPlatform.java @@ -2,7 +2,7 @@ package com.baeldung.mockito.argumentcaptor; public interface DeliveryPlatform { - void send(Email email); + void deliver(Email email); String getServiceStatus(); diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/EmailService.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/EmailService.java index c368f41d2f..d22feaf8a4 100644 --- a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/EmailService.java +++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/argumentcaptor/EmailService.java @@ -15,7 +15,7 @@ public class EmailService { } Email email = new Email(to, subject, body); email.setFormat(format); - platform.send(email); + platform.deliver(email); } public ServiceStatus checkServiceStatus() { diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java index 9d18957b2e..5ed7be7d6e 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/argumentcaptor/EmailServiceUnitTest.java @@ -10,12 +10,12 @@ import static org.junit.Assert.*; @RunWith(MockitoJUnitRunner.class) public class EmailServiceUnitTest { - @InjectMocks - EmailService emailService; - @Mock DeliveryPlatform platform; + @InjectMocks + EmailService emailService; + @Captor ArgumentCaptor emailCaptor; @@ -30,7 +30,7 @@ public class EmailServiceUnitTest { emailService.send(to, subject, body, false); - Mockito.verify(platform).send(emailCaptor.capture()); + Mockito.verify(platform).deliver(emailCaptor.capture()); Email emailCaptorValue = emailCaptor.getValue(); assertEquals(Format.TEXT_ONLY, emailCaptorValue.getFormat()); } @@ -43,7 +43,7 @@ public class EmailServiceUnitTest { emailService.send(to, subject, body, true); - Mockito.verify(platform).send(emailCaptor.capture()); + Mockito.verify(platform).deliver(emailCaptor.capture()); Email value = emailCaptor.getValue(); assertEquals(Format.HTML, value.getFormat()); } @@ -67,7 +67,7 @@ public class EmailServiceUnitTest { } @Test - public void usingArgumentMatcher_whenAuthenticatedWithValidCredentials_expectTrue() { + public void whenUsingArgumentMatcherForValidCredentials_expectTrue() { Credentials credentials = new Credentials("baeldung", "correct_password", "correct_key"); Mockito.when(platform.authenticate(Mockito.eq(credentials))).thenReturn(AuthenticationStatus.AUTHENTICATED); @@ -75,7 +75,7 @@ public class EmailServiceUnitTest { } @Test - public void usingArgumentCaptor_whenAuthenticatedWithValidCredentials_expectTrue() { + public void whenUsingArgumentCaptorForValidCredentials_expectTrue() { Credentials credentials = new Credentials("baeldung", "correct_password", "correct_key"); Mockito.when(platform.authenticate(credentialsCaptor.capture())).thenReturn(AuthenticationStatus.AUTHENTICATED); From 48ea32d583dd5fd5d45aa60516476c3e2096d300 Mon Sep 17 00:00:00 2001 From: STS Date: Sun, 26 Jul 2020 20:01:42 +0200 Subject: [PATCH 141/309] change test class name, add blank line and swap assert method parameter --- .../baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java b/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java index 45314519d4..b3f6949216 100644 --- a/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java +++ b/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java @@ -25,7 +25,7 @@ class ExcelFormulaUnitTest { } @Test - void givenExcelData_whenSetAndEvaluateFormula() throws IOException { + void givenExcelData_whenSetFormula_thenSuccess() throws IOException { FileInputStream inputStream = new FileInputStream(new File(fileLocation)); XSSFWorkbook wb = new XSSFWorkbook(inputStream); XSSFSheet sheet = wb.getSheetAt(0); @@ -43,7 +43,9 @@ class ExcelFormulaUnitTest { String startCellB = colNameB + 1; String stopCellB = colNameB + (sheet.getLastRowNum() + 1); String sumFormulaForColumnB = String.format("SUM(%s:%s)", startCellB, stopCellB); + double resultValue = excelFormula.setFormula(fileLocation, wb, sumFormulaForColumnA + "-" + sumFormulaForColumnB); - Assert.assertEquals(resultValue, resultColumnA - resultColumnB, 0d); + + Assert.assertEquals(resultColumnA - resultColumnB, resultValue, 0d); } } From 78d44e5a6010aecdb209855f1854ad017b2ac89c Mon Sep 17 00:00:00 2001 From: STS Date: Mon, 27 Jul 2020 10:07:30 +0200 Subject: [PATCH 142/309] change baeldung spell --- .../poi/excel/setformula/SetFormulaTest.xlsx | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename apache-poi/src/main/resources/com/{bealdung => baeldung}/poi/excel/setformula/SetFormulaTest.xlsx (100%) diff --git a/apache-poi/src/main/resources/com/bealdung/poi/excel/setformula/SetFormulaTest.xlsx b/apache-poi/src/main/resources/com/baeldung/poi/excel/setformula/SetFormulaTest.xlsx similarity index 100% rename from apache-poi/src/main/resources/com/bealdung/poi/excel/setformula/SetFormulaTest.xlsx rename to apache-poi/src/main/resources/com/baeldung/poi/excel/setformula/SetFormulaTest.xlsx From 2dbb667128e3f370bc68b5d1dd4269d8cc6861ef Mon Sep 17 00:00:00 2001 From: Loredana Date: Mon, 27 Jul 2020 12:01:55 +0300 Subject: [PATCH 143/309] article was moved to mockito-2; remove duplicate methods from mockito module --- testing-modules/mockito-2/README.md | 3 +- testing-modules/mockito/README.md | 1 - .../mockito/MockitoAnnotationUnitTest.java | 46 ------------------- 3 files changed, 2 insertions(+), 48 deletions(-) diff --git a/testing-modules/mockito-2/README.md b/testing-modules/mockito-2/README.md index 1a013f5de3..bb7235c2cc 100644 --- a/testing-modules/mockito-2/README.md +++ b/testing-modules/mockito-2/README.md @@ -5,4 +5,5 @@ - [Mockito Strict Stubbing and The UnnecessaryStubbingException](https://www.baeldung.com/mockito-unnecessary-stubbing-exception) - [Mockito and Fluent APIs](https://www.baeldung.com/mockito-fluent-apis) - [Mocking the ObjectMapper readValue() Method](https://www.baeldung.com/mockito-mock-jackson-read-value) -- [Introduction to Mockito’s AdditionalAnswers](https://www.baeldung.com/mockito-additionalanswers) \ No newline at end of file +- [Introduction to Mockito’s AdditionalAnswers](https://www.baeldung.com/mockito-additionalanswers) +- [Mockito – Using Spies](https://www.baeldung.com/mockito-spy) diff --git a/testing-modules/mockito/README.md b/testing-modules/mockito/README.md index 5f307c2f0b..38fb8225a6 100644 --- a/testing-modules/mockito/README.md +++ b/testing-modules/mockito/README.md @@ -12,5 +12,4 @@ - [Mocking Void Methods with Mockito](https://www.baeldung.com/mockito-void-methods) - [Mock Final Classes and Methods with Mockito](https://www.baeldung.com/mockito-final) - [Testing Callbacks with Mockito](https://www.baeldung.com/mockito-callbacks) -- [Mockito – Using Spies](https://www.baeldung.com/mockito-spy) - [Quick Guide to BDDMockito](https://www.baeldung.com/bdd-mockito) diff --git a/testing-modules/mockito/src/test/java/com/baeldung/mockito/MockitoAnnotationUnitTest.java b/testing-modules/mockito/src/test/java/com/baeldung/mockito/MockitoAnnotationUnitTest.java index 27e3258efb..1d3d6b1428 100644 --- a/testing-modules/mockito/src/test/java/com/baeldung/mockito/MockitoAnnotationUnitTest.java +++ b/testing-modules/mockito/src/test/java/com/baeldung/mockito/MockitoAnnotationUnitTest.java @@ -76,52 +76,6 @@ public class MockitoAnnotationUnitTest { assertEquals(100, spiedList.size()); } - @Test - public void whenSpyingOnList_thenCorrect() { - List list = new ArrayList(); - List spyList = Mockito.spy(list); - - spyList.add("one"); - spyList.add("two"); - - Mockito.verify(spyList).add("one"); - Mockito.verify(spyList).add("two"); - - assertEquals(2, spyList.size()); - } - - @Test - public void whenUsingTheSpyAnnotation_thenObjectIsSpied() { - spiedList.add("one"); - spiedList.add("two"); - - Mockito.verify(spiedList).add("one"); - Mockito.verify(spiedList).add("two"); - - assertEquals(2, spiedList.size()); - } - - @Test - public void whenStubASpy_thenStubbed() { - List list = new ArrayList(); - List spyList = Mockito.spy(list); - - assertEquals(0, spyList.size()); - - Mockito.doReturn(100).when(spyList).size(); - assertEquals(100, spyList.size()); - } - - @Test - public void whenCreateSpy_thenCreate() { - List spyList = Mockito.spy(new ArrayList<>()); - - spyList.add("one"); - Mockito.verify(spyList).add("one"); - - assertEquals(1, spyList.size()); - } - @Test public void whenNotUseCaptorAnnotation_thenCorrect() { final List mockList = Mockito.mock(List.class); From 8ee84bbc4aa5ad94af7b66315d1776ab9faf28f1 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Mon, 27 Jul 2020 22:13:05 +0200 Subject: [PATCH 144/309] JAVA-1650: Get rid of the overriden spring-boot.version property --- spring-5-reactive-security/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-5-reactive-security/pom.xml b/spring-5-reactive-security/pom.xml index 58c993bda5..2024cb5138 100644 --- a/spring-5-reactive-security/pom.xml +++ b/spring-5-reactive-security/pom.xml @@ -128,7 +128,6 @@ 1.0 4.1 3.1.6.RELEASE - 2.2.2.RELEASE From 2a58dcf29d8bf5ae716347d7d879536b747ee6a3 Mon Sep 17 00:00:00 2001 From: Maja Joksovic Date: Tue, 28 Jul 2020 01:33:43 +0200 Subject: [PATCH 145/309] initial commit --- .../baeldung/copyfolder/ApacheCommons.java | 15 +++++ .../java/com/baeldung/copyfolder/CoreOld.java | 38 +++++++++++ .../java/com/baeldung/copyfolder/JavaNio.java | 22 +++++++ .../copyfolder/ApacheCommonsUnitTest.java | 59 +++++++++++++++++ .../baeldung/copyfolder/CoreOldUnitTest.java | 63 +++++++++++++++++++ .../baeldung/copyfolder/JavaNioUnitTest.java | 59 +++++++++++++++++ 6 files changed, 256 insertions(+) create mode 100644 core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/ApacheCommons.java create mode 100644 core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/CoreOld.java create mode 100644 core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/JavaNio.java create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/ApacheCommonsUnitTest.java create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/CoreOldUnitTest.java create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/JavaNioUnitTest.java diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/ApacheCommons.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/ApacheCommons.java new file mode 100644 index 0000000000..67af0594a4 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/ApacheCommons.java @@ -0,0 +1,15 @@ +package com.baeldung.copyfolder; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; + +public class ApacheCommons { + + public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException { + File sourceFolder = new File(sourceDirectoryLocation); + File destinationFolder = new File(destinationDirectoryLocation); + FileUtils.copyDirectory(sourceFolder, destinationFolder); + } +} diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/CoreOld.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/CoreOld.java new file mode 100644 index 0000000000..d1a0158db3 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/CoreOld.java @@ -0,0 +1,38 @@ +package com.baeldung.copyfolder; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +public class CoreOld { + + public static void copyDirectoryJavaUnder7(File source, File destination) throws IOException { + if (source.isDirectory()) { + copyDirectory(source, destination); + } else { + copyFile(source, destination); + } + } + + private static void copyDirectory(File sourceFolder, File destinationFolder) throws IOException { + if (!destinationFolder.exists()) { + destinationFolder.mkdir(); + } + for (String f : sourceFolder.list()) { + copyDirectoryJavaUnder7(new File(sourceFolder, f), new File(destinationFolder, f)); + } + } + + private static void copyFile(File sourceFile, File destinationFile) throws IOException { + try (InputStream in = new FileInputStream(sourceFile); OutputStream out = new FileOutputStream(destinationFile)) { + byte[] buf = new byte[1024]; + int length; + while ((length = in.read(buf)) > 0) { + out.write(buf, 0, length); + } + } + } +} diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/JavaNio.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/JavaNio.java new file mode 100644 index 0000000000..368118a943 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/JavaNio.java @@ -0,0 +1,22 @@ +package com.baeldung.copyfolder; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class JavaNio { + + public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException { + Files.walk(Paths.get(sourceDirectoryLocation)) + .forEach(a -> { + Path b = Paths.get(destinationDirectoryLocation, a.toString() + .substring(sourceDirectoryLocation.length())); + try { + Files.copy(a, b); + } catch (IOException e) { + e.printStackTrace(); + } + }); + } +} diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/ApacheCommonsUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/ApacheCommonsUnitTest.java new file mode 100644 index 0000000000..71e4c52104 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/ApacheCommonsUnitTest.java @@ -0,0 +1,59 @@ +package com.baeldung.copyfolder; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Comparator; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ApacheCommonsUnitTest { + + private final String sourceFolderLocation = "src/test/resources/sourceFolder"; + private final String subFolderName = "/childFolder"; + private final String fileName = "/file.txt"; + private final String destinationFolderLocation = "src/test/resources/destinationFolder"; + + @BeforeEach + public void createFolderWithSubfolderAndFile() throws IOException { + Files.createDirectories(Paths.get(sourceFolderLocation)); + Files.createDirectories(Paths.get(sourceFolderLocation + subFolderName)); + Files.createFile(Paths.get(sourceFolderLocation + subFolderName + fileName)); + } + + @Test + public void whenSourceFolderExists_thenFolderIsFullyCopied() throws IOException { + ApacheCommons.copyDirectory(sourceFolderLocation, destinationFolderLocation); + + assertTrue(new File(destinationFolderLocation).exists()); + assertTrue(new File(destinationFolderLocation + subFolderName).exists()); + assertTrue(new File(destinationFolderLocation + subFolderName + fileName).exists()); + } + + @Test + public void whenSourceFolderDoesNotExist_thenExceptionIsThrown() { + assertThrows(Exception.class, () -> ApacheCommons.copyDirectory("nonExistingFolder", destinationFolderLocation)); + } + + @AfterEach + public void cleanUp() throws IOException { + Files.walk(Paths.get(sourceFolderLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + if (new File(destinationFolderLocation).exists()) { + Files.walk(Paths.get(destinationFolderLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } + } + +} diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/CoreOldUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/CoreOldUnitTest.java new file mode 100644 index 0000000000..ba45fd3cd0 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/CoreOldUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.copyfolder; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Comparator; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class CoreOldUnitTest { + + private final String sourceFolderLocation = "src/test/resources/sourceFolder"; + private final String subFolderName = "/childFolder"; + private final String fileName = "/file.txt"; + private final String destinationFolderLocation = "src/test/resources/destinationFolder"; + + @BeforeEach + public void createFolderWithSubfolderAndFile() throws IOException { + Files.createDirectories(Paths.get(sourceFolderLocation)); + Files.createDirectories(Paths.get(sourceFolderLocation + subFolderName)); + Files.createFile(Paths.get(sourceFolderLocation + subFolderName + fileName)); + } + + @Test + public void whenSourceFolderExists_thenFolderIsFullyCopied() throws IOException { + File sourceFolder = new File(sourceFolderLocation); + File destinationFolder = new File(destinationFolderLocation); + CoreOld.copyDirectoryJavaUnder7(sourceFolder, destinationFolder); + + assertTrue(new File(destinationFolderLocation).exists()); + assertTrue(new File(destinationFolderLocation + subFolderName).exists()); + assertTrue(new File(destinationFolderLocation + subFolderName + fileName).exists()); + } + + @Test + public void whenSourceFolderDoesNotExist_thenExceptionIsThrown() throws IOException { + File sourceFolder = new File("nonExistingFolder"); + File destinationFolder = new File(destinationFolderLocation); + assertThrows(IOException.class, () -> CoreOld.copyDirectoryJavaUnder7(sourceFolder, destinationFolder)); + } + + @AfterEach + public void cleanUp() throws IOException { + Files.walk(Paths.get(sourceFolderLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + if (new File(destinationFolderLocation).exists()) { + Files.walk(Paths.get(destinationFolderLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } + } + +} diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/JavaNioUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/JavaNioUnitTest.java new file mode 100644 index 0000000000..162811912c --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/JavaNioUnitTest.java @@ -0,0 +1,59 @@ +package com.baeldung.copyfolder; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Comparator; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class JavaNioUnitTest { + + private final String sourceFolderLocation = "src/test/resources/sourceFolder"; + private final String subFolderName = "/childFolder"; + private final String fileName = "/file.txt"; + private final String destinationFolderLocation = "src/test/resources/destinationFolder"; + + @BeforeEach + public void createFolderWithSubfolderAndFile() throws IOException { + Files.createDirectories(Paths.get(sourceFolderLocation)); + Files.createDirectories(Paths.get(sourceFolderLocation + subFolderName)); + Files.createFile(Paths.get(sourceFolderLocation + subFolderName + fileName)); + } + + @Test + public void whenSourceFolderExists_thenFolderIsFullyCopied() throws IOException { + JavaNio.copyDirectory(sourceFolderLocation, destinationFolderLocation); + + assertTrue(new File(destinationFolderLocation).exists()); + assertTrue(new File(destinationFolderLocation + subFolderName).exists()); + assertTrue(new File(destinationFolderLocation + subFolderName + fileName).exists()); + } + + @Test + public void whenSourceFolderDoesNotExist_thenExceptionIsThrown() { + assertThrows(IOException.class, () -> JavaNio.copyDirectory("nonExistingFolder", destinationFolderLocation)); + } + + @AfterEach + public void cleanUp() throws IOException { + Files.walk(Paths.get(sourceFolderLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + if (new File(destinationFolderLocation).exists()) { + Files.walk(Paths.get(destinationFolderLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } + } + +} From 0423536cf417fdbd1c380b5ae4b6fb685d6b1b4f Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 28 Jul 2020 06:01:54 +0200 Subject: [PATCH 146/309] JAVA-2113: Split or move spring-resttemplate module (#9753) * JAVA-2113: Move Proxies With RestTemplate to spring-resttemplate-2 * JAVA-2113: Move A Custom Media Type for a Spring REST API to spring-resttemplate-2 * JAVA-2113: Move RestTemplate Post Request with JSON to spring-resttemplate-2 * JAVA-2113: Move Download an Image or a File with Spring MVC to spring-boot-mvc-3 * JAVA-2113: Fix the test --- spring-boot-modules/spring-boot-mvc-3/README.md | 1 + spring-boot-modules/spring-boot-mvc-3/pom.xml | 9 +++++++++ .../baeldung/produceimage/ImageApplication.java | 0 .../controller/DataProducerController.java | 0 spring-resttemplate-2/README.md | 3 +++ .../RestTemplateConfigurationApplication.java | 13 +++++++++++++ .../resttemplate/web/controller/PersonAPI.java | 0 .../baeldung/resttemplate/web/dto/Person.java | 0 .../resttemplate/web/service/PersonService.java | 0 .../web/service/PersonServiceImpl.java | 0 .../baeldung/sampleapp/config/WebConfig.java | 17 +++++++++++++++++ .../mediatypes/CustomMediaTypeController.java | 0 .../sampleapp/web/dto/BaeldungItem.java | 0 .../sampleapp/web/dto/BaeldungItemV2.java | 0 .../postjson/PersonAPILiveTest.java | 0 .../proxy/RequestFactoryLiveTest.java | 0 .../proxy/RestTemplateCustomizerLiveTest.java | 0 ...ustomMediaTypeControllerIntegrationTest.java | 0 .../CustomMediaTypeControllerLiveTest.java | 0 .../web/controller/mediatypes/TestConfig.java | 0 spring-resttemplate/README.md | 5 ----- .../java/com/baeldung/SpringContextTest.java | 4 +--- 22 files changed, 44 insertions(+), 8 deletions(-) rename {spring-resttemplate => spring-boot-modules/spring-boot-mvc-3}/src/main/java/com/baeldung/produceimage/ImageApplication.java (100%) rename {spring-resttemplate => spring-boot-modules/spring-boot-mvc-3}/src/main/java/com/baeldung/produceimage/controller/DataProducerController.java (100%) create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java rename {spring-resttemplate => spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/web/dto/Person.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java (100%) create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/config/WebConfig.java rename {spring-resttemplate => spring-resttemplate-2}/src/main/java/com/baeldung/sampleapp/web/controller/mediatypes/CustomMediaTypeController.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerIntegrationTest.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerLiveTest.java (100%) rename {spring-resttemplate => spring-resttemplate-2}/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java (100%) diff --git a/spring-boot-modules/spring-boot-mvc-3/README.md b/spring-boot-modules/spring-boot-mvc-3/README.md index 58a3008966..0562224337 100644 --- a/spring-boot-modules/spring-boot-mvc-3/README.md +++ b/spring-boot-modules/spring-boot-mvc-3/README.md @@ -5,4 +5,5 @@ This module contains articles about Spring Web MVC in Spring Boot projects. ### Relevant Articles: - [Circular View Path Error](https://www.baeldung.com/spring-circular-view-path-error) +- [Download an Image or a File with Spring MVC](https://www.baeldung.com/spring-controller-return-image-file) - More articles: [[prev -->]](/spring-boot-modules/spring-boot-mvc-2) diff --git a/spring-boot-modules/spring-boot-mvc-3/pom.xml b/spring-boot-modules/spring-boot-mvc-3/pom.xml index 71b7383ef4..31c43461d2 100644 --- a/spring-boot-modules/spring-boot-mvc-3/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-3/pom.xml @@ -26,6 +26,15 @@ org.springframework.boot spring-boot-starter-thymeleaf + + commons-io + commons-io + ${commons-io.version} + + + 2.7 + + \ No newline at end of file diff --git a/spring-resttemplate/src/main/java/com/baeldung/produceimage/ImageApplication.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/produceimage/ImageApplication.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/produceimage/ImageApplication.java rename to spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/produceimage/ImageApplication.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/produceimage/controller/DataProducerController.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/produceimage/controller/DataProducerController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/produceimage/controller/DataProducerController.java rename to spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/produceimage/controller/DataProducerController.java diff --git a/spring-resttemplate-2/README.md b/spring-resttemplate-2/README.md index d7a8a8633a..e1e0ba40b0 100644 --- a/spring-resttemplate-2/README.md +++ b/spring-resttemplate-2/README.md @@ -5,3 +5,6 @@ This module contains articles about Spring RestTemplate ### Relevant Articles: - [Spring RestTemplate Request/Response Logging](https://www.baeldung.com/spring-resttemplate-logging) +- [Proxies With RestTemplate](https://www.baeldung.com/java-resttemplate-proxy) +- [A Custom Media Type for a Spring REST API](https://www.baeldung.com/spring-rest-custom-media-type) +- [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json) diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java new file mode 100644 index 0000000000..8df3c13d7b --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.resttemplate; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RestTemplateConfigurationApplication { + + public static void main(String[] args) { + SpringApplication.run(RestTemplateConfigurationApplication.class, args); + } +} diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java rename to spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Person.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/dto/Person.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Person.java rename to spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/dto/Person.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java rename to spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java rename to spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/config/WebConfig.java b/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/config/WebConfig.java new file mode 100644 index 0000000000..cac12c6978 --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/config/WebConfig.java @@ -0,0 +1,17 @@ +package com.baeldung.sampleapp.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +@EnableWebMvc +@ComponentScan({ "com.baeldung.sampleapp.web" }) +public class WebConfig implements WebMvcConfigurer { + + public WebConfig() { + super(); + } + +} diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/mediatypes/CustomMediaTypeController.java b/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/controller/mediatypes/CustomMediaTypeController.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/mediatypes/CustomMediaTypeController.java rename to spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/controller/mediatypes/CustomMediaTypeController.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java b/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java rename to spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItem.java diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java b/spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java rename to spring-resttemplate-2/src/main/java/com/baeldung/sampleapp/web/dto/BaeldungItemV2.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java b/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java rename to spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java b/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java rename to spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java b/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java rename to spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerIntegrationTest.java b/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerIntegrationTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerIntegrationTest.java rename to spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerIntegrationTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerLiveTest.java b/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerLiveTest.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerLiveTest.java rename to spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/CustomMediaTypeControllerLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java b/spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java similarity index 100% rename from spring-resttemplate/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java rename to spring-resttemplate-2/src/test/java/com/baeldung/web/controller/mediatypes/TestConfig.java diff --git a/spring-resttemplate/README.md b/spring-resttemplate/README.md index bbfda4f6b8..952f35e90b 100644 --- a/spring-resttemplate/README.md +++ b/spring-resttemplate/README.md @@ -11,16 +11,11 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring RestTemplate Error Handling](https://www.baeldung.com/spring-rest-template-error-handling) - [Configure a RestTemplate with RestTemplateBuilder](https://www.baeldung.com/spring-rest-template-builder) - [Mocking a RestTemplate in Spring](https://www.baeldung.com/spring-mock-rest-template) -- [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json) - [Download a Large File Through a Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-download-large-file) - [Using the Spring RestTemplate Interceptor](https://www.baeldung.com/spring-rest-template-interceptor) - [Uploading MultipartFile with Spring RestTemplate](https://www.baeldung.com/spring-rest-template-multipart-upload) - [Get and Post Lists of Objects with RestTemplate](https://www.baeldung.com/spring-rest-template-list) -- [Copy of RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json-test) - [HTTP PUT vs HTTP PATCH in a REST API](https://www.baeldung.com/http-put-patch-difference-spring) -- [A Custom Media Type for a Spring REST API](https://www.baeldung.com/spring-rest-custom-media-type) -- [Download an Image or a File with Spring MVC](https://www.baeldung.com/spring-controller-return-image-file) -- [Proxies With RestTemplate](https://www.baeldung.com/java-resttemplate-proxy) ### NOTE: diff --git a/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java b/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java index 19d5eabd2b..43901cf37f 100644 --- a/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java @@ -5,12 +5,10 @@ import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.produceimage.ImageApplication; import com.baeldung.responseheaders.ResponseHeadersApplication; @RunWith(SpringRunner.class) -@SpringBootTest(classes = { ImageApplication.class, - ResponseHeadersApplication.class, +@SpringBootTest(classes = { ResponseHeadersApplication.class, com.baeldung.web.upload.app.UploadApplication.class, }) public class SpringContextTest { From 784ea2b061cf91622131eb6c0b50d75908f055fe Mon Sep 17 00:00:00 2001 From: Maja Joksovic Date: Tue, 28 Jul 2020 08:26:32 +0200 Subject: [PATCH 147/309] clean-up --- .../ApacheCommons.java | 8 +-- .../CoreOld.java | 12 ++-- .../JavaNio.java | 2 +- .../copydirectory/ApacheCommonsUnitTest.java | 59 +++++++++++++++++ .../copydirectory/CoreOldUnitTest.java | 63 +++++++++++++++++++ .../copydirectory/JavaNioUnitTest.java | 59 +++++++++++++++++ .../copyfolder/ApacheCommonsUnitTest.java | 59 ----------------- .../baeldung/copyfolder/CoreOldUnitTest.java | 63 ------------------- .../baeldung/copyfolder/JavaNioUnitTest.java | 59 ----------------- 9 files changed, 192 insertions(+), 192 deletions(-) rename core-java-modules/core-java-io-3/src/main/java/com/baeldung/{copyfolder => copydirectory}/ApacheCommons.java (51%) rename core-java-modules/core-java-io-3/src/main/java/com/baeldung/{copyfolder => copydirectory}/CoreOld.java (69%) rename core-java-modules/core-java-io-3/src/main/java/com/baeldung/{copyfolder => copydirectory}/JavaNio.java (94%) create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java delete mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/ApacheCommonsUnitTest.java delete mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/CoreOldUnitTest.java delete mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/JavaNioUnitTest.java diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/ApacheCommons.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/ApacheCommons.java similarity index 51% rename from core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/ApacheCommons.java rename to core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/ApacheCommons.java index 67af0594a4..b8aa283b48 100644 --- a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/ApacheCommons.java +++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/ApacheCommons.java @@ -1,4 +1,4 @@ -package com.baeldung.copyfolder; +package com.baeldung.copydirectory; import java.io.File; import java.io.IOException; @@ -8,8 +8,8 @@ import org.apache.commons.io.FileUtils; public class ApacheCommons { public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException { - File sourceFolder = new File(sourceDirectoryLocation); - File destinationFolder = new File(destinationDirectoryLocation); - FileUtils.copyDirectory(sourceFolder, destinationFolder); + File sourceDirectory = new File(sourceDirectoryLocation); + File destinationDirectory = new File(destinationDirectoryLocation); + FileUtils.copyDirectory(sourceDirectory, destinationDirectory); } } diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/CoreOld.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/CoreOld.java similarity index 69% rename from core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/CoreOld.java rename to core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/CoreOld.java index d1a0158db3..2070977534 100644 --- a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/CoreOld.java +++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/CoreOld.java @@ -1,4 +1,4 @@ -package com.baeldung.copyfolder; +package com.baeldung.copydirectory; import java.io.File; import java.io.FileInputStream; @@ -17,12 +17,12 @@ public class CoreOld { } } - private static void copyDirectory(File sourceFolder, File destinationFolder) throws IOException { - if (!destinationFolder.exists()) { - destinationFolder.mkdir(); + private static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException { + if (!destinationDirectory.exists()) { + destinationDirectory.mkdir(); } - for (String f : sourceFolder.list()) { - copyDirectoryJavaUnder7(new File(sourceFolder, f), new File(destinationFolder, f)); + for (String f : sourceDirectory.list()) { + copyDirectoryJavaUnder7(new File(sourceDirectory, f), new File(destinationDirectory, f)); } } diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/JavaNio.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java similarity index 94% rename from core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/JavaNio.java rename to core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java index 368118a943..3f28bf0c9d 100644 --- a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copyfolder/JavaNio.java +++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java @@ -1,4 +1,4 @@ -package com.baeldung.copyfolder; +package com.baeldung.copydirectory; import java.io.IOException; import java.nio.file.Files; diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java new file mode 100644 index 0000000000..3486a9af9d --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java @@ -0,0 +1,59 @@ +package com.baeldung.copydirectory; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Comparator; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ApacheCommonsUnitTest { + + private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory"; + private final String subDirectoryName = "/childDirectory"; + private final String fileName = "/file.txt"; + private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory"; + + @BeforeEach + public void createDirectoryWithSubdirectoryAndFile() throws IOException { + Files.createDirectories(Paths.get(sourceDirectoryLocation)); + Files.createDirectories(Paths.get(sourceDirectoryLocation + subDirectoryName)); + Files.createFile(Paths.get(sourceDirectoryLocation + subDirectoryName + fileName)); + } + + @Test + public void whenSourceDirectoryExists_thenDirectoryIsFullyCopied() throws IOException { + ApacheCommons.copyDirectory(sourceDirectoryLocation, destinationDirectoryLocation); + + assertTrue(new File(destinationDirectoryLocation).exists()); + assertTrue(new File(destinationDirectoryLocation + subDirectoryName).exists()); + assertTrue(new File(destinationDirectoryLocation + subDirectoryName + fileName).exists()); + } + + @Test + public void whenSourceDirectoryDoesNotExist_thenExceptionIsThrown() { + assertThrows(Exception.class, () -> ApacheCommons.copyDirectory("nonExistingDirectory", destinationDirectoryLocation)); + } + + @AfterEach + public void cleanUp() throws IOException { + Files.walk(Paths.get(sourceDirectoryLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + if (new File(destinationDirectoryLocation).exists()) { + Files.walk(Paths.get(destinationDirectoryLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } + } + +} diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java new file mode 100644 index 0000000000..53ae216399 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.copydirectory; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Comparator; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class CoreOldUnitTest { + + private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory"; + private final String subDirectoryName = "/childDirectory"; + private final String fileName = "/file.txt"; + private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory"; + + @BeforeEach + public void createDirectoryWithSubdirectoryAndFile() throws IOException { + Files.createDirectories(Paths.get(sourceDirectoryLocation)); + Files.createDirectories(Paths.get(sourceDirectoryLocation + subDirectoryName)); + Files.createFile(Paths.get(sourceDirectoryLocation + subDirectoryName + fileName)); + } + + @Test + public void whenSourceDirectoryExists_thenDirectoryIsFullyCopied() throws IOException { + File sourceDirectory = new File(sourceDirectoryLocation); + File destinationDirectory = new File(destinationDirectoryLocation); + CoreOld.copyDirectoryJavaUnder7(sourceDirectory, destinationDirectory); + + assertTrue(new File(destinationDirectoryLocation).exists()); + assertTrue(new File(destinationDirectoryLocation + subDirectoryName).exists()); + assertTrue(new File(destinationDirectoryLocation + subDirectoryName + fileName).exists()); + } + + @Test + public void whenSourceDirectoryDoesNotExist_thenExceptionIsThrown() throws IOException { + File sourceDirectory = new File("nonExistingDirectory"); + File destinationDirectory = new File(destinationDirectoryLocation); + assertThrows(IOException.class, () -> CoreOld.copyDirectoryJavaUnder7(sourceDirectory, destinationDirectory)); + } + + @AfterEach + public void cleanUp() throws IOException { + Files.walk(Paths.get(sourceDirectoryLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + if (new File(destinationDirectoryLocation).exists()) { + Files.walk(Paths.get(destinationDirectoryLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } + } + +} diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java new file mode 100644 index 0000000000..8d1eea53c9 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java @@ -0,0 +1,59 @@ +package com.baeldung.copydirectory; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Comparator; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class JavaNioUnitTest { + + private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory"; + private final String subDirectoryName = "/childDirectory"; + private final String fileName = "/file.txt"; + private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory"; + + @BeforeEach + public void createDirectoryWithSubdirectoryAndFile() throws IOException { + Files.createDirectories(Paths.get(sourceDirectoryLocation)); + Files.createDirectories(Paths.get(sourceDirectoryLocation + subDirectoryName)); + Files.createFile(Paths.get(sourceDirectoryLocation + subDirectoryName + fileName)); + } + + @Test + public void whenSourceDirectoryExists_thenDirectoryIsFullyCopied() throws IOException { + JavaNio.copyDirectory(sourceDirectoryLocation, destinationDirectoryLocation); + + assertTrue(new File(destinationDirectoryLocation).exists()); + assertTrue(new File(destinationDirectoryLocation + subDirectoryName).exists()); + assertTrue(new File(destinationDirectoryLocation + subDirectoryName + fileName).exists()); + } + + @Test + public void whenSourceDirectoryDoesNotExist_thenExceptionIsThrown() { + assertThrows(IOException.class, () -> JavaNio.copyDirectory("nonExistingDirectory", destinationDirectoryLocation)); + } + + @AfterEach + public void cleanUp() throws IOException { + Files.walk(Paths.get(sourceDirectoryLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + if (new File(destinationDirectoryLocation).exists()) { + Files.walk(Paths.get(destinationDirectoryLocation)) + .sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } + } + +} diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/ApacheCommonsUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/ApacheCommonsUnitTest.java deleted file mode 100644 index 71e4c52104..0000000000 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/ApacheCommonsUnitTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.baeldung.copyfolder; - -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Comparator; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class ApacheCommonsUnitTest { - - private final String sourceFolderLocation = "src/test/resources/sourceFolder"; - private final String subFolderName = "/childFolder"; - private final String fileName = "/file.txt"; - private final String destinationFolderLocation = "src/test/resources/destinationFolder"; - - @BeforeEach - public void createFolderWithSubfolderAndFile() throws IOException { - Files.createDirectories(Paths.get(sourceFolderLocation)); - Files.createDirectories(Paths.get(sourceFolderLocation + subFolderName)); - Files.createFile(Paths.get(sourceFolderLocation + subFolderName + fileName)); - } - - @Test - public void whenSourceFolderExists_thenFolderIsFullyCopied() throws IOException { - ApacheCommons.copyDirectory(sourceFolderLocation, destinationFolderLocation); - - assertTrue(new File(destinationFolderLocation).exists()); - assertTrue(new File(destinationFolderLocation + subFolderName).exists()); - assertTrue(new File(destinationFolderLocation + subFolderName + fileName).exists()); - } - - @Test - public void whenSourceFolderDoesNotExist_thenExceptionIsThrown() { - assertThrows(Exception.class, () -> ApacheCommons.copyDirectory("nonExistingFolder", destinationFolderLocation)); - } - - @AfterEach - public void cleanUp() throws IOException { - Files.walk(Paths.get(sourceFolderLocation)) - .sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - if (new File(destinationFolderLocation).exists()) { - Files.walk(Paths.get(destinationFolderLocation)) - .sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - } - } - -} diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/CoreOldUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/CoreOldUnitTest.java deleted file mode 100644 index ba45fd3cd0..0000000000 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/CoreOldUnitTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.baeldung.copyfolder; - -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Comparator; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class CoreOldUnitTest { - - private final String sourceFolderLocation = "src/test/resources/sourceFolder"; - private final String subFolderName = "/childFolder"; - private final String fileName = "/file.txt"; - private final String destinationFolderLocation = "src/test/resources/destinationFolder"; - - @BeforeEach - public void createFolderWithSubfolderAndFile() throws IOException { - Files.createDirectories(Paths.get(sourceFolderLocation)); - Files.createDirectories(Paths.get(sourceFolderLocation + subFolderName)); - Files.createFile(Paths.get(sourceFolderLocation + subFolderName + fileName)); - } - - @Test - public void whenSourceFolderExists_thenFolderIsFullyCopied() throws IOException { - File sourceFolder = new File(sourceFolderLocation); - File destinationFolder = new File(destinationFolderLocation); - CoreOld.copyDirectoryJavaUnder7(sourceFolder, destinationFolder); - - assertTrue(new File(destinationFolderLocation).exists()); - assertTrue(new File(destinationFolderLocation + subFolderName).exists()); - assertTrue(new File(destinationFolderLocation + subFolderName + fileName).exists()); - } - - @Test - public void whenSourceFolderDoesNotExist_thenExceptionIsThrown() throws IOException { - File sourceFolder = new File("nonExistingFolder"); - File destinationFolder = new File(destinationFolderLocation); - assertThrows(IOException.class, () -> CoreOld.copyDirectoryJavaUnder7(sourceFolder, destinationFolder)); - } - - @AfterEach - public void cleanUp() throws IOException { - Files.walk(Paths.get(sourceFolderLocation)) - .sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - if (new File(destinationFolderLocation).exists()) { - Files.walk(Paths.get(destinationFolderLocation)) - .sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - } - } - -} diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/JavaNioUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/JavaNioUnitTest.java deleted file mode 100644 index 162811912c..0000000000 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copyfolder/JavaNioUnitTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.baeldung.copyfolder; - -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Comparator; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class JavaNioUnitTest { - - private final String sourceFolderLocation = "src/test/resources/sourceFolder"; - private final String subFolderName = "/childFolder"; - private final String fileName = "/file.txt"; - private final String destinationFolderLocation = "src/test/resources/destinationFolder"; - - @BeforeEach - public void createFolderWithSubfolderAndFile() throws IOException { - Files.createDirectories(Paths.get(sourceFolderLocation)); - Files.createDirectories(Paths.get(sourceFolderLocation + subFolderName)); - Files.createFile(Paths.get(sourceFolderLocation + subFolderName + fileName)); - } - - @Test - public void whenSourceFolderExists_thenFolderIsFullyCopied() throws IOException { - JavaNio.copyDirectory(sourceFolderLocation, destinationFolderLocation); - - assertTrue(new File(destinationFolderLocation).exists()); - assertTrue(new File(destinationFolderLocation + subFolderName).exists()); - assertTrue(new File(destinationFolderLocation + subFolderName + fileName).exists()); - } - - @Test - public void whenSourceFolderDoesNotExist_thenExceptionIsThrown() { - assertThrows(IOException.class, () -> JavaNio.copyDirectory("nonExistingFolder", destinationFolderLocation)); - } - - @AfterEach - public void cleanUp() throws IOException { - Files.walk(Paths.get(sourceFolderLocation)) - .sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - if (new File(destinationFolderLocation).exists()) { - Files.walk(Paths.get(destinationFolderLocation)) - .sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - } - } - -} From 000ce564ffe3e9191285d56854b23b8b4ea9455e Mon Sep 17 00:00:00 2001 From: Maja Joksovic Date: Tue, 28 Jul 2020 10:03:46 +0200 Subject: [PATCH 148/309] changed variable names --- .../src/main/java/com/baeldung/copydirectory/JavaNio.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java index 3f28bf0c9d..fe1eb59c64 100644 --- a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java +++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java @@ -9,11 +9,11 @@ public class JavaNio { public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException { Files.walk(Paths.get(sourceDirectoryLocation)) - .forEach(a -> { - Path b = Paths.get(destinationDirectoryLocation, a.toString() + .forEach(source -> { + Path destination = Paths.get(destinationDirectoryLocation, source.toString() .substring(sourceDirectoryLocation.length())); try { - Files.copy(a, b); + Files.copy(source, destination); } catch (IOException e) { e.printStackTrace(); } From 0cade733ca1f44f2d726dff8290708820fbd3ccd Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Tue, 28 Jul 2020 17:34:46 +0530 Subject: [PATCH 149/309] JAVA-2154: Create guava-parent module and organize guava modules (#9782) * JAVA-2154: Removed module, now split into guava-utilities and guava-core * JAVA-2154: Removed module, articles moved to new module guava-core * JAVA-2154: Moved module inside guava-modules * JAVA-2154: Moved module inside guava-modules * JAVA-2154: Moved module inside guava-modules * JAVA-2154: Moved module inside guava-modules * JAVA-2154: Moved 1 article to guava-collections * JAVA-2154: New module guava-collections-list * JAVA-2154: New module guava-core * JAVA-2154: New module guava-utilities * JAVA-2154: Updated README, removed extra article reference * JAVA-2154: parent module pom changes * JAVA-2154: main pom changes - removed guava related modules as they have been shifted inside guava-modules * JAVA-2154: rearranged and moved module inside guava-modules folder --- guava-2/README.md | 7 -- guava-modules/guava-18/README.md | 5 +- guava-modules/guava-19/README.md | 2 - guava-modules/guava-21/README.md | 4 +- guava-modules/guava-21/pom.xml | 9 -- .../guava-collections-list/README.md | 8 ++ .../guava-collections-list}/pom.xml | 8 +- .../src/main/resources/logback.xml | 0 .../guava/lists/GuavaListsUnitTest.java | 0 .../CollectionApachePartitionUnitTest.java | 0 .../CollectionGuavaPartitionUnitTest.java | 0 .../CollectionJavaPartitionUnitTest.java | 0 .../guava-collections-map}/README.md | 0 .../guava-collections-map}/pom.xml | 4 +- .../com/baeldung/guava/mapmaker/Profile.java | 0 .../com/baeldung/guava/mapmaker/Session.java | 0 .../com/baeldung/guava/mapmaker/User.java | 0 .../ClassToInstanceMapUnitTest.java | 0 .../GuavaMapInitializeUnitTest.java | 0 .../guava/mapmaker/GuavaMapMakerUnitTest.java | 0 .../guava/maps/GuavaMapsUnitTest.java | 0 .../guava/multimap/GuavaMultiMapUnitTest.java | 0 .../guava/rangemap/GuavaRangeMapUnitTest.java | 0 .../guava-collections-set}/.gitignore | 0 .../guava-collections-set}/README.md | 0 .../guava-collections-set}/pom.xml | 4 +- .../com/baeldung/guava/GuavaMapFromSet.java | 0 .../guava/GuavaMapFromSetUnitTest.java | 0 .../baeldung/guava/GuavaMultiSetUnitTest.java | 0 .../baeldung/guava/GuavaRangeSetUnitTest.java | 0 .../guava/GuavaSetOperationsUnitTest.java | 0 .../guava-collections}/README.md | 3 +- guava-modules/guava-collections/pom.xml | 95 ++++++++++++++++++ .../src/main/resources/logback.xml | 0 .../GuavaCollectionsExamplesUnitTest.java | 0 ...avaFilterTransformCollectionsUnitTest.java | 0 .../guava/joinsplit/GuavaStringUnitTest.java | 0 .../GuavaOrderingExamplesUnitTest.java | 0 .../guava/ordering/GuavaOrderingUnitTest.java | 0 .../guava/queues/EvictingQueueUnitTest.java | 0 .../queues/MinMaxPriorityQueueUnitTest.java | 0 .../guava/table/GuavaTableUnitTest.java | 0 .../guava/zip/ZipCollectionUnitTest.java | 0 .../hamcrest/HamcrestExamplesUnitTest.java | 0 .../src/test/resources/test.out | 0 .../src/test/resources/test1.in | 0 .../src/test/resources/test1_1.in | 0 .../src/test/resources/test2.in | 0 .../src/test/resources/test_copy.in | 0 .../src/test/resources/test_le.txt | Bin guava-modules/guava-core/README.md | 10 ++ {guava-2 => guava-modules/guava-core}/pom.xml | 8 +- .../guava/memoizer/CostlySupplier.java | 0 .../baeldung/guava/memoizer/Factorial.java | 0 .../guava/memoizer/FibonacciSequence.java | 0 .../charmatcher/GuavaCharMatcherUnitTest.java | 0 .../GuavaFunctionalExamplesUnitTest.java | 2 +- .../memoizer}/GuavaMemoizerUnitTest.java | 2 +- .../GuavaPreConditionsUnitTest.java | 2 +- .../guava/throwables/ThrowablesUnitTest.java | 0 .../guava-core/src/test/resources}/.gitignore | 0 .../guava-core}/src/test/resources/test.out | 0 .../guava-core}/src/test/resources/test1.in | 0 .../guava-core}/src/test/resources/test1_1.in | 0 .../guava-core}/src/test/resources/test2.in | 0 .../src/test/resources/test_copy.in | 0 .../src/test/resources/test_le.txt | Bin .../guava-io}/README.md | 0 {guava-io => guava-modules/guava-io}/pom.xml | 4 +- .../GuavaCountingOutputStreamUnitTest.java | 0 .../com/baeldung/guava/GuavaIOUnitTest.java | 0 .../guava-io}/src/test/resources/test1.in | 0 .../guava-io}/src/test/resources/test1_1.in | 0 .../guava-io}/src/test/resources/test2.in | 0 .../guava-utilities}/.gitignore | 0 .../guava-utilities}/README.md | 9 +- .../guava-utilities}/pom.xml | 8 +- .../baeldung/guava/eventbus}/CustomEvent.java | 2 +- .../guava/eventbus}/EventListener.java | 2 +- .../src/main/resources/logback.xml | 19 ++++ .../bloomfilter}/BloomFilterUnitTest.java | 2 +- .../guava/cache}/GuavaCacheUnitTest.java | 2 +- .../GuavaCacheLoaderUnitTest.java | 2 +- .../eventbus}/GuavaEventBusUnitTest.java | 4 +- .../GuavaBigIntegerMathUnitTest.java | 2 +- .../mathutils}/GuavaDoubleMathUnitTest.java | 2 +- .../mathutils}/GuavaIntMathUnitTest.java | 2 +- .../mathutils}/GuavaLongMathUnitTest.java | 2 +- .../guava/mathutils}/GuavaMathUnitTest.java | 2 +- .../RateLimiterLongRunningUnitTest.java | 2 +- .../GuavaReflectionUtilsUnitTest.java | 2 +- .../src/test/resources/.gitignore | 0 .../src/test/resources/test.out | 0 .../src/test/resources/test1.in | 0 .../src/test/resources/test1_1.in | 0 .../src/test/resources/test2.in | 0 .../src/test/resources/test_copy.in | 0 .../src/test/resources/test_le.txt | Bin guava-modules/pom.xml | 7 ++ pom.xml | 15 +-- 100 files changed, 184 insertions(+), 79 deletions(-) delete mode 100644 guava-2/README.md create mode 100644 guava-modules/guava-collections-list/README.md rename {guava-collections => guava-modules/guava-collections-list}/pom.xml (93%) rename {guava-collections => guava-modules/guava-collections-list}/src/main/resources/logback.xml (100%) rename {guava-collections => guava-modules/guava-collections-list}/src/test/java/com/baeldung/guava/lists/GuavaListsUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections-list}/src/test/java/com/baeldung/guava/partition/CollectionApachePartitionUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections-list}/src/test/java/com/baeldung/guava/partition/CollectionGuavaPartitionUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections-list}/src/test/java/com/baeldung/guava/partition/CollectionJavaPartitionUnitTest.java (100%) rename {guava-collections-map => guava-modules/guava-collections-map}/README.md (100%) rename {guava-collections-map => guava-modules/guava-collections-map}/pom.xml (94%) rename {guava-collections-map => guava-modules/guava-collections-map}/src/main/java/com/baeldung/guava/mapmaker/Profile.java (100%) rename {guava-collections-map => guava-modules/guava-collections-map}/src/main/java/com/baeldung/guava/mapmaker/Session.java (100%) rename {guava-collections-map => guava-modules/guava-collections-map}/src/main/java/com/baeldung/guava/mapmaker/User.java (100%) rename {guava-collections-map => guava-modules/guava-collections-map}/src/test/java/com/baeldung/guava/classtoinstancemap/ClassToInstanceMapUnitTest.java (100%) rename {guava-collections-map => guava-modules/guava-collections-map}/src/test/java/com/baeldung/guava/initializemaps/GuavaMapInitializeUnitTest.java (100%) rename {guava-collections-map => guava-modules/guava-collections-map}/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java (100%) rename {guava-collections-map => guava-modules/guava-collections-map}/src/test/java/com/baeldung/guava/maps/GuavaMapsUnitTest.java (100%) rename {guava-collections-map => guava-modules/guava-collections-map}/src/test/java/com/baeldung/guava/multimap/GuavaMultiMapUnitTest.java (100%) rename {guava-collections-map => guava-modules/guava-collections-map}/src/test/java/com/baeldung/guava/rangemap/GuavaRangeMapUnitTest.java (100%) rename {guava-2/src/test/resources => guava-modules/guava-collections-set}/.gitignore (100%) rename {guava-collections-set => guava-modules/guava-collections-set}/README.md (100%) rename {guava-collections-set => guava-modules/guava-collections-set}/pom.xml (94%) rename {guava-collections-set => guava-modules/guava-collections-set}/src/test/java/com/baeldung/guava/GuavaMapFromSet.java (100%) rename {guava-collections-set => guava-modules/guava-collections-set}/src/test/java/com/baeldung/guava/GuavaMapFromSetUnitTest.java (100%) rename {guava-collections-set => guava-modules/guava-collections-set}/src/test/java/com/baeldung/guava/GuavaMultiSetUnitTest.java (100%) rename {guava-collections-set => guava-modules/guava-collections-set}/src/test/java/com/baeldung/guava/GuavaRangeSetUnitTest.java (100%) rename {guava-collections-set => guava-modules/guava-collections-set}/src/test/java/com/baeldung/guava/GuavaSetOperationsUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections}/README.md (86%) create mode 100644 guava-modules/guava-collections/pom.xml rename {guava => guava-modules/guava-collections}/src/main/resources/logback.xml (100%) rename {guava-collections => guava-modules/guava-collections}/src/test/java/com/baeldung/guava/collections/GuavaCollectionsExamplesUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections}/src/test/java/com/baeldung/guava/filtertransform/GuavaFilterTransformCollectionsUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections}/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections}/src/test/java/com/baeldung/guava/ordering/GuavaOrderingExamplesUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections}/src/test/java/com/baeldung/guava/ordering/GuavaOrderingUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections}/src/test/java/com/baeldung/guava/queues/EvictingQueueUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections}/src/test/java/com/baeldung/guava/queues/MinMaxPriorityQueueUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections}/src/test/java/com/baeldung/guava/table/GuavaTableUnitTest.java (100%) rename guava-modules/{guava-21 => guava-collections}/src/test/java/com/baeldung/guava/zip/ZipCollectionUnitTest.java (100%) rename {guava-collections => guava-modules/guava-collections}/src/test/java/com/baeldung/hamcrest/HamcrestExamplesUnitTest.java (100%) rename {guava-2 => guava-modules/guava-collections}/src/test/resources/test.out (100%) rename {guava-2 => guava-modules/guava-collections}/src/test/resources/test1.in (100%) rename {guava-2 => guava-modules/guava-collections}/src/test/resources/test1_1.in (100%) rename {guava-2 => guava-modules/guava-collections}/src/test/resources/test2.in (100%) rename {guava-2 => guava-modules/guava-collections}/src/test/resources/test_copy.in (100%) rename {guava-2 => guava-modules/guava-collections}/src/test/resources/test_le.txt (100%) create mode 100644 guava-modules/guava-core/README.md rename {guava-2 => guava-modules/guava-core}/pom.xml (89%) rename {guava => guava-modules/guava-core}/src/main/java/com/baeldung/guava/memoizer/CostlySupplier.java (100%) rename {guava => guava-modules/guava-core}/src/main/java/com/baeldung/guava/memoizer/Factorial.java (100%) rename {guava => guava-modules/guava-core}/src/main/java/com/baeldung/guava/memoizer/FibonacciSequence.java (100%) rename {guava-2 => guava-modules/guava-core}/src/test/java/com/baeldung/guava/charmatcher/GuavaCharMatcherUnitTest.java (100%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-core/src/test/java/com/baeldung/guava/functional}/GuavaFunctionalExamplesUnitTest.java (99%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-core/src/test/java/com/baeldung/guava/memoizer}/GuavaMemoizerUnitTest.java (98%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-core/src/test/java/com/baeldung/guava/preconditions}/GuavaPreConditionsUnitTest.java (99%) rename {guava-2 => guava-modules/guava-core}/src/test/java/com/baeldung/guava/throwables/ThrowablesUnitTest.java (100%) rename {guava-collections-set => guava-modules/guava-core/src/test/resources}/.gitignore (100%) rename {guava-collections => guava-modules/guava-core}/src/test/resources/test.out (100%) rename {guava-collections => guava-modules/guava-core}/src/test/resources/test1.in (100%) rename {guava-collections => guava-modules/guava-core}/src/test/resources/test1_1.in (100%) rename {guava-collections => guava-modules/guava-core}/src/test/resources/test2.in (100%) rename {guava-collections => guava-modules/guava-core}/src/test/resources/test_copy.in (100%) rename {guava-collections => guava-modules/guava-core}/src/test/resources/test_le.txt (100%) rename {guava-io => guava-modules/guava-io}/README.md (100%) rename {guava-io => guava-modules/guava-io}/pom.xml (94%) rename {guava-io => guava-modules/guava-io}/src/test/java/com/baeldung/guava/GuavaCountingOutputStreamUnitTest.java (100%) rename {guava-io => guava-modules/guava-io}/src/test/java/com/baeldung/guava/GuavaIOUnitTest.java (100%) rename {guava-io => guava-modules/guava-io}/src/test/resources/test1.in (100%) rename {guava-io => guava-modules/guava-io}/src/test/resources/test1_1.in (100%) rename {guava-io => guava-modules/guava-io}/src/test/resources/test2.in (100%) rename {guava => guava-modules/guava-utilities}/.gitignore (100%) rename {guava => guava-modules/guava-utilities}/README.md (60%) rename {guava => guava-modules/guava-utilities}/pom.xml (92%) rename {guava/src/main/java/com/baeldung/guava => guava-modules/guava-utilities/src/main/java/com/baeldung/guava/eventbus}/CustomEvent.java (87%) rename {guava/src/main/java/com/baeldung/guava => guava-modules/guava-utilities/src/main/java/com/baeldung/guava/eventbus}/EventListener.java (96%) create mode 100644 guava-modules/guava-utilities/src/main/resources/logback.xml rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/bloomfilter}/BloomFilterUnitTest.java (97%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/cache}/GuavaCacheUnitTest.java (99%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/cacheloader}/GuavaCacheLoaderUnitTest.java (98%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/eventbus}/GuavaEventBusUnitTest.java (90%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils}/GuavaBigIntegerMathUnitTest.java (99%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils}/GuavaDoubleMathUnitTest.java (98%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils}/GuavaIntMathUnitTest.java (99%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils}/GuavaLongMathUnitTest.java (99%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils}/GuavaMathUnitTest.java (99%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/ratelimiter}/RateLimiterLongRunningUnitTest.java (98%) rename {guava/src/test/java/com/baeldung/guava => guava-modules/guava-utilities/src/test/java/com/baeldung/guava/reflectionutils}/GuavaReflectionUtilsUnitTest.java (99%) rename {guava => guava-modules/guava-utilities}/src/test/resources/.gitignore (100%) rename {guava => guava-modules/guava-utilities}/src/test/resources/test.out (100%) rename {guava => guava-modules/guava-utilities}/src/test/resources/test1.in (100%) rename {guava => guava-modules/guava-utilities}/src/test/resources/test1_1.in (100%) rename {guava => guava-modules/guava-utilities}/src/test/resources/test2.in (100%) rename {guava => guava-modules/guava-utilities}/src/test/resources/test_copy.in (100%) rename {guava => guava-modules/guava-utilities}/src/test/resources/test_le.txt (100%) diff --git a/guava-2/README.md b/guava-2/README.md deleted file mode 100644 index 32afc10916..0000000000 --- a/guava-2/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Guava - -This module contains articles a Google Guava - -### Relevant Articles: - -- [Guava CharMatcher](https://www.baeldung.com/guava-string-charmatcher) diff --git a/guava-modules/guava-18/README.md b/guava-modules/guava-18/README.md index fd5de4170a..bdd289b86f 100644 --- a/guava-modules/guava-18/README.md +++ b/guava-modules/guava-18/README.md @@ -1,8 +1,5 @@ -========= - -## Guava and Hamcrest Cookbooks and Examples +## Guava 18 ### Relevant Articles: -- [Guava Functional Cookbook](http://www.baeldung.com/guava-functions-predicates) - [Guava 18: What’s New?](http://www.baeldung.com/whats-new-in-guava-18) diff --git a/guava-modules/guava-19/README.md b/guava-modules/guava-19/README.md index be9f2d72a4..6508410ba2 100644 --- a/guava-modules/guava-19/README.md +++ b/guava-modules/guava-19/README.md @@ -1,5 +1,3 @@ -========= - ## Guava 19 diff --git a/guava-modules/guava-21/README.md b/guava-modules/guava-21/README.md index 4e897325b6..ad70a180b0 100644 --- a/guava-modules/guava-21/README.md +++ b/guava-modules/guava-21/README.md @@ -1,4 +1,6 @@ +## Guava 21 + ### Relevant articles: + - [New Stream, Comparator and Collector in Guava 21](http://www.baeldung.com/guava-21-new) - [New in Guava 21 common.util.concurrent](http://www.baeldung.com/guava-21-util-concurrent) -- [Zipping Collections in Java](http://www.baeldung.com/java-collections-zip) diff --git a/guava-modules/guava-21/pom.xml b/guava-modules/guava-21/pom.xml index b126df99cb..b793f11a7f 100644 --- a/guava-modules/guava-21/pom.xml +++ b/guava-modules/guava-21/pom.xml @@ -13,17 +13,8 @@ ../ - - - org.jooq - jool - ${jool.version} - - - 21.0 - 0.9.12 \ No newline at end of file diff --git a/guava-modules/guava-collections-list/README.md b/guava-modules/guava-collections-list/README.md new file mode 100644 index 0000000000..d7f9ce2e32 --- /dev/null +++ b/guava-modules/guava-collections-list/README.md @@ -0,0 +1,8 @@ +## Guava Collections List examples + +This module contains articles about list collections in Guava + +### Relevant Articles: + +- [Partition a List in Java](https://www.baeldung.com/java-list-split) +- [Guava – Lists](https://www.baeldung.com/guava-lists) \ No newline at end of file diff --git a/guava-collections/pom.xml b/guava-modules/guava-collections-list/pom.xml similarity index 93% rename from guava-collections/pom.xml rename to guava-modules/guava-collections-list/pom.xml index 238ab60f84..cc52a5d48b 100644 --- a/guava-collections/pom.xml +++ b/guava-modules/guava-collections-list/pom.xml @@ -4,15 +4,15 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - guava-collections + guava-collections-list 0.1.0-SNAPSHOT - guava-collections + guava-collections-list com.baeldung - parent-java + guava-modules 0.0.1-SNAPSHOT - ../parent-java + ../ diff --git a/guava-collections/src/main/resources/logback.xml b/guava-modules/guava-collections-list/src/main/resources/logback.xml similarity index 100% rename from guava-collections/src/main/resources/logback.xml rename to guava-modules/guava-collections-list/src/main/resources/logback.xml diff --git a/guava-collections/src/test/java/com/baeldung/guava/lists/GuavaListsUnitTest.java b/guava-modules/guava-collections-list/src/test/java/com/baeldung/guava/lists/GuavaListsUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/lists/GuavaListsUnitTest.java rename to guava-modules/guava-collections-list/src/test/java/com/baeldung/guava/lists/GuavaListsUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/guava/partition/CollectionApachePartitionUnitTest.java b/guava-modules/guava-collections-list/src/test/java/com/baeldung/guava/partition/CollectionApachePartitionUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/partition/CollectionApachePartitionUnitTest.java rename to guava-modules/guava-collections-list/src/test/java/com/baeldung/guava/partition/CollectionApachePartitionUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/guava/partition/CollectionGuavaPartitionUnitTest.java b/guava-modules/guava-collections-list/src/test/java/com/baeldung/guava/partition/CollectionGuavaPartitionUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/partition/CollectionGuavaPartitionUnitTest.java rename to guava-modules/guava-collections-list/src/test/java/com/baeldung/guava/partition/CollectionGuavaPartitionUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/guava/partition/CollectionJavaPartitionUnitTest.java b/guava-modules/guava-collections-list/src/test/java/com/baeldung/guava/partition/CollectionJavaPartitionUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/partition/CollectionJavaPartitionUnitTest.java rename to guava-modules/guava-collections-list/src/test/java/com/baeldung/guava/partition/CollectionJavaPartitionUnitTest.java diff --git a/guava-collections-map/README.md b/guava-modules/guava-collections-map/README.md similarity index 100% rename from guava-collections-map/README.md rename to guava-modules/guava-collections-map/README.md diff --git a/guava-collections-map/pom.xml b/guava-modules/guava-collections-map/pom.xml similarity index 94% rename from guava-collections-map/pom.xml rename to guava-modules/guava-collections-map/pom.xml index 4a95234d5c..82d634265b 100644 --- a/guava-collections-map/pom.xml +++ b/guava-modules/guava-collections-map/pom.xml @@ -9,9 +9,9 @@ com.baeldung - parent-java + guava-modules 0.0.1-SNAPSHOT - ../parent-java + ../ diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Profile.java b/guava-modules/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Profile.java similarity index 100% rename from guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Profile.java rename to guava-modules/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Profile.java diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Session.java b/guava-modules/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Session.java similarity index 100% rename from guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Session.java rename to guava-modules/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Session.java diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/User.java b/guava-modules/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/User.java similarity index 100% rename from guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/User.java rename to guava-modules/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/User.java diff --git a/guava-collections-map/src/test/java/com/baeldung/guava/classtoinstancemap/ClassToInstanceMapUnitTest.java b/guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/classtoinstancemap/ClassToInstanceMapUnitTest.java similarity index 100% rename from guava-collections-map/src/test/java/com/baeldung/guava/classtoinstancemap/ClassToInstanceMapUnitTest.java rename to guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/classtoinstancemap/ClassToInstanceMapUnitTest.java diff --git a/guava-collections-map/src/test/java/com/baeldung/guava/initializemaps/GuavaMapInitializeUnitTest.java b/guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/initializemaps/GuavaMapInitializeUnitTest.java similarity index 100% rename from guava-collections-map/src/test/java/com/baeldung/guava/initializemaps/GuavaMapInitializeUnitTest.java rename to guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/initializemaps/GuavaMapInitializeUnitTest.java diff --git a/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java b/guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java similarity index 100% rename from guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java rename to guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java diff --git a/guava-collections-map/src/test/java/com/baeldung/guava/maps/GuavaMapsUnitTest.java b/guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/maps/GuavaMapsUnitTest.java similarity index 100% rename from guava-collections-map/src/test/java/com/baeldung/guava/maps/GuavaMapsUnitTest.java rename to guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/maps/GuavaMapsUnitTest.java diff --git a/guava-collections-map/src/test/java/com/baeldung/guava/multimap/GuavaMultiMapUnitTest.java b/guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/multimap/GuavaMultiMapUnitTest.java similarity index 100% rename from guava-collections-map/src/test/java/com/baeldung/guava/multimap/GuavaMultiMapUnitTest.java rename to guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/multimap/GuavaMultiMapUnitTest.java diff --git a/guava-collections-map/src/test/java/com/baeldung/guava/rangemap/GuavaRangeMapUnitTest.java b/guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/rangemap/GuavaRangeMapUnitTest.java similarity index 100% rename from guava-collections-map/src/test/java/com/baeldung/guava/rangemap/GuavaRangeMapUnitTest.java rename to guava-modules/guava-collections-map/src/test/java/com/baeldung/guava/rangemap/GuavaRangeMapUnitTest.java diff --git a/guava-2/src/test/resources/.gitignore b/guava-modules/guava-collections-set/.gitignore similarity index 100% rename from guava-2/src/test/resources/.gitignore rename to guava-modules/guava-collections-set/.gitignore diff --git a/guava-collections-set/README.md b/guava-modules/guava-collections-set/README.md similarity index 100% rename from guava-collections-set/README.md rename to guava-modules/guava-collections-set/README.md diff --git a/guava-collections-set/pom.xml b/guava-modules/guava-collections-set/pom.xml similarity index 94% rename from guava-collections-set/pom.xml rename to guava-modules/guava-collections-set/pom.xml index af46400555..8f58148e41 100644 --- a/guava-collections-set/pom.xml +++ b/guava-modules/guava-collections-set/pom.xml @@ -8,9 +8,9 @@ com.baeldung - parent-java + guava-modules 0.0.1-SNAPSHOT - ../parent-java + ../ diff --git a/guava-collections-set/src/test/java/com/baeldung/guava/GuavaMapFromSet.java b/guava-modules/guava-collections-set/src/test/java/com/baeldung/guava/GuavaMapFromSet.java similarity index 100% rename from guava-collections-set/src/test/java/com/baeldung/guava/GuavaMapFromSet.java rename to guava-modules/guava-collections-set/src/test/java/com/baeldung/guava/GuavaMapFromSet.java diff --git a/guava-collections-set/src/test/java/com/baeldung/guava/GuavaMapFromSetUnitTest.java b/guava-modules/guava-collections-set/src/test/java/com/baeldung/guava/GuavaMapFromSetUnitTest.java similarity index 100% rename from guava-collections-set/src/test/java/com/baeldung/guava/GuavaMapFromSetUnitTest.java rename to guava-modules/guava-collections-set/src/test/java/com/baeldung/guava/GuavaMapFromSetUnitTest.java diff --git a/guava-collections-set/src/test/java/com/baeldung/guava/GuavaMultiSetUnitTest.java b/guava-modules/guava-collections-set/src/test/java/com/baeldung/guava/GuavaMultiSetUnitTest.java similarity index 100% rename from guava-collections-set/src/test/java/com/baeldung/guava/GuavaMultiSetUnitTest.java rename to guava-modules/guava-collections-set/src/test/java/com/baeldung/guava/GuavaMultiSetUnitTest.java diff --git a/guava-collections-set/src/test/java/com/baeldung/guava/GuavaRangeSetUnitTest.java b/guava-modules/guava-collections-set/src/test/java/com/baeldung/guava/GuavaRangeSetUnitTest.java similarity index 100% rename from guava-collections-set/src/test/java/com/baeldung/guava/GuavaRangeSetUnitTest.java rename to guava-modules/guava-collections-set/src/test/java/com/baeldung/guava/GuavaRangeSetUnitTest.java diff --git a/guava-collections-set/src/test/java/com/baeldung/guava/GuavaSetOperationsUnitTest.java b/guava-modules/guava-collections-set/src/test/java/com/baeldung/guava/GuavaSetOperationsUnitTest.java similarity index 100% rename from guava-collections-set/src/test/java/com/baeldung/guava/GuavaSetOperationsUnitTest.java rename to guava-modules/guava-collections-set/src/test/java/com/baeldung/guava/GuavaSetOperationsUnitTest.java diff --git a/guava-collections/README.md b/guava-modules/guava-collections/README.md similarity index 86% rename from guava-collections/README.md rename to guava-modules/guava-collections/README.md index 51731d7db7..474ded6f33 100644 --- a/guava-collections/README.md +++ b/guava-modules/guava-collections/README.md @@ -8,9 +8,8 @@ This module contains articles about Google Guava collections - [Guava Ordering Cookbook](https://www.baeldung.com/guava-order) - [Guide to Guava’s Ordering](https://www.baeldung.com/guava-ordering) - [Hamcrest Collections Cookbook](https://www.baeldung.com/hamcrest-collections-arrays) -- [Partition a List in Java](https://www.baeldung.com/java-list-split) - [Filtering and Transforming Collections in Guava](https://www.baeldung.com/guava-filter-and-transform-a-collection) - [Guava – Join and Split Collections](https://www.baeldung.com/guava-joiner-and-splitter-tutorial) -- [Guava – Lists](https://www.baeldung.com/guava-lists) - [Guide to Guava MinMaxPriorityQueue and EvictingQueue](https://www.baeldung.com/guava-minmax-priority-queue-and-evicting-queue) - [Guide to Guava Table](https://www.baeldung.com/guava-table) +- [Zipping Collections in Java](http://www.baeldung.com/java-collections-zip) diff --git a/guava-modules/guava-collections/pom.xml b/guava-modules/guava-collections/pom.xml new file mode 100644 index 0000000000..53c55dc655 --- /dev/null +++ b/guava-modules/guava-collections/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + guava-collections + 0.1.0-SNAPSHOT + guava-collections + + + com.baeldung + guava-modules + 0.0.1-SNAPSHOT + ../ + + + + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.jooq + jool + ${jool.version} + + + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + org.hamcrest + java-hamcrest + ${java-hamcrest.version} + test + + + + + guava-collections + + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + + + + 4.1 + 0.9.12 + + + 3.6.1 + 2.0.0.0 + 5.6.2 + + + \ No newline at end of file diff --git a/guava/src/main/resources/logback.xml b/guava-modules/guava-collections/src/main/resources/logback.xml similarity index 100% rename from guava/src/main/resources/logback.xml rename to guava-modules/guava-collections/src/main/resources/logback.xml diff --git a/guava-collections/src/test/java/com/baeldung/guava/collections/GuavaCollectionsExamplesUnitTest.java b/guava-modules/guava-collections/src/test/java/com/baeldung/guava/collections/GuavaCollectionsExamplesUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/collections/GuavaCollectionsExamplesUnitTest.java rename to guava-modules/guava-collections/src/test/java/com/baeldung/guava/collections/GuavaCollectionsExamplesUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/guava/filtertransform/GuavaFilterTransformCollectionsUnitTest.java b/guava-modules/guava-collections/src/test/java/com/baeldung/guava/filtertransform/GuavaFilterTransformCollectionsUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/filtertransform/GuavaFilterTransformCollectionsUnitTest.java rename to guava-modules/guava-collections/src/test/java/com/baeldung/guava/filtertransform/GuavaFilterTransformCollectionsUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java b/guava-modules/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java rename to guava-modules/guava-collections/src/test/java/com/baeldung/guava/joinsplit/GuavaStringUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/guava/ordering/GuavaOrderingExamplesUnitTest.java b/guava-modules/guava-collections/src/test/java/com/baeldung/guava/ordering/GuavaOrderingExamplesUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/ordering/GuavaOrderingExamplesUnitTest.java rename to guava-modules/guava-collections/src/test/java/com/baeldung/guava/ordering/GuavaOrderingExamplesUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/guava/ordering/GuavaOrderingUnitTest.java b/guava-modules/guava-collections/src/test/java/com/baeldung/guava/ordering/GuavaOrderingUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/ordering/GuavaOrderingUnitTest.java rename to guava-modules/guava-collections/src/test/java/com/baeldung/guava/ordering/GuavaOrderingUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/guava/queues/EvictingQueueUnitTest.java b/guava-modules/guava-collections/src/test/java/com/baeldung/guava/queues/EvictingQueueUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/queues/EvictingQueueUnitTest.java rename to guava-modules/guava-collections/src/test/java/com/baeldung/guava/queues/EvictingQueueUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/guava/queues/MinMaxPriorityQueueUnitTest.java b/guava-modules/guava-collections/src/test/java/com/baeldung/guava/queues/MinMaxPriorityQueueUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/queues/MinMaxPriorityQueueUnitTest.java rename to guava-modules/guava-collections/src/test/java/com/baeldung/guava/queues/MinMaxPriorityQueueUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/guava/table/GuavaTableUnitTest.java b/guava-modules/guava-collections/src/test/java/com/baeldung/guava/table/GuavaTableUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/guava/table/GuavaTableUnitTest.java rename to guava-modules/guava-collections/src/test/java/com/baeldung/guava/table/GuavaTableUnitTest.java diff --git a/guava-modules/guava-21/src/test/java/com/baeldung/guava/zip/ZipCollectionUnitTest.java b/guava-modules/guava-collections/src/test/java/com/baeldung/guava/zip/ZipCollectionUnitTest.java similarity index 100% rename from guava-modules/guava-21/src/test/java/com/baeldung/guava/zip/ZipCollectionUnitTest.java rename to guava-modules/guava-collections/src/test/java/com/baeldung/guava/zip/ZipCollectionUnitTest.java diff --git a/guava-collections/src/test/java/com/baeldung/hamcrest/HamcrestExamplesUnitTest.java b/guava-modules/guava-collections/src/test/java/com/baeldung/hamcrest/HamcrestExamplesUnitTest.java similarity index 100% rename from guava-collections/src/test/java/com/baeldung/hamcrest/HamcrestExamplesUnitTest.java rename to guava-modules/guava-collections/src/test/java/com/baeldung/hamcrest/HamcrestExamplesUnitTest.java diff --git a/guava-2/src/test/resources/test.out b/guava-modules/guava-collections/src/test/resources/test.out similarity index 100% rename from guava-2/src/test/resources/test.out rename to guava-modules/guava-collections/src/test/resources/test.out diff --git a/guava-2/src/test/resources/test1.in b/guava-modules/guava-collections/src/test/resources/test1.in similarity index 100% rename from guava-2/src/test/resources/test1.in rename to guava-modules/guava-collections/src/test/resources/test1.in diff --git a/guava-2/src/test/resources/test1_1.in b/guava-modules/guava-collections/src/test/resources/test1_1.in similarity index 100% rename from guava-2/src/test/resources/test1_1.in rename to guava-modules/guava-collections/src/test/resources/test1_1.in diff --git a/guava-2/src/test/resources/test2.in b/guava-modules/guava-collections/src/test/resources/test2.in similarity index 100% rename from guava-2/src/test/resources/test2.in rename to guava-modules/guava-collections/src/test/resources/test2.in diff --git a/guava-2/src/test/resources/test_copy.in b/guava-modules/guava-collections/src/test/resources/test_copy.in similarity index 100% rename from guava-2/src/test/resources/test_copy.in rename to guava-modules/guava-collections/src/test/resources/test_copy.in diff --git a/guava-2/src/test/resources/test_le.txt b/guava-modules/guava-collections/src/test/resources/test_le.txt similarity index 100% rename from guava-2/src/test/resources/test_le.txt rename to guava-modules/guava-collections/src/test/resources/test_le.txt diff --git a/guava-modules/guava-core/README.md b/guava-modules/guava-core/README.md new file mode 100644 index 0000000000..59391ca076 --- /dev/null +++ b/guava-modules/guava-core/README.md @@ -0,0 +1,10 @@ +## Guava Core + +This module contains articles about core or base functionality provided by Google Guava + +### Relevant Articles: +- [Introduction to Guava Throwables](https://www.baeldung.com/guava-throwables) +- [Guava CharMatcher](https://www.baeldung.com/guava-string-charmatcher) +- [Guide to Guava’s PreConditions](https://www.baeldung.com/guava-preconditions) +- [Introduction to Guava Memoizer](https://www.baeldung.com/guava-memoizer) +- [Guava Functional Cookbook](https://www.baeldung.com/guava-functions-predicates) diff --git a/guava-2/pom.xml b/guava-modules/guava-core/pom.xml similarity index 89% rename from guava-2/pom.xml rename to guava-modules/guava-core/pom.xml index b19f59a9b4..5224148cb8 100644 --- a/guava-2/pom.xml +++ b/guava-modules/guava-core/pom.xml @@ -4,15 +4,15 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - guava-2 + guava-core 0.1.0-SNAPSHOT - guava-2 + guava-core com.baeldung - parent-java + guava-modules 0.0.1-SNAPSHOT - ../parent-java + ../ diff --git a/guava/src/main/java/com/baeldung/guava/memoizer/CostlySupplier.java b/guava-modules/guava-core/src/main/java/com/baeldung/guava/memoizer/CostlySupplier.java similarity index 100% rename from guava/src/main/java/com/baeldung/guava/memoizer/CostlySupplier.java rename to guava-modules/guava-core/src/main/java/com/baeldung/guava/memoizer/CostlySupplier.java diff --git a/guava/src/main/java/com/baeldung/guava/memoizer/Factorial.java b/guava-modules/guava-core/src/main/java/com/baeldung/guava/memoizer/Factorial.java similarity index 100% rename from guava/src/main/java/com/baeldung/guava/memoizer/Factorial.java rename to guava-modules/guava-core/src/main/java/com/baeldung/guava/memoizer/Factorial.java diff --git a/guava/src/main/java/com/baeldung/guava/memoizer/FibonacciSequence.java b/guava-modules/guava-core/src/main/java/com/baeldung/guava/memoizer/FibonacciSequence.java similarity index 100% rename from guava/src/main/java/com/baeldung/guava/memoizer/FibonacciSequence.java rename to guava-modules/guava-core/src/main/java/com/baeldung/guava/memoizer/FibonacciSequence.java diff --git a/guava-2/src/test/java/com/baeldung/guava/charmatcher/GuavaCharMatcherUnitTest.java b/guava-modules/guava-core/src/test/java/com/baeldung/guava/charmatcher/GuavaCharMatcherUnitTest.java similarity index 100% rename from guava-2/src/test/java/com/baeldung/guava/charmatcher/GuavaCharMatcherUnitTest.java rename to guava-modules/guava-core/src/test/java/com/baeldung/guava/charmatcher/GuavaCharMatcherUnitTest.java diff --git a/guava/src/test/java/com/baeldung/guava/GuavaFunctionalExamplesUnitTest.java b/guava-modules/guava-core/src/test/java/com/baeldung/guava/functional/GuavaFunctionalExamplesUnitTest.java similarity index 99% rename from guava/src/test/java/com/baeldung/guava/GuavaFunctionalExamplesUnitTest.java rename to guava-modules/guava-core/src/test/java/com/baeldung/guava/functional/GuavaFunctionalExamplesUnitTest.java index b54a7c951a..0177f4f13e 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaFunctionalExamplesUnitTest.java +++ b/guava-modules/guava-core/src/test/java/com/baeldung/guava/functional/GuavaFunctionalExamplesUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.functional; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaMemoizerUnitTest.java b/guava-modules/guava-core/src/test/java/com/baeldung/guava/memoizer/GuavaMemoizerUnitTest.java similarity index 98% rename from guava/src/test/java/com/baeldung/guava/GuavaMemoizerUnitTest.java rename to guava-modules/guava-core/src/test/java/com/baeldung/guava/memoizer/GuavaMemoizerUnitTest.java index 9bafb7ad3f..9af9462e56 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaMemoizerUnitTest.java +++ b/guava-modules/guava-core/src/test/java/com/baeldung/guava/memoizer/GuavaMemoizerUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.memoizer; import com.google.common.base.Suppliers; import com.baeldung.guava.memoizer.CostlySupplier; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaPreConditionsUnitTest.java b/guava-modules/guava-core/src/test/java/com/baeldung/guava/preconditions/GuavaPreConditionsUnitTest.java similarity index 99% rename from guava/src/test/java/com/baeldung/guava/GuavaPreConditionsUnitTest.java rename to guava-modules/guava-core/src/test/java/com/baeldung/guava/preconditions/GuavaPreConditionsUnitTest.java index fe3be9abf0..1f7111b12f 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaPreConditionsUnitTest.java +++ b/guava-modules/guava-core/src/test/java/com/baeldung/guava/preconditions/GuavaPreConditionsUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.preconditions; import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.Arrays; diff --git a/guava-2/src/test/java/com/baeldung/guava/throwables/ThrowablesUnitTest.java b/guava-modules/guava-core/src/test/java/com/baeldung/guava/throwables/ThrowablesUnitTest.java similarity index 100% rename from guava-2/src/test/java/com/baeldung/guava/throwables/ThrowablesUnitTest.java rename to guava-modules/guava-core/src/test/java/com/baeldung/guava/throwables/ThrowablesUnitTest.java diff --git a/guava-collections-set/.gitignore b/guava-modules/guava-core/src/test/resources/.gitignore similarity index 100% rename from guava-collections-set/.gitignore rename to guava-modules/guava-core/src/test/resources/.gitignore diff --git a/guava-collections/src/test/resources/test.out b/guava-modules/guava-core/src/test/resources/test.out similarity index 100% rename from guava-collections/src/test/resources/test.out rename to guava-modules/guava-core/src/test/resources/test.out diff --git a/guava-collections/src/test/resources/test1.in b/guava-modules/guava-core/src/test/resources/test1.in similarity index 100% rename from guava-collections/src/test/resources/test1.in rename to guava-modules/guava-core/src/test/resources/test1.in diff --git a/guava-collections/src/test/resources/test1_1.in b/guava-modules/guava-core/src/test/resources/test1_1.in similarity index 100% rename from guava-collections/src/test/resources/test1_1.in rename to guava-modules/guava-core/src/test/resources/test1_1.in diff --git a/guava-collections/src/test/resources/test2.in b/guava-modules/guava-core/src/test/resources/test2.in similarity index 100% rename from guava-collections/src/test/resources/test2.in rename to guava-modules/guava-core/src/test/resources/test2.in diff --git a/guava-collections/src/test/resources/test_copy.in b/guava-modules/guava-core/src/test/resources/test_copy.in similarity index 100% rename from guava-collections/src/test/resources/test_copy.in rename to guava-modules/guava-core/src/test/resources/test_copy.in diff --git a/guava-collections/src/test/resources/test_le.txt b/guava-modules/guava-core/src/test/resources/test_le.txt similarity index 100% rename from guava-collections/src/test/resources/test_le.txt rename to guava-modules/guava-core/src/test/resources/test_le.txt diff --git a/guava-io/README.md b/guava-modules/guava-io/README.md similarity index 100% rename from guava-io/README.md rename to guava-modules/guava-io/README.md diff --git a/guava-io/pom.xml b/guava-modules/guava-io/pom.xml similarity index 94% rename from guava-io/pom.xml rename to guava-modules/guava-io/pom.xml index e01f76e2e3..6b3280755c 100644 --- a/guava-io/pom.xml +++ b/guava-modules/guava-io/pom.xml @@ -11,9 +11,9 @@ com.baeldung - parent-java + guava-modules 0.0.1-SNAPSHOT - ../parent-java + ../ diff --git a/guava-io/src/test/java/com/baeldung/guava/GuavaCountingOutputStreamUnitTest.java b/guava-modules/guava-io/src/test/java/com/baeldung/guava/GuavaCountingOutputStreamUnitTest.java similarity index 100% rename from guava-io/src/test/java/com/baeldung/guava/GuavaCountingOutputStreamUnitTest.java rename to guava-modules/guava-io/src/test/java/com/baeldung/guava/GuavaCountingOutputStreamUnitTest.java diff --git a/guava-io/src/test/java/com/baeldung/guava/GuavaIOUnitTest.java b/guava-modules/guava-io/src/test/java/com/baeldung/guava/GuavaIOUnitTest.java similarity index 100% rename from guava-io/src/test/java/com/baeldung/guava/GuavaIOUnitTest.java rename to guava-modules/guava-io/src/test/java/com/baeldung/guava/GuavaIOUnitTest.java diff --git a/guava-io/src/test/resources/test1.in b/guava-modules/guava-io/src/test/resources/test1.in similarity index 100% rename from guava-io/src/test/resources/test1.in rename to guava-modules/guava-io/src/test/resources/test1.in diff --git a/guava-io/src/test/resources/test1_1.in b/guava-modules/guava-io/src/test/resources/test1_1.in similarity index 100% rename from guava-io/src/test/resources/test1_1.in rename to guava-modules/guava-io/src/test/resources/test1_1.in diff --git a/guava-io/src/test/resources/test2.in b/guava-modules/guava-io/src/test/resources/test2.in similarity index 100% rename from guava-io/src/test/resources/test2.in rename to guava-modules/guava-io/src/test/resources/test2.in diff --git a/guava/.gitignore b/guava-modules/guava-utilities/.gitignore similarity index 100% rename from guava/.gitignore rename to guava-modules/guava-utilities/.gitignore diff --git a/guava/README.md b/guava-modules/guava-utilities/README.md similarity index 60% rename from guava/README.md rename to guava-modules/guava-utilities/README.md index 24beca60c3..e2caa1a145 100644 --- a/guava/README.md +++ b/guava-modules/guava-utilities/README.md @@ -1,17 +1,12 @@ -## Guava +## Guava Utilities -This module contains articles a Google Guava +This module contains articles about utilities provided by Google Guava ### Relevant Articles: - -- [Guava Functional Cookbook](https://www.baeldung.com/guava-functions-predicates) -- [Guide to Guava’s PreConditions](https://www.baeldung.com/guava-preconditions) - [Introduction to Guava CacheLoader](https://www.baeldung.com/guava-cacheloader) -- [Introduction to Guava Memoizer](https://www.baeldung.com/guava-memoizer) - [Guide to Guava’s EventBus](https://www.baeldung.com/guava-eventbus) - [Guide to Guava’s Reflection Utilities](https://www.baeldung.com/guava-reflection) - [Guide to Mathematical Utilities in Guava](https://www.baeldung.com/guava-math) - [Bloom Filter in Java using Guava](https://www.baeldung.com/guava-bloom-filter) - [Quick Guide to the Guava RateLimiter](https://www.baeldung.com/guava-rate-limiter) - [Guava Cache](https://www.baeldung.com/guava-cache) -- [Introduction to Guava Throwables](https://www.baeldung.com/guava-throwables) diff --git a/guava/pom.xml b/guava-modules/guava-utilities/pom.xml similarity index 92% rename from guava/pom.xml rename to guava-modules/guava-utilities/pom.xml index 2c4ff07c84..0496f5b2e8 100644 --- a/guava/pom.xml +++ b/guava-modules/guava-utilities/pom.xml @@ -4,15 +4,15 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - guava + guava-utilities 0.1.0-SNAPSHOT - guava + guava-utilities com.baeldung - parent-java + guava-modules 0.0.1-SNAPSHOT - ../parent-java + ../ diff --git a/guava/src/main/java/com/baeldung/guava/CustomEvent.java b/guava-modules/guava-utilities/src/main/java/com/baeldung/guava/eventbus/CustomEvent.java similarity index 87% rename from guava/src/main/java/com/baeldung/guava/CustomEvent.java rename to guava-modules/guava-utilities/src/main/java/com/baeldung/guava/eventbus/CustomEvent.java index a154790374..55112b5cb3 100644 --- a/guava/src/main/java/com/baeldung/guava/CustomEvent.java +++ b/guava-modules/guava-utilities/src/main/java/com/baeldung/guava/eventbus/CustomEvent.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.eventbus; public class CustomEvent { private String action; diff --git a/guava/src/main/java/com/baeldung/guava/EventListener.java b/guava-modules/guava-utilities/src/main/java/com/baeldung/guava/eventbus/EventListener.java similarity index 96% rename from guava/src/main/java/com/baeldung/guava/EventListener.java rename to guava-modules/guava-utilities/src/main/java/com/baeldung/guava/eventbus/EventListener.java index 7bcfbcb8e9..404501b578 100644 --- a/guava/src/main/java/com/baeldung/guava/EventListener.java +++ b/guava-modules/guava-utilities/src/main/java/com/baeldung/guava/eventbus/EventListener.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.eventbus; import com.google.common.eventbus.DeadEvent; import com.google.common.eventbus.Subscribe; diff --git a/guava-modules/guava-utilities/src/main/resources/logback.xml b/guava-modules/guava-utilities/src/main/resources/logback.xml new file mode 100644 index 0000000000..56af2d397e --- /dev/null +++ b/guava-modules/guava-utilities/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/guava/src/test/java/com/baeldung/guava/BloomFilterUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/bloomfilter/BloomFilterUnitTest.java similarity index 97% rename from guava/src/test/java/com/baeldung/guava/BloomFilterUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/bloomfilter/BloomFilterUnitTest.java index c11bf27256..96cc8ac1d9 100644 --- a/guava/src/test/java/com/baeldung/guava/BloomFilterUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/bloomfilter/BloomFilterUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.bloomfilter; import com.google.common.hash.BloomFilter; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaCacheUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/cache/GuavaCacheUnitTest.java similarity index 99% rename from guava/src/test/java/com/baeldung/guava/GuavaCacheUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/cache/GuavaCacheUnitTest.java index 8aa56c7c52..0129d661fc 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaCacheUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/cache/GuavaCacheUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.cache; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaCacheLoaderUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/cacheloader/GuavaCacheLoaderUnitTest.java similarity index 98% rename from guava/src/test/java/com/baeldung/guava/GuavaCacheLoaderUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/cacheloader/GuavaCacheLoaderUnitTest.java index bf9747ec18..7157c76494 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaCacheLoaderUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/cacheloader/GuavaCacheLoaderUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.cacheloader; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaEventBusUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/eventbus/GuavaEventBusUnitTest.java similarity index 90% rename from guava/src/test/java/com/baeldung/guava/GuavaEventBusUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/eventbus/GuavaEventBusUnitTest.java index bb9d26fcce..a6967d18f7 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaEventBusUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/eventbus/GuavaEventBusUnitTest.java @@ -1,5 +1,7 @@ -package com.baeldung.guava; +package com.baeldung.guava.eventbus; +import com.baeldung.guava.eventbus.CustomEvent; +import com.baeldung.guava.eventbus.EventListener; import com.google.common.eventbus.EventBus; import org.junit.After; import org.junit.Before; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaBigIntegerMathUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaBigIntegerMathUnitTest.java similarity index 99% rename from guava/src/test/java/com/baeldung/guava/GuavaBigIntegerMathUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaBigIntegerMathUnitTest.java index cca42a688f..d890ef0bf0 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaBigIntegerMathUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaBigIntegerMathUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.mathutils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaDoubleMathUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaDoubleMathUnitTest.java similarity index 98% rename from guava/src/test/java/com/baeldung/guava/GuavaDoubleMathUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaDoubleMathUnitTest.java index 9c78fb36fa..05a70e3654 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaDoubleMathUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaDoubleMathUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.mathutils; import static org.junit.Assert.*; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaIntMathUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaIntMathUnitTest.java similarity index 99% rename from guava/src/test/java/com/baeldung/guava/GuavaIntMathUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaIntMathUnitTest.java index 547f423396..4ac3c93518 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaIntMathUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaIntMathUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.mathutils; import static org.junit.Assert.*; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaLongMathUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaLongMathUnitTest.java similarity index 99% rename from guava/src/test/java/com/baeldung/guava/GuavaLongMathUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaLongMathUnitTest.java index 33c28d4594..41358b081b 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaLongMathUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaLongMathUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.mathutils; import static org.junit.Assert.*; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaMathUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaMathUnitTest.java similarity index 99% rename from guava/src/test/java/com/baeldung/guava/GuavaMathUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaMathUnitTest.java index fce0fec13b..0d21a6f4ae 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaMathUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/mathutils/GuavaMathUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.mathutils; import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.*; diff --git a/guava/src/test/java/com/baeldung/guava/RateLimiterLongRunningUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/ratelimiter/RateLimiterLongRunningUnitTest.java similarity index 98% rename from guava/src/test/java/com/baeldung/guava/RateLimiterLongRunningUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/ratelimiter/RateLimiterLongRunningUnitTest.java index 7372e9f6e9..cb06e6ff85 100644 --- a/guava/src/test/java/com/baeldung/guava/RateLimiterLongRunningUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/ratelimiter/RateLimiterLongRunningUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.ratelimiter; import com.google.common.util.concurrent.RateLimiter; diff --git a/guava/src/test/java/com/baeldung/guava/GuavaReflectionUtilsUnitTest.java b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/reflectionutils/GuavaReflectionUtilsUnitTest.java similarity index 99% rename from guava/src/test/java/com/baeldung/guava/GuavaReflectionUtilsUnitTest.java rename to guava-modules/guava-utilities/src/test/java/com/baeldung/guava/reflectionutils/GuavaReflectionUtilsUnitTest.java index 36df241711..8060191bdc 100644 --- a/guava/src/test/java/com/baeldung/guava/GuavaReflectionUtilsUnitTest.java +++ b/guava-modules/guava-utilities/src/test/java/com/baeldung/guava/reflectionutils/GuavaReflectionUtilsUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.guava; +package com.baeldung.guava.reflectionutils; import com.google.common.collect.Lists; diff --git a/guava/src/test/resources/.gitignore b/guava-modules/guava-utilities/src/test/resources/.gitignore similarity index 100% rename from guava/src/test/resources/.gitignore rename to guava-modules/guava-utilities/src/test/resources/.gitignore diff --git a/guava/src/test/resources/test.out b/guava-modules/guava-utilities/src/test/resources/test.out similarity index 100% rename from guava/src/test/resources/test.out rename to guava-modules/guava-utilities/src/test/resources/test.out diff --git a/guava/src/test/resources/test1.in b/guava-modules/guava-utilities/src/test/resources/test1.in similarity index 100% rename from guava/src/test/resources/test1.in rename to guava-modules/guava-utilities/src/test/resources/test1.in diff --git a/guava/src/test/resources/test1_1.in b/guava-modules/guava-utilities/src/test/resources/test1_1.in similarity index 100% rename from guava/src/test/resources/test1_1.in rename to guava-modules/guava-utilities/src/test/resources/test1_1.in diff --git a/guava/src/test/resources/test2.in b/guava-modules/guava-utilities/src/test/resources/test2.in similarity index 100% rename from guava/src/test/resources/test2.in rename to guava-modules/guava-utilities/src/test/resources/test2.in diff --git a/guava/src/test/resources/test_copy.in b/guava-modules/guava-utilities/src/test/resources/test_copy.in similarity index 100% rename from guava/src/test/resources/test_copy.in rename to guava-modules/guava-utilities/src/test/resources/test_copy.in diff --git a/guava/src/test/resources/test_le.txt b/guava-modules/guava-utilities/src/test/resources/test_le.txt similarity index 100% rename from guava/src/test/resources/test_le.txt rename to guava-modules/guava-utilities/src/test/resources/test_le.txt diff --git a/guava-modules/pom.xml b/guava-modules/pom.xml index d1a2bbc16e..2d0bf68183 100644 --- a/guava-modules/pom.xml +++ b/guava-modules/pom.xml @@ -17,9 +17,16 @@ + guava-utilities + guava-core guava-18 guava-19 guava-21 + guava-collections + guava-collections-list + guava-collections-map + guava-collections-set + guava-io diff --git a/pom.xml b/pom.xml index 9d9c448887..5ed3791760 100644 --- a/pom.xml +++ b/pom.xml @@ -415,13 +415,7 @@ graphql/graphql-java grpc - gson - guava - guava-2 - guava-collections - guava-collections-map - guava-collections-set - guava-io + gson guava-modules guice @@ -933,12 +927,7 @@ graphql/graphql-java grpc - gson - guava - guava-collections - guava-collections-map - guava-collections-set - guava-io + gson guava-modules guice From a0bfc4c72a95983736c8bbf226bfa22ae24795a3 Mon Sep 17 00:00:00 2001 From: STS Date: Tue, 28 Jul 2020 14:23:08 +0200 Subject: [PATCH 150/309] change address --- .../com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java b/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java index b3f6949216..fa5baa37fa 100644 --- a/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java +++ b/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java @@ -14,7 +14,7 @@ import java.net.URISyntaxException; import java.nio.file.Paths; class ExcelFormulaUnitTest { - private static String FILE_NAME = "com/bealdung/poi/excel/setformula/SetFormulaTest.xlsx"; + private static String FILE_NAME = "com/baeldung/poi/excel/setformula/SetFormulaTest.xlsx"; private String fileLocation; private ExcelFormula excelFormula; From 45be1b60457eaa89e2dca7bbbc928154a2596a40 Mon Sep 17 00:00:00 2001 From: joe zhang Date: Tue, 28 Jul 2020 21:12:15 +0800 Subject: [PATCH 151/309] Add primitive type check method and unit tests --- .../core-java-lang-oop-types/pom.xml | 8 ++++ .../primitivetype/PrimitiveTypeUtil.java | 38 +++++++++++++++++ .../primitivetype/PrimitiveTypeUtilTest.java | 41 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java create mode 100644 core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java diff --git a/core-java-modules/core-java-lang-oop-types/pom.xml b/core-java-modules/core-java-lang-oop-types/pom.xml index 5555df4818..ee167bbae2 100644 --- a/core-java-modules/core-java-lang-oop-types/pom.xml +++ b/core-java-modules/core-java-lang-oop-types/pom.xml @@ -12,4 +12,12 @@ core-java-lang-oop-types core-java-lang-oop-types jar + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + \ No newline at end of file diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java new file mode 100644 index 0000000000..c749ed9dcd --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java @@ -0,0 +1,38 @@ +package com.baeldung.primitivetype; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.ClassUtils; + +import com.google.common.primitives.Primitives; + +public class PrimitiveTypeUtil { + + private static final Map, Class> WRAPPER_TYPE_MAP; + static { + WRAPPER_TYPE_MAP = new HashMap, Class>(16); + WRAPPER_TYPE_MAP.put(Integer.class, int.class); + WRAPPER_TYPE_MAP.put(Byte.class, byte.class); + WRAPPER_TYPE_MAP.put(Character.class, char.class); + WRAPPER_TYPE_MAP.put(Boolean.class, boolean.class); + WRAPPER_TYPE_MAP.put(Double.class, double.class); + WRAPPER_TYPE_MAP.put(Float.class, float.class); + WRAPPER_TYPE_MAP.put(Long.class, long.class); + WRAPPER_TYPE_MAP.put(Short.class, short.class); + WRAPPER_TYPE_MAP.put(Void.class, void.class); + } + + public boolean isPrimitiveTypeByCommansLang(Object source) { + return ClassUtils.isPrimitiveOrWrapper(source.getClass()); + } + + public boolean isPrimitiveTypeByGuava(Object source) { + return Primitives.isWrapperType(source.getClass()); + } + + public boolean isPrimitiveType(Object source) { + return WRAPPER_TYPE_MAP.containsKey(source.getClass()); + } + +} diff --git a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java new file mode 100644 index 0000000000..7d3c2964d4 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java @@ -0,0 +1,41 @@ +package com.baeldung.primitivetype; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +public class PrimitiveTypeUtilTest { + + private PrimitiveTypeUtil primitiveTypeUtil; + private boolean booleanVal = false; + private Long longWrapper = 1L; + private String nonPrimitiveVal = "Test"; + + @Before + public void setup() { + primitiveTypeUtil = new PrimitiveTypeUtil(); + } + + @Test + public void givenObjectWhenCheckWithGuavaShouldValidate() { + assertTrue(primitiveTypeUtil.isPrimitiveTypeByGuava(booleanVal)); + assertTrue(primitiveTypeUtil.isPrimitiveTypeByGuava(longWrapper)); + assertFalse(primitiveTypeUtil.isPrimitiveTypeByGuava(nonPrimitiveVal)); + } + + @Test + public void givenObjectWhenCheckWithCommansLangShouldValidate() { + assertTrue(primitiveTypeUtil.isPrimitiveTypeByCommansLang(booleanVal)); + assertTrue(primitiveTypeUtil.isPrimitiveTypeByCommansLang(longWrapper)); + assertFalse(primitiveTypeUtil.isPrimitiveTypeByCommansLang(nonPrimitiveVal)); + } + + @Test + public void givenPrimitiveOrWrapperWhenCheckWithCustomMethodShouldReturnTrue() { + assertTrue(primitiveTypeUtil.isPrimitiveType(booleanVal)); + assertTrue(primitiveTypeUtil.isPrimitiveType(longWrapper)); + assertFalse(primitiveTypeUtil.isPrimitiveType(nonPrimitiveVal)); + } +} From 011b56d158f8bfa4b9bfc34e3e7a90975e5491b9 Mon Sep 17 00:00:00 2001 From: STS Date: Tue, 28 Jul 2020 20:17:02 +0200 Subject: [PATCH 152/309] Trigger Test From 92b315a3a6cf07165f5f9e0e96eff1c22ba52c59 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 28 Jul 2020 22:08:52 +0200 Subject: [PATCH 153/309] BAEL-3905: Mark test ctx as dirty after each test method (#9784) --- .../com/baeldung/testloglevel/TestLogLevelApplication.java | 4 +--- .../LogbackMultiProfileTestLogLevelIntegrationTest.java | 4 ++-- .../testloglevel/LogbackTestLogLevelIntegrationTest.java | 4 ++-- .../testloglevel/TestLogLevelWithProfileIntegrationTest.java | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelApplication.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelApplication.java index ed8218c6a3..ef4534938b 100644 --- a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelApplication.java +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/testloglevel/TestLogLevelApplication.java @@ -3,13 +3,11 @@ package com.baeldung.testloglevel; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.baeldung.boot.Application; - @SpringBootApplication(scanBasePackages = {"com.baeldung.testloglevel", "com.baeldung.component"}) public class TestLogLevelApplication { public static void main(String[] args) { - SpringApplication.run(Application.class, args); + SpringApplication.run(TestLogLevelApplication.class, args); } } diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java index f8bd61e5c7..ffe99672be 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackMultiProfileTestLogLevelIntegrationTest.java @@ -16,9 +16,9 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_CLASS; +import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; -@DirtiesContext(classMode = AFTER_CLASS) +@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class) @EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java index ffe9d400ed..cbd22e8087 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/LogbackTestLogLevelIntegrationTest.java @@ -16,9 +16,9 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_CLASS; +import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; -@DirtiesContext(classMode = AFTER_CLASS) +@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class) @EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java index 6e80f50c00..571b826b80 100644 --- a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/testloglevel/TestLogLevelWithProfileIntegrationTest.java @@ -16,10 +16,10 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_CLASS; +import static org.springframework.test.annotation.DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD; @RunWith(SpringRunner.class) -@DirtiesContext(classMode = AFTER_CLASS) +@DirtiesContext(classMode = AFTER_EACH_TEST_METHOD) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestLogLevelApplication.class) @EnableAutoConfiguration(exclude = SecurityAutoConfiguration.class) @ActiveProfiles("logging-test") From eadd24ad5de2567d7dca6365715340b8c5258b05 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Tue, 28 Jul 2020 18:03:57 -0400 Subject: [PATCH 154/309] Simplify hashcode example --- .../java/com/baeldung/jpa/equality/EqualByBusinessKey.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java index 3e34f97d77..78ba1ad1e9 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java @@ -32,10 +32,7 @@ public class EqualByBusinessKey { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((email == null) ? 0 : email.hashCode()); - return result; + return java.util.Objects.hashCode(email); } @Override From da07a30a00cf92b2b251714f56684dd4a94d57fa Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Tue, 28 Jul 2020 18:40:29 -0400 Subject: [PATCH 155/309] Remove metamodel plugin --- persistence-modules/java-jpa-3/pom.xml | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/persistence-modules/java-jpa-3/pom.xml b/persistence-modules/java-jpa-3/pom.xml index 562f337215..57791f474e 100644 --- a/persistence-modules/java-jpa-3/pom.xml +++ b/persistence-modules/java-jpa-3/pom.xml @@ -66,26 +66,6 @@ -proc:none - - org.bsc.maven - maven-processor-plugin - ${maven-processor-plugin.version} - - - process - - process - - generate-sources - - target/metamodel - - org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor - - - - - org.codehaus.mojo build-helper-maven-plugin From 12322ff46b265ccf3b58aac62c5d197bc495bda4 Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Wed, 29 Jul 2020 08:59:06 +0200 Subject: [PATCH 156/309] update test --- .../java/com/baeldung/screenshot/ScreenshotTest.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java index 3df31897e1..20d2d333a3 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java @@ -17,10 +17,9 @@ public class ScreenshotTest { public void takeScreenshotOfMainScreen() throws Exception { Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage capture = new Robot().createScreenCapture(screenRect); - File imageFile = new File("single-screen.bmp"); + File imageFile = File.createTempFile("single-screen", "bmp"); ImageIO.write(capture, "bmp", imageFile); assertTrue(imageFile.exists()); - imageFile.delete(); } @Test @@ -34,10 +33,9 @@ public class ScreenshotTest { allScreenBounds.height = Math.max(allScreenBounds.height, screenBounds.height); } BufferedImage capture = new Robot().createScreenCapture(allScreenBounds); - File imageFile = new File("all-screens.bmp"); + File imageFile = File.createTempFile("all-screens", "bmp"); ImageIO.write(capture, "bmp", imageFile); assertTrue(imageFile.exists()); - imageFile.delete(); } @Test @@ -45,10 +43,9 @@ public class ScreenshotTest { Rectangle componentRect = component.getBounds(); BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB); component.paint(bufferedImage.getGraphics()); - File imageFile = new File("component-screenshot.bmp"); + File imageFile = File.createTempFile("component-screenshot", "bmp"); ImageIO.write(bufferedImage, "bmp", imageFile); assertTrue(imageFile.exists()); - imageFile.delete(); } } \ No newline at end of file From 768658cfc8ab0ad9a9df6fca9574f72ac1905576 Mon Sep 17 00:00:00 2001 From: helga_sh Date: Wed, 29 Jul 2020 11:36:09 +0300 Subject: [PATCH 157/309] Fixed builder formatting --- .../baeldung/deeplearning4j/cnn/CnnModel.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnModel.java b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnModel.java index bd87709c0e..efa7f828ed 100644 --- a/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnModel.java +++ b/deeplearning4j/src/main/java/com/baeldung/deeplearning4j/cnn/CnnModel.java @@ -30,23 +30,23 @@ class CnnModel { this.properties = properties; MultiLayerConfiguration configuration = new NeuralNetConfiguration.Builder() - .seed(1611) - .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) - .learningRate(properties.getLearningRate()) - .regularization(true) - .updater(properties.getOptimizer()) - .list() - .layer(0, conv5x5()) - .layer(1, pooling2x2Stride2()) - .layer(2, conv3x3Stride1Padding2()) - .layer(3, pooling2x2Stride1()) - .layer(4, conv3x3Stride1Padding1()) - .layer(5, pooling2x2Stride1()) - .layer(6, dense()) - .pretrain(false) - .backprop(true) - .setInputType(dataSetService.inputType()) - .build(); + .seed(1611) + .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) + .learningRate(properties.getLearningRate()) + .regularization(true) + .updater(properties.getOptimizer()) + .list() + .layer(0, conv5x5()) + .layer(1, pooling2x2Stride2()) + .layer(2, conv3x3Stride1Padding2()) + .layer(3, pooling2x2Stride1()) + .layer(4, conv3x3Stride1Padding1()) + .layer(5, pooling2x2Stride1()) + .layer(6, dense()) + .pretrain(false) + .backprop(true) + .setInputType(dataSetService.inputType()) + .build(); network = new MultiLayerNetwork(configuration); } From 23f1333aaaca15c8bc662ef873c5b5f494284b9f Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Thu, 30 Jul 2020 01:43:57 +0530 Subject: [PATCH 158/309] Implementing Code Review comments --- .../spring-data-cosmosdb/pom.xml | 84 ++++++++++--------- .../controller/ProductController.java | 10 ++- .../spring/data/cosmosdb/entity/Product.java | 42 ++-------- .../data/cosmosdb/service/ProductService.java | 3 +- ...=> AzurecosmodbApplicationManualTest.java} | 12 ++- 5 files changed, 62 insertions(+), 89 deletions(-) rename persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/{AzurecosmodbApplicationIntegrationTest.java => AzurecosmodbApplicationManualTest.java} (70%) diff --git a/persistence-modules/spring-data-cosmosdb/pom.xml b/persistence-modules/spring-data-cosmosdb/pom.xml index 8bb103879d..7de135cdb6 100644 --- a/persistence-modules/spring-data-cosmosdb/pom.xml +++ b/persistence-modules/spring-data-cosmosdb/pom.xml @@ -1,48 +1,52 @@ - 4.0.0 - spring-data-cosmosdb - spring-data-cosmos-db - tutorial for spring-data-cosmosdb + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + spring-data-cosmosdb + spring-data-cosmos-db + tutorial for spring-data-cosmosdb - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + - - 1.8 - + + 1.8 + 2.3.0 + - - - org.springframework.boot - spring-boot-starter-web - - - com.microsoft.azure - spring-data-cosmosdb - 2.3.0 - + + + org.springframework.boot + spring-boot-starter-web + + + com.microsoft.azure + spring-data-cosmosdb + ${cosmodb.version} + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + + - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java index c1e38c9601..fe02be88ff 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java @@ -22,9 +22,13 @@ import java.util.Optional; @RequestMapping("/products") public class ProductController { - @Autowired private ProductService productService; + @Autowired + public ProductController(ProductService productService) { + this.productService = productService; + } + @PostMapping @ResponseStatus(HttpStatus.CREATED) public void create(@RequestBody Product product) { @@ -46,8 +50,8 @@ public class ProductController { return productService.findProductByName(name); } - @GetMapping(value = "/category/{category}") - public List getByCategory(@PathVariable String category) { + @GetMapping(value = "/category") + public List getByCategory(@RequestParam String category) { return productService.getProductsOfCategory(category); } diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java index 07bb8889f5..10bbe1b9ae 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/entity/Product.java @@ -5,6 +5,11 @@ import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey; import org.springframework.data.annotation.Id; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter @Document(collection = "products") public class Product { @@ -18,41 +23,4 @@ public class Product { @PartitionKey private String productCategory; - public String getProductid() { - return productid; - } - - public void setProductid(String productid) { - this.productid = productid; - } - - public String getProductName() { - return productName; - } - - public void setProductName(String productName) { - this.productName = productName; - } - - public String getProductCategory() { - return productCategory; - } - - public void setProductCategory(String productCategory) { - this.productCategory = productCategory; - } - - public double getPrice() { - return price; - } - - public void setPrice(double price) { - this.price = price; - } - - @Override - public String toString() { - return "Product [productid=" + productid + ", productName=" + productName + ", price=" + price + ", productCategory=" + productCategory + "]"; - } - } diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java index 6846d5205c..03f3ba39cd 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java @@ -25,8 +25,7 @@ public class ProductService { } public List getProductsOfCategory(String category) { - List products = repository.findByProductCategory(category); - return products; + return repository.findByProductCategory(category); } public void saveProduct(Product product) { diff --git a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationIntegrationTest.java b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java similarity index 70% rename from persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationIntegrationTest.java rename to persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java index 0ef6af15e1..80cf17284a 100644 --- a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationIntegrationTest.java +++ b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java @@ -14,14 +14,14 @@ import java.util.Optional; //Uncomment this when configured URI and keys for Azure Cosmos DB in application.properties //to run the integration test //@SpringBootTest -public class AzurecosmodbApplicationIntegrationTest { +public class AzurecosmodbApplicationManualTest { @Autowired ProductRepository productRepository; // Uncomment this when configured URI and keys for Azure Cosmos DB in application.properties // to run the integration test - // @Test + //@Test public void givenProductIsCreated_whenCallFindById_thenProductIsFound() { Product product = new Product(); product.setProductid("1001"); @@ -29,11 +29,9 @@ public class AzurecosmodbApplicationIntegrationTest { product.setPrice(110.0); product.setProductName("Blue Shirt"); - // Uncomment these lines when configured URI and keys for Azure Cosmos DB in application.properties - // to run the integration test - // productRepository.save(product); - // Optional retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt")); - // Assert.notNull(retrievedProduct, "Retrieved Product is Null"); + productRepository.save(product); + Optional retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt")); + Assert.notNull(retrievedProduct, "Retrieved Product is Null"); } From bb391a389f9fe800f76d94ddc3c13f2c4716b819 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Thu, 30 Jul 2020 01:49:05 +0530 Subject: [PATCH 159/309] Implementing Code Review comments-2 --- .../spring/data/cosmosdb/service/ProductService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java index 03f3ba39cd..49d07ca5a2 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java @@ -13,8 +13,12 @@ import java.util.Optional; @Component public class ProductService { - @Autowired private ProductRepository repository; + + @Autowired + public ProductService(ProductRepository repository) { + this.repository = repository; + } public List findProductByName(String productName) { return repository.findByProductName(productName); From 7693cbd8fe05a8c365e52c3cfa93c6d9a2f5a009 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Thu, 30 Jul 2020 01:54:23 +0530 Subject: [PATCH 160/309] Fixing indentation Issue in pom.xml --- .../spring-data-cosmosdb/pom.xml | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/persistence-modules/spring-data-cosmosdb/pom.xml b/persistence-modules/spring-data-cosmosdb/pom.xml index 7de135cdb6..3bf19575dd 100644 --- a/persistence-modules/spring-data-cosmosdb/pom.xml +++ b/persistence-modules/spring-data-cosmosdb/pom.xml @@ -1,52 +1,52 @@ - 4.0.0 - spring-data-cosmosdb - spring-data-cosmos-db - tutorial for spring-data-cosmosdb + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + spring-data-cosmosdb + spring-data-cosmos-db + tutorial for spring-data-cosmosdb - - com.baeldung + + com.baeldung parent-boot-2 0.0.1-SNAPSHOT ../../parent-boot-2 - + - + 1.8 2.3.0 - + - + - org.springframework.boot - spring-boot-starter-web + org.springframework.boot + spring-boot-starter-web - com.microsoft.azure - spring-data-cosmosdb - ${cosmodb.version} + com.microsoft.azure + spring-data-cosmosdb + ${cosmodb.version} - - org.springframework.boot - spring-boot-starter-test - test + + org.springframework.boot + spring-boot-starter-test + test - org.projectlombok - lombok + org.projectlombok + lombok - + - + - + org.springframework.boot spring-boot-maven-plugin - + - + From 251466b0a6a5b154b6e0f62ea42ec9a65eb927e1 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Thu, 30 Jul 2020 02:03:32 +0530 Subject: [PATCH 161/309] Fixing indentation issues --- .../spring-data-cosmosdb/pom.xml | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/persistence-modules/spring-data-cosmosdb/pom.xml b/persistence-modules/spring-data-cosmosdb/pom.xml index 3bf19575dd..91fb53286a 100644 --- a/persistence-modules/spring-data-cosmosdb/pom.xml +++ b/persistence-modules/spring-data-cosmosdb/pom.xml @@ -6,47 +6,47 @@ spring-data-cosmosdb spring-data-cosmos-db tutorial for spring-data-cosmosdb - + com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 - 1.8 - 2.3.0 + 1.8 + 2.3.0 - - org.springframework.boot - spring-boot-starter-web - - - com.microsoft.azure - spring-data-cosmosdb - ${cosmodb.version} - + + org.springframework.boot + spring-boot-starter-web + + + com.microsoft.azure + spring-data-cosmosdb + ${cosmodb.version} + - org.springframework.boot - spring-boot-starter-test - test - - - org.projectlombok - lombok - + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + - - - org.springframework.boot - spring-boot-maven-plugin - - + + + org.springframework.boot + spring-boot-maven-plugin + + From 929ec03e4b603119b47df93ef1924aeabff16053 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Thu, 30 Jul 2020 02:09:15 +0530 Subject: [PATCH 162/309] Fixing Indentation Issues - 2 --- .../spring-data-cosmosdb/pom.xml | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/persistence-modules/spring-data-cosmosdb/pom.xml b/persistence-modules/spring-data-cosmosdb/pom.xml index 91fb53286a..1b21c6dd71 100644 --- a/persistence-modules/spring-data-cosmosdb/pom.xml +++ b/persistence-modules/spring-data-cosmosdb/pom.xml @@ -9,35 +9,35 @@ com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 - 1.8 - 2.3.0 + 1.8 + 2.3.0 - - org.springframework.boot - spring-boot-starter-web - - - com.microsoft.azure - spring-data-cosmosdb - ${cosmodb.version} - + + org.springframework.boot + spring-boot-starter-web + + + com.microsoft.azure + spring-data-cosmosdb + ${cosmodb.version} + - org.springframework.boot - spring-boot-starter-test - test - - - org.projectlombok - lombok - + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + From 36279b05b48e78f50a8735adf38b458fa3b6ef16 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Thu, 30 Jul 2020 02:14:27 +0530 Subject: [PATCH 163/309] Fixing Indentation Issue -3 --- .../spring-data-cosmosdb/pom.xml | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/persistence-modules/spring-data-cosmosdb/pom.xml b/persistence-modules/spring-data-cosmosdb/pom.xml index 1b21c6dd71..75cc830578 100644 --- a/persistence-modules/spring-data-cosmosdb/pom.xml +++ b/persistence-modules/spring-data-cosmosdb/pom.xml @@ -6,40 +6,39 @@ spring-data-cosmosdb spring-data-cosmos-db tutorial for spring-data-cosmosdb - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 - + - 1.8 - 2.3.0 + 1.8 + 2.3.0 - + - - org.springframework.boot - spring-boot-starter-web - - - com.microsoft.azure - spring-data-cosmosdb - ${cosmodb.version} - - org.springframework.boot - spring-boot-starter-test - test - - - org.projectlombok - lombok - + org.springframework.boot + spring-boot-starter-web + + + com.microsoft.azure + spring-data-cosmosdb + ${cosmodb.version} + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + - + From 204caa3219e220245475d699d89fd03a2200ea38 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Thu, 30 Jul 2020 02:44:25 +0530 Subject: [PATCH 164/309] uncommenting the @SpringBootTest and @Test annotation --- .../data/cosmosdb/AzurecosmodbApplicationManualTest.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java index 80cf17284a..0f42aadc6f 100644 --- a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java +++ b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java @@ -11,17 +11,13 @@ import org.springframework.util.Assert; import java.util.Optional; -//Uncomment this when configured URI and keys for Azure Cosmos DB in application.properties -//to run the integration test -//@SpringBootTest +@SpringBootTest public class AzurecosmodbApplicationManualTest { @Autowired ProductRepository productRepository; - // Uncomment this when configured URI and keys for Azure Cosmos DB in application.properties - // to run the integration test - //@Test + @Test public void givenProductIsCreated_whenCallFindById_thenProductIsFound() { Product product = new Product(); product.setProductid("1001"); From 75df0b0778cdfd6e13c6ef34290d22c41a2c42ac Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Thu, 30 Jul 2020 03:05:16 +0530 Subject: [PATCH 165/309] retrieving the object from optional object --- .../spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java index 0f42aadc6f..786b578501 100644 --- a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java +++ b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java @@ -27,7 +27,7 @@ public class AzurecosmodbApplicationManualTest { productRepository.save(product); Optional retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt")); - Assert.notNull(retrievedProduct, "Retrieved Product is Null"); + Assert.notNull(retrievedProduct.get(), "Retrieved Product is Null"); } From a4b9016d6cbdea0b74d1754fbcabf8c5b988d5b5 Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Thu, 30 Jul 2020 08:23:43 +0530 Subject: [PATCH 166/309] JAVA-2154: Added guava dependency to module pom directly (#9789) instead of inheriting from parent --- guava-modules/pom.xml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/guava-modules/pom.xml b/guava-modules/pom.xml index 2d0bf68183..b625f9fd0f 100644 --- a/guava-modules/pom.xml +++ b/guava-modules/pom.xml @@ -4,9 +4,6 @@ 4.0.0 guava-modules guava-modules - - 5.6.2 - pom @@ -30,6 +27,11 @@ + + com.google.guava + guava + ${guava.version} + org.junit.jupiter junit-jupiter @@ -54,4 +56,9 @@ + + 5.6.2 + 29.0-jre + + From 6889e238ff978ab3ed3175b011bcc0309fccc60d Mon Sep 17 00:00:00 2001 From: kwoyke Date: Thu, 30 Jul 2020 07:50:21 +0200 Subject: [PATCH 167/309] BAEL-3415: Get rid of the MockitoAnnotations.initMocks (#9787) --- .../fluentapi/PizzaServiceUnitTest.java | 29 ++++++++----------- .../ArgumentMatcherWithLambdaUnitTest.java | 25 +++++++--------- .../ArgumentMatcherWithoutLambdaUnitTest.java | 14 ++++----- .../java8/CustomAnswerWithLambdaUnitTest.java | 6 ++-- .../CustomAnswerWithoutLambdaUnitTest.java | 7 ++--- .../mockito/java8/JobServiceUnitTest.java | 22 ++++++-------- .../UnemploymentServiceImplUnitTest.java | 24 +++++++-------- .../MockitoUnecessaryStubUnitTest.java | 28 ++++++++---------- 8 files changed, 66 insertions(+), 89 deletions(-) diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/fluentapi/PizzaServiceUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/fluentapi/PizzaServiceUnitTest.java index b5dd10b1d4..5993d1968c 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/fluentapi/PizzaServiceUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/fluentapi/PizzaServiceUnitTest.java @@ -1,5 +1,16 @@ package com.baeldung.mockito.fluentapi; +import com.baeldung.mockito.fluentapi.Pizza.PizzaBuilder; +import com.baeldung.mockito.fluentapi.Pizza.PizzaSize; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Answers; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; @@ -8,18 +19,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Answers; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; - -import com.baeldung.mockito.fluentapi.Pizza.PizzaBuilder; -import com.baeldung.mockito.fluentapi.Pizza.PizzaSize; - +@RunWith(MockitoJUnitRunner.class) public class PizzaServiceUnitTest { @Mock @@ -33,11 +33,6 @@ public class PizzaServiceUnitTest { @Captor private ArgumentCaptor sizeCaptor; - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - @Test public void givenTraditonalMocking_whenServiceInvoked_thenPizzaIsBuilt() { PizzaBuilder nameBuilder = Mockito.mock(Pizza.PizzaBuilder.class); diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/ArgumentMatcherWithLambdaUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/ArgumentMatcherWithLambdaUnitTest.java index 2efac513b7..8d6d4bade1 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/ArgumentMatcherWithLambdaUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/ArgumentMatcherWithLambdaUnitTest.java @@ -1,19 +1,19 @@ package com.baeldung.mockito.java8; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.Optional; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentMatchers; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - - +@RunWith(MockitoJUnitRunner.class) public class ArgumentMatcherWithLambdaUnitTest { @InjectMocks @@ -36,9 +36,4 @@ public class ArgumentMatcherWithLambdaUnitTest { assertTrue(unemploymentService.personIsEntitledToUnemploymentSupport(linda)); assertFalse(unemploymentService.personIsEntitledToUnemploymentSupport(peter)); } - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } } diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/ArgumentMatcherWithoutLambdaUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/ArgumentMatcherWithoutLambdaUnitTest.java index aaa8d03585..3b003d0a87 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/ArgumentMatcherWithoutLambdaUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/ArgumentMatcherWithoutLambdaUnitTest.java @@ -1,8 +1,12 @@ package com.baeldung.mockito.java8; -import org.junit.Before; import org.junit.Test; -import org.mockito.*; +import org.junit.runner.RunWith; +import org.mockito.ArgumentMatcher; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; import java.util.Optional; @@ -11,6 +15,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; +@RunWith(MockitoJUnitRunner.class) public class ArgumentMatcherWithoutLambdaUnitTest { private class PeterArgumentMatcher implements ArgumentMatcher { @@ -43,9 +48,4 @@ public class ArgumentMatcherWithoutLambdaUnitTest { assertTrue(unemploymentService.personIsEntitledToUnemploymentSupport(linda)); assertFalse(unemploymentService.personIsEntitledToUnemploymentSupport(peter)); } - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } } diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/CustomAnswerWithLambdaUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/CustomAnswerWithLambdaUnitTest.java index 06e9bca6d3..8886d1325c 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/CustomAnswerWithLambdaUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/CustomAnswerWithLambdaUnitTest.java @@ -2,9 +2,10 @@ package com.baeldung.mockito.java8; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; import java.util.stream.Stream; @@ -13,6 +14,7 @@ import static org.junit.Assert.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; +@RunWith(MockitoJUnitRunner.class) public class CustomAnswerWithLambdaUnitTest { @InjectMocks @@ -37,8 +39,6 @@ public class CustomAnswerWithLambdaUnitTest { @Before public void init() { - MockitoAnnotations.initMocks(this); - when(jobService.listJobs(any(Person.class))).then((i) -> Stream.of(new JobPosition("Teacher")) .filter(p -> ((Person) i.getArgument(0)).getName().equals("Peter"))); diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/CustomAnswerWithoutLambdaUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/CustomAnswerWithoutLambdaUnitTest.java index d5b9d6d1ce..f75a62fea5 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/CustomAnswerWithoutLambdaUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/CustomAnswerWithoutLambdaUnitTest.java @@ -2,10 +2,11 @@ package com.baeldung.mockito.java8; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; +import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import java.util.stream.Stream; @@ -15,7 +16,7 @@ import static org.junit.Assert.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; - +@RunWith(MockitoJUnitRunner.class) public class CustomAnswerWithoutLambdaUnitTest { private class PersonAnswer implements Answer> { @@ -54,8 +55,6 @@ public class CustomAnswerWithoutLambdaUnitTest { @Before public void init() { - MockitoAnnotations.initMocks(this); - when(jobService.listJobs(any(Person.class))).then(new PersonAnswer()); } } diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/JobServiceUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/JobServiceUnitTest.java index 9ea5c1db47..5b3bc5e3d5 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/JobServiceUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/JobServiceUnitTest.java @@ -1,18 +1,19 @@ package com.baeldung.mockito.java8; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.Optional; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doCallRealMethod; import static org.mockito.Mockito.when; -import java.util.Optional; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; - +@RunWith(MockitoJUnitRunner.class) public class JobServiceUnitTest { @Mock private JobService jobService; @@ -36,9 +37,4 @@ public class JobServiceUnitTest { assertTrue(jobService.assignJobPosition(person, new JobPosition())); } - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } } diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/UnemploymentServiceImplUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/UnemploymentServiceImplUnitTest.java index b3b71e5bf9..87093fc1ba 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/UnemploymentServiceImplUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/java8/UnemploymentServiceImplUnitTest.java @@ -1,19 +1,20 @@ package com.baeldung.mockito.java8; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.Optional; +import java.util.stream.Stream; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; -import java.util.Optional; -import java.util.stream.Stream; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +@RunWith(MockitoJUnitRunner.class) public class UnemploymentServiceImplUnitTest { @Mock private JobService jobService; @@ -54,9 +55,4 @@ public class UnemploymentServiceImplUnitTest { // This will fail when Mockito 1 is used assertFalse(unemploymentService.searchJob(person, "").isPresent()); } - - @Before - public void init() { - MockitoAnnotations.initMocks(this); - } } diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/misusing/MockitoUnecessaryStubUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/misusing/MockitoUnecessaryStubUnitTest.java index 00edb699de..828d31f6f9 100644 --- a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/misusing/MockitoUnecessaryStubUnitTest.java +++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/misusing/MockitoUnecessaryStubUnitTest.java @@ -1,21 +1,22 @@ package com.baeldung.mockito.misusing; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.exceptions.misusing.UnnecessaryStubbingException; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.quality.Strictness; + +import java.util.ArrayList; + import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; -import java.util.ArrayList; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.mockito.exceptions.misusing.UnnecessaryStubbingException; -import org.mockito.junit.MockitoJUnit; -import org.mockito.quality.Strictness; - +@RunWith(MockitoJUnitRunner.class) public class MockitoUnecessaryStubUnitTest { @Rule @@ -25,11 +26,6 @@ public class MockitoUnecessaryStubUnitTest { @Mock private ArrayList mockList; - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - } - @Test public void givenUnusedStub_whenInvokingGetThenThrowUnnecessaryStubbingException() { rule.expectedFailure(UnnecessaryStubbingException.class); From a623d1714fa8611dd5e9d630ca6686290072f316 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Thu, 30 Jul 2020 07:57:02 +0200 Subject: [PATCH 168/309] BAEL-4468: Fix nullSafeSet method (#9791) --- .../com/baeldung/hibernate/customtypes/PhoneNumberType.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java index 9f09352bec..79caa3d6fd 100644 --- a/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java +++ b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java @@ -57,6 +57,8 @@ public class PhoneNumberType implements UserType { if (Objects.isNull(value)) { st.setNull(index, Types.INTEGER); + st.setNull(index+1, Types.INTEGER); + st.setNull(index+2, Types.INTEGER); } else { PhoneNumber employeeNumber = (PhoneNumber) value; st.setInt(index,employeeNumber.getCountryCode()); From baa46f6f4fb4ede1cb89893dacde69cbbf9baef1 Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Thu, 30 Jul 2020 11:26:57 +0200 Subject: [PATCH 169/309] rename --- .../{ScreenshotTest.java => ScreenshotUnitTest.java} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/{ScreenshotTest.java => ScreenshotUnitTest.java} (85%) diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java similarity index 85% rename from core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java rename to core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java index 20d2d333a3..6bd0e7dff7 100644 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotTest.java +++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java @@ -11,10 +11,10 @@ import org.junit.Test; import static org.junit.Assert.assertTrue; -public class ScreenshotTest { +public class ScreenshotUnitTest { @Test - public void takeScreenshotOfMainScreen() throws Exception { + public void givenMainScreen_whenTakeScreenshot_thenSaveToFile() throws Exception { Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage capture = new Robot().createScreenCapture(screenRect); File imageFile = File.createTempFile("single-screen", "bmp"); @@ -23,7 +23,7 @@ public class ScreenshotTest { } @Test - public void takeScreenshotOfAllScreens() throws Exception { + public void givenMultipleScreens_whenTakeScreenshot_thenSaveToFile() throws Exception { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] screens = ge.getScreenDevices(); Rectangle allScreenBounds = new Rectangle(); @@ -39,7 +39,7 @@ public class ScreenshotTest { } @Test - public void makeScreenshot(Component component) throws Exception { + public void givenComponent_whenTakeScreenshot_thenSaveToFile(Component component) throws Exception { Rectangle componentRect = component.getBounds(); BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB); component.paint(bufferedImage.getGraphics()); From 06ac0b5589d6ff198b10c5ff411e1f09d64a18bd Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 30 Jul 2020 18:06:42 +0530 Subject: [PATCH 170/309] JAVA-1525: Moved 1 article to security module --- spring-5-reactive-security/README.md | 1 + .../cors/annotated/CorsOnAnnotatedElementsApplication.java | 0 .../cors/annotated/controllers/CorsOnClassController.java | 0 .../cors/annotated/controllers/CorsOnMethodsController.java | 0 .../reactive/cors/global/CorsGlobalConfigApplication.java | 0 .../reactive/cors/global/config/CorsGlobalConfiguration.java | 0 .../cors/global/controllers/FurtherCorsConfigsController.java | 0 .../cors/global/controllers/RegularRestController.java | 0 .../functional/handlers/CorsGlobalFunctionalHandler.java | 0 .../cors/global/functional/routers/CorsRouterFunctions.java | 0 .../reactive/cors/webfilter/CorsWebFilterApplication.java | 0 .../reactive/cors/webfilter/config/CorsWebFilterConfig.java | 0 .../webfilter/controllers/FurtherCorsConfigsController.java | 0 .../cors/webfilter/controllers/RegularRestController.java | 0 .../functional/handlers/CorsWithWebFilterHandler.java | 0 .../functional/routers/CorsWithWebFilterRouterFunctions.java | 0 .../reactive/cors/CorsOnAnnotatedElementsLiveTest.java | 4 +++- .../baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java | 4 +++- .../com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java | 4 +++- 19 files changed, 10 insertions(+), 3 deletions(-) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java (100%) rename {spring-5-reactive => spring-5-reactive-security}/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java (96%) rename {spring-5-reactive => spring-5-reactive-security}/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java (94%) rename {spring-5-reactive => spring-5-reactive-security}/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java (94%) diff --git a/spring-5-reactive-security/README.md b/spring-5-reactive-security/README.md index a0f47a503d..915f74cd78 100644 --- a/spring-5-reactive-security/README.md +++ b/spring-5-reactive-security/README.md @@ -12,3 +12,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Guide to Spring 5 WebFlux](https://www.baeldung.com/spring-webflux) - [Introduction to the Functional Web Framework in Spring 5](https://www.baeldung.com/spring-5-functional-web) - [Guide to the AuthenticationManagerResolver in Spring Security](https://www.baeldung.com/spring-security-authenticationmanagerresolver) +- [Spring Webflux and CORS](https://www.baeldung.com/spring-webflux-cors) diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java rename to spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java b/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java similarity index 96% rename from spring-5-reactive/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java rename to spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java index e6847e63da..5fd20eedfd 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java +++ b/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java @@ -6,7 +6,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +import com.baeldung.reactive.cors.annotated.CorsOnAnnotatedElementsApplication; + +@SpringBootTest(classes = CorsOnAnnotatedElementsApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class CorsOnAnnotatedElementsLiveTest { private static final String BASE_URL = "http://localhost:8081"; diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java b/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java similarity index 94% rename from spring-5-reactive/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java rename to spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java index 008f1a16f2..5c6582c127 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java +++ b/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java @@ -6,7 +6,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +import com.baeldung.reactive.cors.global.CorsGlobalConfigApplication; + +@SpringBootTest(classes = CorsGlobalConfigApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class CorsOnGlobalConfigLiveTest { private static final String BASE_URL = "http://localhost:8082"; diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java b/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java similarity index 94% rename from spring-5-reactive/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java rename to spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java index f8a4f34e29..7cc44454ec 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java +++ b/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java @@ -6,7 +6,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +import com.baeldung.reactive.cors.webfilter.CorsWebFilterApplication; + +@SpringBootTest(classes = CorsWebFilterApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) public class CorsOnWebFilterLiveTest { private static final String BASE_URL = "http://localhost:8083"; From 4dc2535bc5361493c305a1834b7c6ad90210ef3c Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 30 Jul 2020 18:07:49 +0530 Subject: [PATCH 171/309] JAVA-1525: Moved 1 article to reactive-2 module --- .../serversentevents/consumer/ConsumerSSEApplication.java | 0 .../consumer/controller/ClientController.java | 0 .../serversentevents/server/ServerSSEApplication.java | 0 .../serversentevents/server/controllers/ServerController.java | 0 .../reactive/serversentsevents/ServiceSentEventLiveTest.java | 4 +++- 5 files changed, 3 insertions(+), 1 deletion(-) rename {spring-5-reactive => spring-5-reactive-2}/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java (100%) rename {spring-5-reactive => spring-5-reactive-2}/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java (100%) rename {spring-5-reactive => spring-5-reactive-2}/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java (100%) rename {spring-5-reactive => spring-5-reactive-2}/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java (100%) rename {spring-5-reactive => spring-5-reactive-2}/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java (92%) diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java b/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java rename to spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java b/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java rename to spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java b/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java rename to spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java b/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java similarity index 100% rename from spring-5-reactive/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java rename to spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java b/spring-5-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java similarity index 92% rename from spring-5-reactive/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java rename to spring-5-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java index 547cd99034..946a038763 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java +++ b/spring-5-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java @@ -8,7 +8,9 @@ import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.reactive.server.WebTestClient; -@SpringBootTest +import com.baeldung.reactive.serversentevents.server.ServerSSEApplication; + +@SpringBootTest(classes = ServerSSEApplication.class) @WithMockUser public class ServiceSentEventLiveTest { From efbd00fdde4246cd6ccf9b955f4cb59c511a6f37 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 30 Jul 2020 18:09:10 +0530 Subject: [PATCH 172/309] JAVA-1525: Moved 1 article to -client module to make space for 1 from reactive module --- spring-5-reactive-2/pom.xml | 5 +++++ spring-5-reactive-client/pom.xml | 4 ++++ .../java/com/baeldung/webclient/filter/WebClientFilters.java | 0 .../baeldung/webclient/filter/FilteredWebClientUnitTest.java | 0 4 files changed, 9 insertions(+) rename {spring-5-reactive-2 => spring-5-reactive-client}/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java (100%) rename {spring-5-reactive-2 => spring-5-reactive-client}/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java (100%) diff --git a/spring-5-reactive-2/pom.xml b/spring-5-reactive-2/pom.xml index fdeebd1dfd..4cb85d879e 100644 --- a/spring-5-reactive-2/pom.xml +++ b/spring-5-reactive-2/pom.xml @@ -53,6 +53,11 @@ reactor-test test + + org.springframework.security + spring-security-test + test + diff --git a/spring-5-reactive-client/pom.xml b/spring-5-reactive-client/pom.xml index 0b5efd1a47..7ae7ba6edd 100644 --- a/spring-5-reactive-client/pom.xml +++ b/spring-5-reactive-client/pom.xml @@ -33,6 +33,10 @@ org.springframework.boot spring-boot-starter-webflux + + org.springframework.boot + spring-boot-starter-security + org.projectreactor reactor-spring diff --git a/spring-5-reactive-2/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java b/spring-5-reactive-client/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java similarity index 100% rename from spring-5-reactive-2/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java rename to spring-5-reactive-client/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java diff --git a/spring-5-reactive-2/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java similarity index 100% rename from spring-5-reactive-2/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java rename to spring-5-reactive-client/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java From a788fa2751dbfbbdd93eca96551e494726174806 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 30 Jul 2020 18:09:51 +0530 Subject: [PATCH 173/309] JAVA-1525: README updates --- spring-5-reactive-2/README.md | 2 +- spring-5-reactive-client/README.md | 1 + spring-5-reactive/README.md | 3 --- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/spring-5-reactive-2/README.md b/spring-5-reactive-2/README.md index 061c15b148..54f7ad35b1 100644 --- a/spring-5-reactive-2/README.md +++ b/spring-5-reactive-2/README.md @@ -8,5 +8,5 @@ This module contains articles about reactive Spring 5 - [Testing Reactive Streams Using StepVerifier and TestPublisher](https://www.baeldung.com/reactive-streams-step-verifier-test-publisher) - [Debugging Reactive Streams in Spring 5](https://www.baeldung.com/spring-debugging-reactive-streams) - [Static Content in Spring WebFlux](https://www.baeldung.com/spring-webflux-static-content) -- [Spring WebClient Filters](https://www.baeldung.com/spring-webclient-filters) +- [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events) - More articles: [[<-- prev]](/spring-5-reactive) diff --git a/spring-5-reactive-client/README.md b/spring-5-reactive-client/README.md index bb308ae330..eebdc23aed 100644 --- a/spring-5-reactive-client/README.md +++ b/spring-5-reactive-client/README.md @@ -10,3 +10,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Simultaneous Spring WebClient Calls](https://www.baeldung.com/spring-webclient-simultaneous-calls) - [Logging Spring WebClient Calls](https://www.baeldung.com/spring-log-webclient-calls) - [Mocking a WebClient in Spring](https://www.baeldung.com/spring-mocking-webclient) +- [Spring WebClient Filters](https://www.baeldung.com/spring-webclient-filters) diff --git a/spring-5-reactive/README.md b/spring-5-reactive/README.md index 41d831632a..1945b7ea33 100644 --- a/spring-5-reactive/README.md +++ b/spring-5-reactive/README.md @@ -7,14 +7,11 @@ The "REST With Spring" Classes: https://bit.ly/restwithspring ### Relevant Articles -- [Introduction to the Functional Web Framework in Spring 5](https://www.baeldung.com/spring-5-functional-web) - [Spring 5 WebClient](https://www.baeldung.com/spring-5-webclient) - [Exploring the Spring 5 WebFlux URL Matching](https://www.baeldung.com/spring-5-mvc-url-matching) - [Reactive WebSockets with Spring 5](https://www.baeldung.com/spring-5-reactive-websockets) - [Spring Webflux Filters](https://www.baeldung.com/spring-webflux-filters) - [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header) -- [Spring Webflux and CORS](https://www.baeldung.com/spring-webflux-cors) - [Handling Errors in Spring WebFlux](https://www.baeldung.com/spring-webflux-errors) -- [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events) - [A Guide to Spring Session Reactive Support: WebSession](https://www.baeldung.com/spring-session-reactive) - More articles: [[next -->]](/spring-5-reactive-2) From 1deeca3b47f97b31fc8cd0417175d840b9b9537c Mon Sep 17 00:00:00 2001 From: joe zhang Date: Thu, 30 Jul 2020 21:00:51 +0800 Subject: [PATCH 174/309] determine if an Object is of primitive type --- .../java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java index 7d3c2964d4..ff532520c2 100644 --- a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java +++ b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java @@ -11,7 +11,7 @@ public class PrimitiveTypeUtilTest { private PrimitiveTypeUtil primitiveTypeUtil; private boolean booleanVal = false; private Long longWrapper = 1L; - private String nonPrimitiveVal = "Test"; + private String nonPrimitiveVal = "non primitive string"; @Before public void setup() { From f29c757e18aff1a9da058768857bcfd3f24bf0ef Mon Sep 17 00:00:00 2001 From: joe zhang Date: Thu, 30 Jul 2020 21:09:33 +0800 Subject: [PATCH 175/309] determine if an Object is of primitive type --- .../java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java index ff532520c2..411bc422e5 100644 --- a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java +++ b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java @@ -26,7 +26,7 @@ public class PrimitiveTypeUtilTest { } @Test - public void givenObjectWhenCheckWithCommansLangShouldValidate() { + public void givenObjectWhenCheckWithCommonsLangShouldValidate() { assertTrue(primitiveTypeUtil.isPrimitiveTypeByCommansLang(booleanVal)); assertTrue(primitiveTypeUtil.isPrimitiveTypeByCommansLang(longWrapper)); assertFalse(primitiveTypeUtil.isPrimitiveTypeByCommansLang(nonPrimitiveVal)); From 6e43adc10748a9dcaf05acbe11ec0f6ca6961506 Mon Sep 17 00:00:00 2001 From: joe zhang Date: Thu, 30 Jul 2020 21:15:06 +0800 Subject: [PATCH 176/309] determine if an Object is of primitive type --- .../java/com/baeldung/primitivetype/PrimitiveTypeUtil.java | 2 +- .../com/baeldung/primitivetype/PrimitiveTypeUtilTest.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java index c749ed9dcd..1b2083b548 100644 --- a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java @@ -23,7 +23,7 @@ public class PrimitiveTypeUtil { WRAPPER_TYPE_MAP.put(Void.class, void.class); } - public boolean isPrimitiveTypeByCommansLang(Object source) { + public boolean isPrimitiveTypeByCommonsLang(Object source) { return ClassUtils.isPrimitiveOrWrapper(source.getClass()); } diff --git a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java index 411bc422e5..79b58967dd 100644 --- a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java +++ b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java @@ -27,9 +27,9 @@ public class PrimitiveTypeUtilTest { @Test public void givenObjectWhenCheckWithCommonsLangShouldValidate() { - assertTrue(primitiveTypeUtil.isPrimitiveTypeByCommansLang(booleanVal)); - assertTrue(primitiveTypeUtil.isPrimitiveTypeByCommansLang(longWrapper)); - assertFalse(primitiveTypeUtil.isPrimitiveTypeByCommansLang(nonPrimitiveVal)); + assertTrue(primitiveTypeUtil.isPrimitiveTypeByCommonsLang(booleanVal)); + assertTrue(primitiveTypeUtil.isPrimitiveTypeByCommonsLang(longWrapper)); + assertFalse(primitiveTypeUtil.isPrimitiveTypeByCommonsLang(nonPrimitiveVal)); } @Test From ae479954f48ae784e1c7e66a19b03e60cd0b31b7 Mon Sep 17 00:00:00 2001 From: joe zhang Date: Fri, 31 Jul 2020 00:33:26 +0800 Subject: [PATCH 177/309] refactor unit test name --- ...rimitiveTypeUtilTest.java => PrimitiveTypeUtilUnitTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/{PrimitiveTypeUtilTest.java => PrimitiveTypeUtilUnitTest.java} (97%) diff --git a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilUnitTest.java similarity index 97% rename from core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java rename to core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilUnitTest.java index 79b58967dd..5cd1b9f9d7 100644 --- a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilTest.java +++ b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilUnitTest.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; -public class PrimitiveTypeUtilTest { +public class PrimitiveTypeUtilUnitTest { private PrimitiveTypeUtil primitiveTypeUtil; private boolean booleanVal = false; From 79b9df98a2c588bc1270ca788bb48f0d802bafc6 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Thu, 30 Jul 2020 21:52:53 +0430 Subject: [PATCH 178/309] boolean[] vs. BitSet: Which is more efficient? --- jmh/pom.xml | 32 ++ .../java/com/baeldung/bitset/Plotter.java | 36 ++ .../main/java/com/baeldung/bitset/Sizing.java | 17 + .../bitset/VectorOfBitsBenchmark.java | 75 +++ jmh/src/main/resources/bitset/cardinal.csv | 449 ++++++++++++++++++ jmh/src/main/resources/bitset/get.csv | 449 ++++++++++++++++++ jmh/src/main/resources/bitset/set.csv | 449 ++++++++++++++++++ 7 files changed, 1507 insertions(+) create mode 100644 jmh/src/main/java/com/baeldung/bitset/Plotter.java create mode 100644 jmh/src/main/java/com/baeldung/bitset/Sizing.java create mode 100644 jmh/src/main/java/com/baeldung/bitset/VectorOfBitsBenchmark.java create mode 100644 jmh/src/main/resources/bitset/cardinal.csv create mode 100644 jmh/src/main/resources/bitset/get.csv create mode 100644 jmh/src/main/resources/bitset/set.csv diff --git a/jmh/pom.xml b/jmh/pom.xml index 735198036e..16a5bc54a4 100644 --- a/jmh/pom.xml +++ b/jmh/pom.xml @@ -26,6 +26,11 @@ jmh-generator-annprocess ${openjdk.jmh.version} + + org.openjdk.jol + jol-core + ${jol-core.version} + @@ -42,12 +47,39 @@ + + + org.apache.maven.plugins + maven-assembly-plugin + ${maven-assembly-plugin.version} + + + jar-with-dependencies + + + + com.baeldung.BenchmarkRunner + + + + + + make-assembly + package + + single + + + +
1.19 3.0.2 + 0.10 + 3.2.0 \ No newline at end of file diff --git a/jmh/src/main/java/com/baeldung/bitset/Plotter.java b/jmh/src/main/java/com/baeldung/bitset/Plotter.java new file mode 100644 index 0000000000..beb136f515 --- /dev/null +++ b/jmh/src/main/java/com/baeldung/bitset/Plotter.java @@ -0,0 +1,36 @@ +package com.baeldung.bitset; + +import org.openjdk.jol.info.ClassLayout; +import org.openjdk.jol.info.GraphLayout; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.util.BitSet; + +public class Plotter { + + public static void main(String[] args) throws IOException { + Path path = Paths.get("footprint.csv"); + try (BufferedWriter stream = Files.newBufferedWriter(path, StandardOpenOption.CREATE)) { + stream.write("bits,bool,bitset\n"); + + for (int i = 0; i <= 10_000_000; i += 500) { + System.out.println("Number of bits => " + i); + + boolean[] ba = new boolean[i]; + BitSet bitSet = new BitSet(i); + + long baSize = ClassLayout.parseInstance(ba).instanceSize(); + long bitSetSize = GraphLayout.parseInstance(bitSet).totalSize(); + + stream.write((i + "," + baSize + "," + bitSetSize + "\n")); + + if (i % 10_000 == 0) stream.flush(); + } + } + } +} diff --git a/jmh/src/main/java/com/baeldung/bitset/Sizing.java b/jmh/src/main/java/com/baeldung/bitset/Sizing.java new file mode 100644 index 0000000000..58c9061c07 --- /dev/null +++ b/jmh/src/main/java/com/baeldung/bitset/Sizing.java @@ -0,0 +1,17 @@ +package com.baeldung.bitset; + +import org.openjdk.jol.info.ClassLayout; +import org.openjdk.jol.info.GraphLayout; + +import java.util.BitSet; + +public class Sizing { + + public static void main(String[] args) { + boolean[] ba = new boolean[10_000]; + System.out.println(ClassLayout.parseInstance(ba).toPrintable()); + + BitSet bitSet = new BitSet(10_000); + System.out.println(GraphLayout.parseInstance(bitSet).toPrintable()); + } +} diff --git a/jmh/src/main/java/com/baeldung/bitset/VectorOfBitsBenchmark.java b/jmh/src/main/java/com/baeldung/bitset/VectorOfBitsBenchmark.java new file mode 100644 index 0000000000..8949d4e117 --- /dev/null +++ b/jmh/src/main/java/com/baeldung/bitset/VectorOfBitsBenchmark.java @@ -0,0 +1,75 @@ +package com.baeldung.bitset; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Level; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; + +import java.util.BitSet; +import java.util.concurrent.ThreadLocalRandom; + +@State(Scope.Benchmark) +@BenchmarkMode(Mode.Throughput) +public class VectorOfBitsBenchmark { + + private boolean[] array; + private BitSet bitSet; + + @Param({"100", "1000", "5000", "50000", "100000", "1000000", "2000000", "3000000", + "5000000", "7000000", "10000000", "20000000", "30000000", "50000000", "70000000", "1000000000"}) + public int size; + + @Setup(Level.Trial) + public void setUp() { + array = new boolean[size]; + for (int i = 0; i < array.length; i++) { + array[i] = ThreadLocalRandom.current().nextBoolean(); + } + + bitSet = new BitSet(size); + for (int i = 0; i < size; i++) { + bitSet.set(i, ThreadLocalRandom.current().nextBoolean()); + } + } + + @Benchmark + public boolean getBoolArray() { + return array[ThreadLocalRandom.current().nextInt(size)]; + } + + @Benchmark + public boolean getBitSet() { + return bitSet.get(ThreadLocalRandom.current().nextInt(size)); + } + + @Benchmark + public void setBoolArray() { + int index = ThreadLocalRandom.current().nextInt(size); + array[index] = true; + } + + @Benchmark + public void setBitSet() { + int index = ThreadLocalRandom.current().nextInt(size); + bitSet.set(index); + } + + @Benchmark + public int cardinalityBoolArray() { + int sum = 0; + for (boolean b : array) { + if (b) sum++; + } + + return sum; + } + + @Benchmark + public int cardinalityBitSet() { + return bitSet.cardinality(); + } +} diff --git a/jmh/src/main/resources/bitset/cardinal.csv b/jmh/src/main/resources/bitset/cardinal.csv new file mode 100644 index 0000000000..1e6f0731f4 --- /dev/null +++ b/jmh/src/main/resources/bitset/cardinal.csv @@ -0,0 +1,449 @@ +"Benchmark","Mode","Threads","Samples","Score","Score Error (99.9%)","Unit","Param: size" +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,393747573.686833,8176258.509541,"ops/s",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,0.001142,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,16.019285,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,3.525011,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,0.001011,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,0.000227,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,9.978252,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,0.000084,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,16.085984,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.000016,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,3.515332,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,0.000104,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,0.000187,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,51.807801,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,200028477.639536,1655942.004821,"ops/s",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,0.002157,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,30.037472,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,4.035148,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,0.002133,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,0.000533,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,14.964408,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,0.000209,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,30.189211,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.000035,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,4.026334,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,0.000222,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,0.000400,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,99.619362,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,63020698.220022,301117.329336,"ops/s",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,0.006739,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,92.968547,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,4.051628,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,0.005924,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,0.002165,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,29.892853,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,0.000582,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,93.493939,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.000109,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,4.051385,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,0.000724,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,0.001279,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,285.417873,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,7204008.548800,26777.006550,"ops/s",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,0.085737,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,796.749450,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,4.282982,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,0.055282,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,1.012529,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,110.884225,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,0.004487,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,801.165820,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.000784,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,4.226255,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,0.006024,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,0.010046,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,2006.941407,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,3629991.817907,11097.373770,"ops/s",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,0.243416,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,1577.873015,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,4.557042,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,0.106117,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,1.025199,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,205.866839,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,0.011796,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,1584.735453,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.002335,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,4.653284,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,0.012223,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,0.020736,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,3947.152509,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,363285.637971,1381.431204,"ops/s",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,1712.185003,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,15660.070795,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,9.441652,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,1.200677,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,1.744812,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,1963.525342,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,0.452116,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,15734.050011,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.023238,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,9.519313,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,0.190122,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,0.208191,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,38999.133661,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,180844.028528,610.040837,"ops/s",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,3664.111553,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,31271.600037,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,14.435729,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,2.610217,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,1.649819,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,3910.476252,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,0.217432,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,31408.622718,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.040256,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,14.601374,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,0.260903,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,0.422715,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,77788.657874,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,118548.730143,468.823226,"ops/s",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,5639.799222,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,47006.741115,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,19.832762,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,4.059959,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,2.278006,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,5874.367510,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,0.324499,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,47272.836745,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.064460,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,22.600079,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,0.467719,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,0.642886,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,116927.646081,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,70086.673236,563.669183,"ops/s",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,9560.498477,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,78198.576932,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,34.810483,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,6.905933,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,2.660745,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,9767.014432,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,0.616113,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,78630.286046,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.101142,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,31.958140,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,0.716475,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,0.975224,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,194453.814959,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,50185.268564,354.561055,"ops/s",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,13480.043453,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,109488.725728,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,45.881465,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,9.602892,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,2.750373,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,13686.896942,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,1.079668,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,110066.269505,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.186638,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,50.867881,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,1.087789,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,1.401113,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,272641.291312,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,34908.512595,116.418990,"ops/s",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,19358.228821,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,156380.208163,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,52.083219,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,13.328039,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,14.661694,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,19522.637780,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,2.203013,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,156928.984801,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,0.273531,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,67.026094,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,1.900268,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,1.929660,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,388765.349238,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,17317.558001,100.005388,"ops/s",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,38984.617172,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,312761.798113,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,110.924669,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,27.027104,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,11.114591,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,39043.188700,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,16.408157,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,314387.564881,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,1.315988,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,121.913794,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,7.243860,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,2.181325,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,778038.560011,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,11501.959917,57.124269,"ops/s",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,58960.217967,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,469304.081395,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,184.289676,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,48.075359,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,9.470284,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,58590.395636,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,110.391626,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,471624.463912,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,5.747181,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,162.875573,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,13.870816,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,1.683658,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,1168184.932237,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,6853.662641,34.907898,"ops/s",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,98396.707621,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,782412.601151,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,276.504336,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,62.269039,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,14.744583,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,97655.835705,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,463.063389,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,785788.480539,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,9.752381,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,309.916361,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,23.524244,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,3.349640,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,1946858.485637,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,4879.613096,31.364409,"ops/s",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,137967.751689,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,1096110.204019,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,460.349614,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,100.554744,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,21.779339,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,136829.273899,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,651.277926,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,1102431.584828,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,11.249848,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,520.978240,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,32.792037,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,3.967967,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,2727814.788476,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet","thrpt",4,40,224.865509,9.210752,"ops/s",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-load-misses","thrpt",4,2,1190415.055459,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-loads","thrpt",4,2,15632200.467402,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-dcache-stores","thrpt",4,2,19441.575768,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:L1-icache-load-misses","thrpt",4,2,2047.756107,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branch-misses","thrpt",4,2,485.442180,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:branches","thrpt",4,2,1965043.175621,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-load-misses","thrpt",4,2,31032.470870,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-loads","thrpt",4,2,15667116.799869,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-store-misses","thrpt",4,2,143.428283,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:dTLB-stores","thrpt",4,2,11595.673237,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-load-misses","thrpt",4,2,742.352246,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:iTLB-loads","thrpt",4,2,98.480752,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBitSet:instructions","thrpt",4,2,39048358.021105,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,37049279.373531,704963.020277,"ops/s",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,0.011099,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,112.064045,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,4.073352,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,0.009620,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,0.002608,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,29.947392,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,0.001015,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,112.623597,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,0.000228,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,4.075249,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,0.001286,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,0.002188,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,622.445960,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,4096591.017375,15272.062456,"ops/s",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,0.131963,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,1012.474032,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,4.586741,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,0.104217,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,1.022211,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,139.987103,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,0.008928,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,1017.535338,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,0.001594,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,4.600783,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,0.010615,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,0.018421,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,5536.843608,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,832334.798376,3074.911358,"ops/s",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,0.766809,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,5030.987321,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,7.002736,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,0.498173,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,1.086794,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,641.641634,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,0.047561,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,5051.582231,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,0.008993,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,6.752675,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,0.050431,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,0.092294,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,27529.642459,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,83377.631077,255.122714,"ops/s",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,539.461053,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,50020.851413,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,29.937221,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,5.092867,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,4.842983,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,6261.566122,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,0.422246,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,50255.455914,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,0.078430,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,24.798375,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,0.559565,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,0.902338,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,273680.241982,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,41408.544806,165.347056,"ops/s",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,1322.755020,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,99955.008469,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,55.552771,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,10.390631,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,5.861952,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,12500.640365,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,0.769535,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,100406.515812,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,0.150189,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,44.164416,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,1.117459,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,1.825801,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,546990.292774,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,4129.742795,17.898464,"ops/s",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,15349.951857,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,1002365.863265,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,499.940618,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,122.631357,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,28.242979,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,125323.009142,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,13.650726,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,1007023.362826,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,1.912985,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,505.608704,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,14.288697,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,17.956474,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,5484912.917616,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,2077.577519,7.337211,"ops/s",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,31292.588903,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,2001841.397596,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,966.586187,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,238.822058,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,46.510032,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,250019.595282,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,68.527514,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,2009528.999936,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,7.098600,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,950.622751,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,53.292000,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,24.529932,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,10953197.041140,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,1382.303027,4.169656,"ops/s",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,47056.390407,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,3000801.315529,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,1470.047881,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,357.378786,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,60.820713,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,374783.769835,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,252.896052,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,3015767.599869,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,21.872987,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,1524.876162,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,112.567929,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,23.688984,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,16425272.638241,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,829.757845,2.907395,"ops/s",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,79794.283301,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,4999110.374252,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,2878.569713,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,600.944033,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,117.854523,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,624380.185108,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,625.032361,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,5023239.665880,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,32.290537,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,1952.720560,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,194.797679,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,26.471072,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,27353169.238296,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,593.611980,2.520324,"ops/s",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,111485.949371,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,7025474.793043,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,3672.457662,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,817.906535,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,116.322549,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,877217.619856,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,957.823851,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,7057039.698064,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,50.812805,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,3850.388980,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,280.996635,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,55.292762,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,38432075.289421,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,414.148792,1.531335,"ops/s",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,158517.772914,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,10012879.292064,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,5067.772968,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,1159.247229,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,219.525384,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,1250534.640040,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,1355.116322,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,10051566.656711,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,68.965296,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,5208.287470,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,369.777199,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,56.291391,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,54776223.581884,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,207.806128,0.628873,"ops/s",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,304113.485355,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,20023501.895517,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,9779.441786,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,2487.972260,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,400.329711,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,2501297.068694,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,2937.078221,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,20089328.718289,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,131.879427,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,10912.262719,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,707.654814,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,108.177862,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,109579830.457931,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,138.119711,0.500755,"ops/s",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,443956.723054,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,30008750.271844,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,14759.175750,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,3431.902326,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,569.840892,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,3747872.534933,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,4806.051229,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,30144733.769549,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,201.619836,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,17338.732113,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,1098.261594,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,195.410627,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,164166517.089861,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,82.709149,0.295436,"ops/s",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,747996.211010,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,50109102.392841,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,37525.937305,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,6197.904618,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,1079.041011,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,6265857.125983,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,7401.558857,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,50190387.111098,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,343.424195,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,30593.259958,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,1746.881433,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,263.036555,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,274256325.159847,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,59.202337,0.381593,"ops/s",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,1049088.662627,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,70094037.559522,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,70850.762444,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,8257.515781,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,1934.286962,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,8780399.271839,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,10142.237142,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,70255089.174523,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,568.459880,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,60618.442280,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,2578.542787,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,369.873390,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,383542921.407972,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray","thrpt",4,40,4.164406,0.021372,"ops/s",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-load-misses","thrpt",4,2,14724055.231818,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-loads","thrpt",4,2,1002251097.850000,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-dcache-stores","thrpt",4,2,1304484.515909,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:L1-icache-load-misses","thrpt",4,2,94383.129545,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branch-misses","thrpt",4,2,29678.675000,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:branches","thrpt",4,2,126027016.040909,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-load-misses","thrpt",4,2,149098.588636,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-loads","thrpt",4,2,1005716183.827273,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-store-misses","thrpt",4,2,9554.579545,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:dTLB-stores","thrpt",4,2,1637043.229545,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-load-misses","thrpt",4,2,36110.963636,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:iTLB-loads","thrpt",4,2,5566.793182,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.cardinalityBoolArray:instructions","thrpt",4,2,5481003131.631819,NaN,"#/op",1000000000 diff --git a/jmh/src/main/resources/bitset/get.csv b/jmh/src/main/resources/bitset/get.csv new file mode 100644 index 0000000000..2d929d927d --- /dev/null +++ b/jmh/src/main/resources/bitset/get.csv @@ -0,0 +1,449 @@ +"Benchmark","Mode","Threads","Samples","Score","Score Error (99.9%)","Unit","Param: size" +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,184790139.562014,2667066.521846,"ops/s",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.002467,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.050243,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.042285,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.002206,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.000451,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,12.985709,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.000194,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.132320,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000034,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.035930,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000246,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000417,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.781944,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,189890949.805559,659556.001166,"ops/s",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.002317,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.036584,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.044334,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.002032,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.000437,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,12.964305,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.000185,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.148063,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000034,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.029343,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000246,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000403,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.597453,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,189507179.833915,629754.953530,"ops/s",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.002466,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.010134,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.029958,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.002275,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.000384,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,12.962285,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.000216,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.086110,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000033,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.018705,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000208,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000400,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.611799,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,185398269.303855,1908706.853646,"ops/s",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.003713,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.039282,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.044589,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.002108,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.000501,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,12.976543,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.000183,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.144876,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000032,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.036796,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000226,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000391,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.713651,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,187470455.311201,2138324.325624,"ops/s",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.005740,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.045473,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.049532,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.002233,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.000559,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,12.975216,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.000182,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.153817,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000042,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.032749,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000279,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000413,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.694265,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,187899335.193431,1227338.646447,"ops/s",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.757697,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.019129,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.035645,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.002595,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.000815,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,12.962763,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.000243,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.079796,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000043,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.018714,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000220,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000400,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.618577,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,181042070.478268,1034313.105183,"ops/s",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.882631,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.055692,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.046466,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.002913,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.001525,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,12.993797,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.000303,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.145567,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000040,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.036471,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000231,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000414,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.837563,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,157845998.770241,1327029.686173,"ops/s",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.923265,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.039213,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.037515,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.003060,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.002237,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,12.989144,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.000377,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.101674,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000044,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.029822,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000275,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000463,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.821119,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,140194241.226829,586052.963759,"ops/s",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.958165,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.065759,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.052019,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.003590,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.002185,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,12.995694,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.000446,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.147433,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000054,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.039960,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000352,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000494,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.850007,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,134363547.905898,817872.600380,"ops/s",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.973091,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.083157,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.060888,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.003270,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.003700,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,13.012286,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.000645,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.162932,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000064,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.039776,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000402,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000526,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.956471,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,129938742.625757,565110.729002,"ops/s",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,0.982322,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.053334,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.051753,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.003960,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.004344,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,12.996532,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.001074,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.146765,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000087,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.040650,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000515,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000530,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.866671,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,125187585.586497,523512.098380,"ops/s",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,1.004652,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.080247,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.054714,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.003770,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.004486,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,13.010171,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.010580,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.154110,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000215,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.041480,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.000953,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000317,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.947671,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,115627724.299332,638665.572272,"ops/s",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,1.227419,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.079678,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.058129,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.004521,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.009050,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,13.012617,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,0.347392,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.142634,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000659,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.040588,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.001420,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000171,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,90.988720,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,103507035.990670,372081.425396,"ops/s",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,1.490488,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.059971,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.061928,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.004491,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.023517,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,13.022696,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,1.014237,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.140833,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000542,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.047774,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.001546,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000198,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,91.179548,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,100061443.949078,900762.613103,"ops/s",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,1.636879,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.089365,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.066827,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.004394,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.023939,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,13.054928,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,1.300501,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.169242,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.000755,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.059205,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.001714,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000271,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,91.429385,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet","thrpt",4,40,30732326.196764,1902855.641551,"ops/s",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-load-misses","thrpt",4,2,2.010809,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-loads","thrpt",4,2,19.363151,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-dcache-stores","thrpt",4,2,6.239644,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:L1-icache-load-misses","thrpt",4,2,0.014491,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branch-misses","thrpt",4,2,0.079687,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:branches","thrpt",4,2,13.302302,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-load-misses","thrpt",4,2,2.698668,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-loads","thrpt",4,2,19.522360,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-store-misses","thrpt",4,2,0.001826,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:dTLB-stores","thrpt",4,2,6.235821,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-load-misses","thrpt",4,2,0.004974,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:iTLB-loads","thrpt",4,2,0.000684,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBitSet:instructions","thrpt",4,2,93.483709,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,227276865.931318,1065421.113528,"ops/s",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,0.001953,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.036393,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.041004,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.001677,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.000390,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,10.983478,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,0.000158,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.114167,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000029,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.030073,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.000194,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000334,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.747475,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,227967057.968084,1094391.643063,"ops/s",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,0.002196,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.038155,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.046080,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.001821,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.000377,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,10.983017,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,0.000151,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.121232,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000027,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.026809,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.000171,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000319,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.269538,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,227488094.016039,1165579.055001,"ops/s",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,0.002484,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.046268,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.048022,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.001649,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.000417,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,10.993480,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,0.000191,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.116395,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000037,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.030824,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.000201,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000356,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.847281,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,220590635.826749,3222316.343407,"ops/s",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,0.386152,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.014363,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.030620,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.001837,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.000445,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,10.970352,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,0.000175,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.071899,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000033,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.015771,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.000197,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000347,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.159399,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,221812217.619440,1882356.038621,"ops/s",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,0.694581,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.036224,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.045287,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.002024,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.000413,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,10.985217,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,0.000159,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.113544,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000035,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.028587,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.000209,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000352,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.781018,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,155300972.624227,1052925.157790,"ops/s",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,0.974041,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.024109,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.040972,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.002724,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.000890,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,10.983857,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,0.000635,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.114472,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000067,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.029008,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.000370,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000485,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.276632,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,150139628.673692,671406.901317,"ops/s",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,0.991759,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.029834,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.039387,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.002965,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.001613,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,10.986406,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,0.002364,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.083273,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000157,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.020146,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.000647,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000345,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.274963,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,146544479.291686,722153.242446,"ops/s",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,1.019540,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.022684,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.043253,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.003449,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.002115,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,10.981744,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,0.025108,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.105318,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000364,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.024680,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.001022,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000151,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.769956,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,131610185.610556,544416.522700,"ops/s",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,1.450890,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.061835,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.056745,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.003605,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.002344,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,11.003703,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,0.764601,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.121742,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000585,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.033532,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.001213,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000137,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.911556,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,125543684.587399,707062.210707,"ops/s",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,1.681832,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.067818,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.051900,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.003963,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.003560,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,11.013663,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,1.126490,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.114877,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000538,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.039862,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.001300,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000148,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.996294,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,120883159.006800,459519.176985,"ops/s",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,1.941920,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.066701,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.057961,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.004200,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.004289,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,11.012477,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,1.402314,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.140748,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000749,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.049852,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.001377,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000179,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,74.017988,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,108406186.294073,582406.851629,"ops/s",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,2.395980,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.064172,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.058329,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.004261,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.004518,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,11.010508,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,1.726519,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.136526,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.000984,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.045655,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.001481,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000179,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.482638,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,87529931.443741,1955927.694142,"ops/s",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,2.594962,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.073273,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.063886,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.005067,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.009322,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,11.027283,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,1.845592,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.149139,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.001220,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.059616,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.001915,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000267,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,74.146192,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,52236198.372609,491642.796386,"ops/s",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,2.846910,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.152230,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.113607,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.009109,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.024525,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,11.088285,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,2.268730,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.251743,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.001259,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.092143,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.003064,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000363,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,73.596518,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,44791183.851884,214906.900295,"ops/s",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,2.967552,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.120575,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.109277,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.009707,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.024510,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,11.064747,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,2.499734,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.227798,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.001357,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.088992,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.003500,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000441,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,74.451386,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray","thrpt",4,40,37389103.890299,90477.383580,"ops/s",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-load-misses","thrpt",4,2,2.804161,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-loads","thrpt",4,2,18.310702,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-dcache-stores","thrpt",4,2,7.181002,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:L1-icache-load-misses","thrpt",4,2,0.011265,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branch-misses","thrpt",4,2,0.078800,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:branches","thrpt",4,2,11.274916,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-load-misses","thrpt",4,2,3.060411,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-loads","thrpt",4,2,18.390751,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-store-misses","thrpt",4,2,0.001505,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:dTLB-stores","thrpt",4,2,7.194463,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-load-misses","thrpt",4,2,0.004221,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:iTLB-loads","thrpt",4,2,0.000530,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.getBoolArray:instructions","thrpt",4,2,75.278465,NaN,"#/op",1000000000 diff --git a/jmh/src/main/resources/bitset/set.csv b/jmh/src/main/resources/bitset/set.csv new file mode 100644 index 0000000000..18b73bf989 --- /dev/null +++ b/jmh/src/main/resources/bitset/set.csv @@ -0,0 +1,449 @@ +"Benchmark","Mode","Threads","Samples","Score","Score Error (99.9%)","Unit","Param: size" +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,51896464.026542,75862.136758,"ops/s",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,0.455765,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,12.076844,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.058151,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.007209,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.001604,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,9.997170,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000671,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,12.155867,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000133,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.044563,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000883,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.001497,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,63.823169,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,70106741.257282,5675561.652157,"ops/s",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,0.701408,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,13.051907,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.038773,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.005106,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.001640,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,9.981827,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000487,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,13.108384,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000085,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.035609,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000635,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.001048,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,66.690961,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,95463073.139209,1113608.612106,"ops/s",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.081256,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,13.019534,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.030687,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003994,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.000999,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,10.961847,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000316,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,13.096411,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000053,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.025559,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000408,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000741,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,67.633459,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,118050031.787664,869821.142403,"ops/s",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.354826,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,11.035931,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.028466,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003085,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.000714,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,10.968244,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000300,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,11.094508,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000058,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.027209,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000403,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000643,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,66.685716,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,126298073.981831,369299.481879,"ops/s",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.310261,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,13.051825,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.033383,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003348,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.000801,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,9.997344,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000286,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,13.113142,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000045,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.022306,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000356,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000579,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,65.864528,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,130991668.121281,644042.215866,"ops/s",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.331196,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,12.047450,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.028621,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003152,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.001000,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,10.485817,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000319,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,12.101103,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000064,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.024312,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000369,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000587,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,66.301371,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,128165315.820896,496869.372046,"ops/s",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.377167,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,13.042081,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.031912,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003844,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.001726,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,9.984710,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000382,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,13.099182,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000066,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.020885,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000347,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000563,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,65.795765,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,125195342.161850,1957938.686648,"ops/s",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.384964,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,12.054831,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.031343,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003650,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.002185,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,10.499255,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000428,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,12.112498,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000084,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.027300,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000379,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000600,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,66.403520,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,133354250.565847,1255106.085613,"ops/s",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.320524,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,12.048234,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.028165,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003275,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.002304,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,10.488182,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000489,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,12.094041,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000097,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.023713,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000585,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000521,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,66.335488,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,137232624.452804,636350.199734,"ops/s",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.246943,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,13.025392,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.028421,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003476,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.003316,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,9.976549,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000551,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,13.085655,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000081,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.022321,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000476,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000522,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,65.766839,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,143989207.138248,756270.794340,"ops/s",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.182833,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,12.044035,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.027349,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003071,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.004236,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,10.491392,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.000717,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,12.088728,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.000137,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.026174,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000380,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000468,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,66.391401,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,151241501.714891,916836.288585,"ops/s",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.107189,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,12.041025,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.031621,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.002955,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.004243,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,10.497239,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.009641,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,12.098803,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.001624,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.024783,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.000804,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000269,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,66.415849,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,144263237.497241,732977.702789,"ops/s",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.295403,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,12.050585,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.033163,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003160,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.008815,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,10.508266,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.278706,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,12.108627,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.071757,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.030249,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.001102,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000163,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,66.538307,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,135443772.106893,604312.063062,"ops/s",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.597651,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,12.088824,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.049898,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003236,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.023795,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,10.565162,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,0.822377,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,12.127978,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.217013,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.047233,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.001227,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000186,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,67.051735,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,131423130.250911,685419.143744,"ops/s",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,1.830028,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,11.075647,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.048544,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.003294,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.023619,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,11.044497,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,1.021551,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,11.121959,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.318409,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.047471,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.001220,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000154,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,67.422027,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet","thrpt",4,40,50126275.321495,128366.907520,"ops/s",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-load-misses","thrpt",4,2,2.007914,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-loads","thrpt",4,2,13.283731,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-dcache-stores","thrpt",4,2,2.158816,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:L1-icache-load-misses","thrpt",4,2,0.009154,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branch-misses","thrpt",4,2,0.077561,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:branches","thrpt",4,2,10.255507,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-load-misses","thrpt",4,2,2.580432,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-loads","thrpt",4,2,13.332989,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-store-misses","thrpt",4,2,0.240555,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:dTLB-stores","thrpt",4,2,2.141680,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-load-misses","thrpt",4,2,0.003075,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:iTLB-loads","thrpt",4,2,0.000400,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBitSet:instructions","thrpt",4,2,68.183448,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,103190024.246958,1465075.410304,"ops/s",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,0.387288,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.061946,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.041483,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.003577,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.001007,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,7.999897,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.000288,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.121073,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,0.000058,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.034064,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.000424,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000703,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,52.880071,NaN,"#/op",100 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,139443098.218536,1499104.709607,"ops/s",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,0.646658,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.016290,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.026692,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.002577,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.000566,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,7.966181,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.000281,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.090556,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,0.000053,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.025779,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.000324,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000544,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,52.677854,NaN,"#/op",1000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,141884743.566510,786570.828615,"ops/s",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,0.721487,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.046555,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.030607,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.002780,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.000635,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,7.999213,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.000238,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.100109,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,0.000048,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.027592,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.000322,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000530,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,52.883150,NaN,"#/op",5000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,141434121.940795,678907.202147,"ops/s",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,0.737588,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.009752,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.025647,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.002709,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.000564,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,7.966167,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.000248,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.084263,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,0.000061,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.022513,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.000310,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000559,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,52.676130,NaN,"#/op",50000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,141443758.907874,627442.604356,"ops/s",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,0.778842,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.031381,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.028014,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.003220,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.000652,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,7.979226,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.000287,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.089836,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,0.000071,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.023236,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.000286,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000507,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,52.734083,NaN,"#/op",100000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,147240354.620049,715098.421473,"ops/s",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,0.974563,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.031177,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.024039,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.003099,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.000948,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,7.989072,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.000372,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.069719,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,0.000330,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.020618,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.000355,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000477,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,52.839884,NaN,"#/op",1000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,153622403.885271,1327782.331450,"ops/s",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,0.991925,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.032598,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.024720,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.003245,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.001456,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,7.991914,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.000825,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.079811,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,0.001852,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.024947,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.000643,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000377,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,52.870424,NaN,"#/op",2000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,156527596.524201,795077.911203,"ops/s",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,1.014728,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.027806,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.024255,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.003058,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.001984,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,7.990123,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.002815,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.076875,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,0.018651,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.022515,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.000962,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000127,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,52.871439,NaN,"#/op",3000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,158079426.644001,913191.923219,"ops/s",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,1.472277,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.052808,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.029994,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.003121,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.002145,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,8.011432,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.004486,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.093163,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,0.766815,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.025713,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.001161,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000105,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,53.016947,NaN,"#/op",5000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,157390156.667728,672584.777681,"ops/s",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,1.695306,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.053664,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.031368,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.003326,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.003155,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,8.010168,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.005645,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.095965,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,1.128123,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.028504,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.001011,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000110,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,53.003675,NaN,"#/op",7000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,157798980.940213,764697.250786,"ops/s",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,1.952853,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.022777,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.023807,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.003257,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.004008,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,7.990682,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.004266,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.059754,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,1.397186,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.019997,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.001003,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000129,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,52.896245,NaN,"#/op",10000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,150330975.246741,1605620.715961,"ops/s",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,2.378773,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.036047,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.030046,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.003117,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.004204,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,8.001242,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.005145,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.078731,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,1.708955,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.023010,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.001044,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000128,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,52.933174,NaN,"#/op",20000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,114316055.929498,3553753.935720,"ops/s",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,2.573253,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.049313,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.038018,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.003989,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.008927,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,8.014444,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.008533,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.094540,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,1.824349,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.033037,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.001348,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000178,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,53.081475,NaN,"#/op",30000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,62800524.051547,1844174.328399,"ops/s",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,2.806845,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.118333,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.069840,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.007308,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.024665,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,8.083796,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.010630,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.175443,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,2.245008,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.067306,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.002569,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000342,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,53.626962,NaN,"#/op",50000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,51085547.708493,526048.863875,"ops/s",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,2.914760,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.140406,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.094680,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.010137,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.024495,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,8.083728,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.010755,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.191453,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,2.472813,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.075312,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.002962,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000380,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,53.631291,NaN,"#/op",70000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray","thrpt",4,40,35331072.282690,115127.559672,"ops/s",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-load-misses","thrpt",4,2,2.877579,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-loads","thrpt",4,2,10.331614,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-dcache-stores","thrpt",4,2,2.181433,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:L1-icache-load-misses","thrpt",4,2,0.013025,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branch-misses","thrpt",4,2,0.078282,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:branches","thrpt",4,2,8.293426,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-load-misses","thrpt",4,2,0.014965,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-loads","thrpt",4,2,10.351742,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-store-misses","thrpt",4,2,3.067687,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:dTLB-stores","thrpt",4,2,2.142323,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-load-misses","thrpt",4,2,0.004301,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:iTLB-loads","thrpt",4,2,0.000614,NaN,"#/op",1000000000 +"com.baeldung.bitset.VectorOfBitsBenchmark.setBoolArray:instructions","thrpt",4,2,55.399010,NaN,"#/op",1000000000 From ed51104e26ff61c9c245ccfbe53998cb41a2c768 Mon Sep 17 00:00:00 2001 From: vatsalgosar Date: Fri, 31 Jul 2020 01:26:27 +0530 Subject: [PATCH 179/309] BAEL-3941 (#9499) * BAEL-3941 - Code snippets for preserving line breaks using Jsoup while parsing HTML strings * BAEL-3941 - swapped the order of arguments in assertEquals --- .../jsoup/PreservingLineBreaksUnitTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 jsoup/src/test/java/com/baeldung/jsoup/PreservingLineBreaksUnitTest.java diff --git a/jsoup/src/test/java/com/baeldung/jsoup/PreservingLineBreaksUnitTest.java b/jsoup/src/test/java/com/baeldung/jsoup/PreservingLineBreaksUnitTest.java new file mode 100644 index 0000000000..0958fa96e2 --- /dev/null +++ b/jsoup/src/test/java/com/baeldung/jsoup/PreservingLineBreaksUnitTest.java @@ -0,0 +1,39 @@ +package com.baeldung.jsoup; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.safety.Whitelist; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class PreservingLineBreaksUnitTest { + + @Test + public void whenBackSlashNNewLineCharacter_thenPreserveLineBreak() { + String strHTML = "Hello\nworld"; + Document.OutputSettings outputSettings = new Document.OutputSettings(); + outputSettings.prettyPrint(false); + String strWithNewLines = Jsoup.clean(strHTML, "", Whitelist.none(), outputSettings); + assertEquals("Hello\nworld", strWithNewLines); + } + + @Test + public void whenHTMLNewLineCharacters_thenPreserveLineBreak() { + String strHTML = "" + + "Hello" + + "
" + + "World" + + "

Paragraph

" + + ""; + Document jsoupDoc = Jsoup.parse(strHTML); + Document.OutputSettings outputSettings = new Document.OutputSettings(); + outputSettings.prettyPrint(false); + jsoupDoc.outputSettings(outputSettings); + jsoupDoc.select("br").before("\\n"); + jsoupDoc.select("p").before("\\n"); + String str = jsoupDoc.html().replaceAll("\\\\n", "\n"); + String strWithNewLines = + Jsoup.clean(str, "", Whitelist.none(), outputSettings); + assertEquals("Hello\nWorld\nParagraph", strWithNewLines); + } +} From 749bd7e99a5e25124434b8cba97d8bcc2f425459 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Fri, 31 Jul 2020 15:26:27 +0430 Subject: [PATCH 180/309] Improve the Kotlin Jackson module --- .../kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt index 84171d9019..95df57fb1e 100644 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt +++ b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt @@ -59,7 +59,11 @@ class JacksonUnitTest { val aMap: Map = mapper.readValue(json) assertEquals(aMap[1], "one") - assertEquals(aMap[2], "two") + assertEquals(aMap[2], "two") + + val sameMap = mapper.readValue>(json) + assertEquals(sameMap[1], "one") + assertEquals(sameMap[2], "two") } @Test From 508b4a2939cb8170a75c51ac20a3b3c65c6519f9 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Fri, 31 Jul 2020 15:31:51 +0430 Subject: [PATCH 181/309] Added Reified Style to the List Example --- .../kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt index 95df57fb1e..0c72edc2fd 100644 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt +++ b/kotlin-libraries-2/src/test/kotlin/com/baeldung/kotlin/jackson/JacksonUnitTest.kt @@ -85,7 +85,11 @@ class JacksonUnitTest { val movie1 = Movie("Endgame", "Marvel", 9.2f) val movie2 = Movie("Shazam", "Warner Bros", 7.6f) assertTrue(movieList.contains(movie1)) - assertTrue(movieList.contains(movie2)) + assertTrue(movieList.contains(movie2)) + + val sameList = mapper.readValue>(json) + assertTrue(sameList.contains(movie1)) + assertTrue(sameList.contains(movie2)) } @Test From c748e8172352f8e65401048c6d668e1cdac4f102 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Fri, 31 Jul 2020 22:02:44 +0200 Subject: [PATCH 182/309] JAVA-17: Move Running Setup Data on Startup in Spring into spring-boot-data --- spring-boot-modules/spring-boot-data/README.md | 1 + .../com/baeldung/startup/AllStrategiesExampleBean.java | 1 - .../com/baeldung/startup/EventListenerExampleBean.java | 1 - .../java/com/baeldung/startup/InitMethodExampleBean.java | 4 ++-- .../com/baeldung/startup/InitializingBeanExampleBean.java | 4 ++-- .../java/com/baeldung/startup/InvalidInitExampleBean.java | 0 .../baeldung/startup/LogicInConstructorExampleBean.java | 4 ++-- .../com/baeldung/startup/PostConstructExampleBean.java | 7 +++---- .../java/com/baeldung/startup/SpringStartupConfig.java | 0 .../startup/StartupApplicationListenerExample.java | 1 - .../spring-boot-data}/src/main/resources/startupConfig.xml | 0 .../com/baeldung/startup/SpringStartupIntegrationTest.java | 0 .../startup/SpringStartupXMLConfigIntegrationTest.java | 0 spring-boot-modules/spring-boot/README.MD | 1 - spring-core-4/README.md | 1 - 15 files changed, 10 insertions(+), 15 deletions(-) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/main/java/com/baeldung/startup/AllStrategiesExampleBean.java (99%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/main/java/com/baeldung/startup/EventListenerExampleBean.java (99%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/main/java/com/baeldung/startup/InitMethodExampleBean.java (100%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/main/java/com/baeldung/startup/InitializingBeanExampleBean.java (100%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/main/java/com/baeldung/startup/InvalidInitExampleBean.java (100%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/main/java/com/baeldung/startup/LogicInConstructorExampleBean.java (100%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/main/java/com/baeldung/startup/PostConstructExampleBean.java (99%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/main/java/com/baeldung/startup/SpringStartupConfig.java (100%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/main/java/com/baeldung/startup/StartupApplicationListenerExample.java (99%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/main/resources/startupConfig.xml (100%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/test/java/com/baeldung/startup/SpringStartupIntegrationTest.java (100%) rename {spring-core-4 => spring-boot-modules/spring-boot-data}/src/test/java/com/baeldung/startup/SpringStartupXMLConfigIntegrationTest.java (100%) diff --git a/spring-boot-modules/spring-boot-data/README.md b/spring-boot-modules/spring-boot-data/README.md index faa38d475e..98589cf2d2 100644 --- a/spring-boot-modules/spring-boot-data/README.md +++ b/spring-boot-modules/spring-boot-data/README.md @@ -10,3 +10,4 @@ This module contains articles about Spring Boot with Spring Data - [Repositories with Multiple Spring Data Modules](https://www.baeldung.com/spring-multiple-data-modules) - [Spring Custom Property Editor](https://www.baeldung.com/spring-mvc-custom-property-editor) - [Using @JsonComponent in Spring Boot](https://www.baeldung.com/spring-boot-jsoncomponent) +- [Running Setup Data on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) diff --git a/spring-core-4/src/main/java/com/baeldung/startup/AllStrategiesExampleBean.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/AllStrategiesExampleBean.java similarity index 99% rename from spring-core-4/src/main/java/com/baeldung/startup/AllStrategiesExampleBean.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/AllStrategiesExampleBean.java index e08309d474..53b81da340 100644 --- a/spring-core-4/src/main/java/com/baeldung/startup/AllStrategiesExampleBean.java +++ b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/AllStrategiesExampleBean.java @@ -2,7 +2,6 @@ package com.baeldung.startup; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.springframework.beans.factory.InitializingBean; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; diff --git a/spring-core-4/src/main/java/com/baeldung/startup/EventListenerExampleBean.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/EventListenerExampleBean.java similarity index 99% rename from spring-core-4/src/main/java/com/baeldung/startup/EventListenerExampleBean.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/EventListenerExampleBean.java index a76fc6a2b2..8a2e36ed8e 100644 --- a/spring-core-4/src/main/java/com/baeldung/startup/EventListenerExampleBean.java +++ b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/EventListenerExampleBean.java @@ -2,7 +2,6 @@ package com.baeldung.startup; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; diff --git a/spring-core-4/src/main/java/com/baeldung/startup/InitMethodExampleBean.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/InitMethodExampleBean.java similarity index 100% rename from spring-core-4/src/main/java/com/baeldung/startup/InitMethodExampleBean.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/InitMethodExampleBean.java index a3b12028d1..86f61dd395 100644 --- a/spring-core-4/src/main/java/com/baeldung/startup/InitMethodExampleBean.java +++ b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/InitMethodExampleBean.java @@ -1,7 +1,5 @@ package com.baeldung.startup; -import java.util.Arrays; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -9,6 +7,8 @@ import org.springframework.context.annotation.Scope; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import java.util.Arrays; + @Component @Scope(value = "prototype") public class InitMethodExampleBean { diff --git a/spring-core-4/src/main/java/com/baeldung/startup/InitializingBeanExampleBean.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/InitializingBeanExampleBean.java similarity index 100% rename from spring-core-4/src/main/java/com/baeldung/startup/InitializingBeanExampleBean.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/InitializingBeanExampleBean.java index c625a172fd..8fef3bf8b7 100644 --- a/spring-core-4/src/main/java/com/baeldung/startup/InitializingBeanExampleBean.java +++ b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/InitializingBeanExampleBean.java @@ -1,7 +1,5 @@ package com.baeldung.startup; -import java.util.Arrays; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; @@ -10,6 +8,8 @@ import org.springframework.context.annotation.Scope; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import java.util.Arrays; + @Component @Scope(value = "prototype") public class InitializingBeanExampleBean implements InitializingBean { diff --git a/spring-core-4/src/main/java/com/baeldung/startup/InvalidInitExampleBean.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/InvalidInitExampleBean.java similarity index 100% rename from spring-core-4/src/main/java/com/baeldung/startup/InvalidInitExampleBean.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/InvalidInitExampleBean.java diff --git a/spring-core-4/src/main/java/com/baeldung/startup/LogicInConstructorExampleBean.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/LogicInConstructorExampleBean.java similarity index 100% rename from spring-core-4/src/main/java/com/baeldung/startup/LogicInConstructorExampleBean.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/LogicInConstructorExampleBean.java index ade7573bbe..b4a102b09d 100644 --- a/spring-core-4/src/main/java/com/baeldung/startup/LogicInConstructorExampleBean.java +++ b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/LogicInConstructorExampleBean.java @@ -1,7 +1,5 @@ package com.baeldung.startup; -import java.util.Arrays; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -9,6 +7,8 @@ import org.springframework.context.annotation.Scope; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import java.util.Arrays; + @Component @Scope(value = "prototype") public class LogicInConstructorExampleBean { diff --git a/spring-core-4/src/main/java/com/baeldung/startup/PostConstructExampleBean.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/PostConstructExampleBean.java similarity index 99% rename from spring-core-4/src/main/java/com/baeldung/startup/PostConstructExampleBean.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/PostConstructExampleBean.java index 1001043d86..337aa1520a 100644 --- a/spring-core-4/src/main/java/com/baeldung/startup/PostConstructExampleBean.java +++ b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/PostConstructExampleBean.java @@ -1,9 +1,5 @@ package com.baeldung.startup; -import java.util.Arrays; - -import javax.annotation.PostConstruct; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -11,6 +7,9 @@ import org.springframework.context.annotation.Scope; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; +import javax.annotation.PostConstruct; +import java.util.Arrays; + @Component @Scope(value = "prototype") public class PostConstructExampleBean { diff --git a/spring-core-4/src/main/java/com/baeldung/startup/SpringStartupConfig.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/SpringStartupConfig.java similarity index 100% rename from spring-core-4/src/main/java/com/baeldung/startup/SpringStartupConfig.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/SpringStartupConfig.java diff --git a/spring-core-4/src/main/java/com/baeldung/startup/StartupApplicationListenerExample.java b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/StartupApplicationListenerExample.java similarity index 99% rename from spring-core-4/src/main/java/com/baeldung/startup/StartupApplicationListenerExample.java rename to spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/StartupApplicationListenerExample.java index 2cc5e6abcb..345fb3a625 100644 --- a/spring-core-4/src/main/java/com/baeldung/startup/StartupApplicationListenerExample.java +++ b/spring-boot-modules/spring-boot-data/src/main/java/com/baeldung/startup/StartupApplicationListenerExample.java @@ -2,7 +2,6 @@ package com.baeldung.startup; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.stereotype.Component; diff --git a/spring-core-4/src/main/resources/startupConfig.xml b/spring-boot-modules/spring-boot-data/src/main/resources/startupConfig.xml similarity index 100% rename from spring-core-4/src/main/resources/startupConfig.xml rename to spring-boot-modules/spring-boot-data/src/main/resources/startupConfig.xml diff --git a/spring-core-4/src/test/java/com/baeldung/startup/SpringStartupIntegrationTest.java b/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupIntegrationTest.java similarity index 100% rename from spring-core-4/src/test/java/com/baeldung/startup/SpringStartupIntegrationTest.java rename to spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupIntegrationTest.java diff --git a/spring-core-4/src/test/java/com/baeldung/startup/SpringStartupXMLConfigIntegrationTest.java b/spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupXMLConfigIntegrationTest.java similarity index 100% rename from spring-core-4/src/test/java/com/baeldung/startup/SpringStartupXMLConfigIntegrationTest.java rename to spring-boot-modules/spring-boot-data/src/test/java/com/baeldung/startup/SpringStartupXMLConfigIntegrationTest.java diff --git a/spring-boot-modules/spring-boot/README.MD b/spring-boot-modules/spring-boot/README.MD index fb1c20e988..c95fe51842 100644 --- a/spring-boot-modules/spring-boot/README.MD +++ b/spring-boot-modules/spring-boot/README.MD @@ -25,4 +25,3 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks) - [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot) - [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation) -- [Running Setup Data on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) diff --git a/spring-core-4/README.md b/spring-core-4/README.md index 83b5c4933d..03a6747c1d 100644 --- a/spring-core-4/README.md +++ b/spring-core-4/README.md @@ -9,7 +9,6 @@ This module contains articles about core Spring functionality - [Spring @Import Annotation](https://www.baeldung.com/spring-import-annotation) - [Spring BeanPostProcessor](https://www.baeldung.com/spring-beanpostprocessor) - [Using @Autowired in Abstract Classes](https://www.baeldung.com/spring-autowired-abstract-class) -- [Running Setup Data on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) - [Constructor Injection in Spring with Lombok](https://www.baeldung.com/spring-injection-lombok) - [The Spring ApplicationContext](https://www.baeldung.com/spring-application-context) - More articles: [[<-- prev]](/spring-core-3) From 21342c2f46c08e54b8bc3cf259f78e99b34e1f4a Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Sat, 1 Aug 2020 20:40:45 +0430 Subject: [PATCH 183/309] Resolved the Comments --- jmh/src/main/java/com/baeldung/bitset/Plotter.java | 4 +++- .../java/com/baeldung/bitset/VectorOfBitsBenchmark.java | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jmh/src/main/java/com/baeldung/bitset/Plotter.java b/jmh/src/main/java/com/baeldung/bitset/Plotter.java index beb136f515..0d065ea185 100644 --- a/jmh/src/main/java/com/baeldung/bitset/Plotter.java +++ b/jmh/src/main/java/com/baeldung/bitset/Plotter.java @@ -29,7 +29,9 @@ public class Plotter { stream.write((i + "," + baSize + "," + bitSetSize + "\n")); - if (i % 10_000 == 0) stream.flush(); + if (i % 10_000 == 0) { + stream.flush(); + } } } } diff --git a/jmh/src/main/java/com/baeldung/bitset/VectorOfBitsBenchmark.java b/jmh/src/main/java/com/baeldung/bitset/VectorOfBitsBenchmark.java index 8949d4e117..7bbf00f36c 100644 --- a/jmh/src/main/java/com/baeldung/bitset/VectorOfBitsBenchmark.java +++ b/jmh/src/main/java/com/baeldung/bitset/VectorOfBitsBenchmark.java @@ -19,8 +19,8 @@ public class VectorOfBitsBenchmark { private boolean[] array; private BitSet bitSet; - @Param({"100", "1000", "5000", "50000", "100000", "1000000", "2000000", "3000000", - "5000000", "7000000", "10000000", "20000000", "30000000", "50000000", "70000000", "1000000000"}) + @Param({"100", "1000", "5000", "50000", "100000", "1000000", "2000000", "3000000", "5000000", + "7000000", "10000000", "20000000", "30000000", "50000000", "70000000", "1000000000"}) public int size; @Setup(Level.Trial) @@ -62,7 +62,9 @@ public class VectorOfBitsBenchmark { public int cardinalityBoolArray() { int sum = 0; for (boolean b : array) { - if (b) sum++; + if (b) { + sum++; + } } return sum; From 6092afb60a41d696ce0b838de7493269093ba58a Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sat, 1 Aug 2020 22:41:28 +0530 Subject: [PATCH 184/309] Implementing Code Review comments -3 --- .../spring/data/cosmosdb/controller/ProductController.java | 5 ----- .../spring/data/cosmosdb/repository/ProductRepository.java | 1 - .../spring/data/cosmosdb/service/ProductService.java | 6 +----- .../data/cosmosdb/AzurecosmodbApplicationManualTest.java | 7 +++---- 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java index fe02be88ff..25f88bac72 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/controller/ProductController.java @@ -50,9 +50,4 @@ public class ProductController { return productService.findProductByName(name); } - @GetMapping(value = "/category") - public List getByCategory(@RequestParam String category) { - return productService.getProductsOfCategory(category); - } - } diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java index 29dc85a2cf..1e4a2987a1 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/repository/ProductRepository.java @@ -11,5 +11,4 @@ import java.util.List; public interface ProductRepository extends CosmosRepository { List findByProductName(String productName); - List findByProductCategory(String category); } diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java index 49d07ca5a2..0d1cf7c6a6 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/service/ProductService.java @@ -14,7 +14,7 @@ import java.util.Optional; public class ProductService { private ProductRepository repository; - + @Autowired public ProductService(ProductRepository repository) { this.repository = repository; @@ -28,10 +28,6 @@ public class ProductService { return repository.findById(productId, new PartitionKey(category)); } - public List getProductsOfCategory(String category) { - return repository.findByProductCategory(category); - } - public void saveProduct(Product product) { repository.save(product); } diff --git a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java index 786b578501..7ebdce279b 100644 --- a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java +++ b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java @@ -9,8 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.util.Assert; -import java.util.Optional; - @SpringBootTest public class AzurecosmodbApplicationManualTest { @@ -26,8 +24,9 @@ public class AzurecosmodbApplicationManualTest { product.setProductName("Blue Shirt"); productRepository.save(product); - Optional retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt")); - Assert.notNull(retrievedProduct.get(), "Retrieved Product is Null"); + Product retrievedProduct = productRepository.findById("1001", new PartitionKey("Shirt")) + .orElse(null); + Assert.notNull(retrievedProduct, "Retrieved Product is Null"); } From 623eaff91dae4c40d79588d350d0869f8bf53208 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 2 Aug 2020 00:55:58 +0530 Subject: [PATCH 185/309] ingore files generated after build --- .gitignore | 1 + spring-soap/.gitignore | 1 + spring-soap/pom.xml | 1 + .../java/com/baeldung/springsoap/client/gen/Country.java | 7 ------- .../java/com/baeldung/springsoap/client/gen/Currency.java | 7 ------- .../baeldung/springsoap/client/gen/GetCountryRequest.java | 7 ------- .../baeldung/springsoap/client/gen/GetCountryResponse.java | 7 ------- .../com/baeldung/springsoap/client/gen/ObjectFactory.java | 7 ------- .../com/baeldung/springsoap/client/gen/package-info.java | 7 ------- 9 files changed, 3 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index c54117203f..fe56746dfd 100644 --- a/.gitignore +++ b/.gitignore @@ -85,5 +85,6 @@ transaction.log *-shell.log apache-cxf/cxf-aegis/baeldung.xml +testing-modules/report-*.json libraries-2/*.db \ No newline at end of file diff --git a/spring-soap/.gitignore b/spring-soap/.gitignore index b83d22266a..cce17abdb9 100644 --- a/spring-soap/.gitignore +++ b/spring-soap/.gitignore @@ -1 +1,2 @@ /target/ +sun-jaxb.episode diff --git a/spring-soap/pom.xml b/spring-soap/pom.xml index 137ff03c31..bea3d033e6 100644 --- a/spring-soap/pom.xml +++ b/spring-soap/pom.xml @@ -75,6 +75,7 @@ ${project.basedir}/src/main/java com.baeldung.springsoap.client.gen ${project.basedir}/src/main/resources + true countries.wsdl diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Country.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Country.java index e17dce55f9..bb196d625d 100644 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Country.java +++ b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Country.java @@ -1,10 +1,3 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0 -// See https://javaee.github.io/jaxb-v2/ -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2020.04.25 at 03:18:49 PM IST -// - package com.baeldung.springsoap.client.gen; diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Currency.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Currency.java index 12fdef58c2..023a8103e5 100644 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Currency.java +++ b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/Currency.java @@ -1,10 +1,3 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0 -// See https://javaee.github.io/jaxb-v2/ -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2020.04.25 at 03:18:49 PM IST -// - package com.baeldung.springsoap.client.gen; diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryRequest.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryRequest.java index 5739ee3b96..dcd5b1f08b 100644 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryRequest.java +++ b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryRequest.java @@ -1,10 +1,3 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0 -// See https://javaee.github.io/jaxb-v2/ -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2020.04.25 at 03:18:49 PM IST -// - package com.baeldung.springsoap.client.gen; diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryResponse.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryResponse.java index ba1ab56cf8..11135c32e1 100644 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryResponse.java +++ b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/GetCountryResponse.java @@ -1,10 +1,3 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0 -// See https://javaee.github.io/jaxb-v2/ -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2020.04.25 at 03:18:49 PM IST -// - package com.baeldung.springsoap.client.gen; diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/ObjectFactory.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/ObjectFactory.java index 88b27245be..e6d56d5aba 100644 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/ObjectFactory.java +++ b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/ObjectFactory.java @@ -1,10 +1,3 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0 -// See https://javaee.github.io/jaxb-v2/ -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2020.04.25 at 03:18:49 PM IST -// - package com.baeldung.springsoap.client.gen; diff --git a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/package-info.java b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/package-info.java index eefed169a8..9432e0c328 100644 --- a/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/package-info.java +++ b/spring-soap/src/main/java/com/baeldung/springsoap/client/gen/package-info.java @@ -1,9 +1,2 @@ -// -// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.3.0 -// See https://javaee.github.io/jaxb-v2/ -// Any modifications to this file will be lost upon recompilation of the source schema. -// Generated on: 2020.04.25 at 03:18:49 PM IST -// - @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.baeldung.com/springsoap/gen", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package com.baeldung.springsoap.client.gen; From f18d4dfa987399981d3c4e9dddaaf4cd5588d7f6 Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Sun, 2 Aug 2020 01:39:35 +0530 Subject: [PATCH 186/309] BAEL-3836: Fix failing test in core-java-concurrency-advanced-3 (#9806) * BAEL-3836: Fix failing test in core-java-concurrency-advanced-3 * BAEL-3836: Fix failing test in core-java-concurrency-advanced-3 --- ...UnitManualTest.java => PrimeNumbersManualTest.java} | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) rename core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/{PrimeNumbersUnitManualTest.java => PrimeNumbersManualTest.java} (93%) diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersUnitManualTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersManualTest.java similarity index 93% rename from core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersUnitManualTest.java rename to core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersManualTest.java index 4fbbef4e61..8d12218c05 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersUnitManualTest.java +++ b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersManualTest.java @@ -15,7 +15,15 @@ import java.util.logging.Logger; import static org.junit.Assert.fail; -public class PrimeNumbersUnitManualTest { +/** + * This test expects the file target/test-classes/META-INF/BenchmarkList to be present. + * + * Before running the test ensure that the file is present. + * If not, please run mvn install on the module. + * + */ + +public class PrimeNumbersManualTest { private static Logger logger = Logger.getAnonymousLogger(); From 71cd51e85fe028784c1a7c936289fa88f30214ff Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 2 Aug 2020 02:07:30 +0530 Subject: [PATCH 187/309] align module name & artifactId --- persistence-modules/flyway-repair/pom.xml | 2 +- persistence-modules/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence-modules/flyway-repair/pom.xml b/persistence-modules/flyway-repair/pom.xml index 4d61bd5c0e..5a5c4103f6 100644 --- a/persistence-modules/flyway-repair/pom.xml +++ b/persistence-modules/flyway-repair/pom.xml @@ -2,7 +2,7 @@ 4.0.0 - flyway + flyway-repair flyway-repair jar Flyway Repair Demo diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index c598ad8805..31b9aaaf6d 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -19,7 +19,7 @@ core-java-persistence deltaspike elasticsearch - flyway + flyway-repair hbase hibernate5 hibernate-mapping From 6fc0c42586e2c85390a5d58cfbf43cc994482083 Mon Sep 17 00:00:00 2001 From: Maja Joksovic Date: Sat, 1 Aug 2020 22:58:00 +0200 Subject: [PATCH 188/309] fixed indentation --- .../com/baeldung/copydirectory/JavaNio.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java index fe1eb59c64..b574042ee5 100644 --- a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java +++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java @@ -9,14 +9,14 @@ public class JavaNio { public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException { Files.walk(Paths.get(sourceDirectoryLocation)) - .forEach(source -> { - Path destination = Paths.get(destinationDirectoryLocation, source.toString() - .substring(sourceDirectoryLocation.length())); - try { - Files.copy(source, destination); - } catch (IOException e) { - e.printStackTrace(); - } - }); + .forEach(source -> { + Path destination = Paths.get(destinationDirectoryLocation, source.toString() + .substring(sourceDirectoryLocation.length())); + try { + Files.copy(source, destination); + } catch (IOException e) { + e.printStackTrace(); + } + }); } } From 314910468f9981eb884bb4279526eaccb68b146b Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 2 Aug 2020 03:47:35 +0530 Subject: [PATCH 189/309] used release repository --- maven-modules/versions-maven-plugin/original/pom.xml | 6 +++--- maven-modules/versions-maven-plugin/pom.xml | 6 +++--- parent-kotlin/pom.xml | 4 ++-- spring-boot-modules/spring-boot-mvc-2/pom.xml | 6 +++--- spring-boot-modules/spring-boot-mvc/pom.xml | 6 +++--- spring-mobile/pom.xml | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/maven-modules/versions-maven-plugin/original/pom.xml b/maven-modules/versions-maven-plugin/original/pom.xml index f81596661e..f705dae5c5 100644 --- a/maven-modules/versions-maven-plugin/original/pom.xml +++ b/maven-modules/versions-maven-plugin/original/pom.xml @@ -58,9 +58,9 @@ - apache.snapshots - Apache Development Snapshot Repository - https://repository.apache.org/content/repositories/snapshots/ + apache.releases + Apache Development Release Repository + https://repository.apache.org/content/repositories/releases/ false diff --git a/maven-modules/versions-maven-plugin/pom.xml b/maven-modules/versions-maven-plugin/pom.xml index 9793f55b28..3a9134ff40 100644 --- a/maven-modules/versions-maven-plugin/pom.xml +++ b/maven-modules/versions-maven-plugin/pom.xml @@ -57,9 +57,9 @@ - apache.snapshots - Apache Development Snapshot Repository - https://repository.apache.org/content/repositories/snapshots/ + apache.releases + Apache Development Release Repository + https://repository.apache.org/content/repositories/releases/ false diff --git a/parent-kotlin/pom.xml b/parent-kotlin/pom.xml index 947dd20483..f8a95e235a 100644 --- a/parent-kotlin/pom.xml +++ b/parent-kotlin/pom.xml @@ -30,8 +30,8 @@ spring-milestone - Spring Milestone Repository - https://repo.spring.io/milestone + Spring Release Repository + https://repo.spring.io/release diff --git a/spring-boot-modules/spring-boot-mvc-2/pom.xml b/spring-boot-modules/spring-boot-mvc-2/pom.xml index 73a75f020c..0b9213a7ea 100644 --- a/spring-boot-modules/spring-boot-mvc-2/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-2/pom.xml @@ -90,15 +90,15 @@ - jcenter-snapshots + jcenter-release jcenter - http://oss.jfrog.org/artifactory/oss-snapshot-local/ + http://oss.jfrog.org/artifactory/oss-release-local/ - 3.0.0-SNAPSHOT + 3.0.0 com.baeldung.swagger2boot.SpringBootSwaggerApplication 1.4.11.1 diff --git a/spring-boot-modules/spring-boot-mvc/pom.xml b/spring-boot-modules/spring-boot-mvc/pom.xml index fd6f1b0a8a..9ae6d8341a 100644 --- a/spring-boot-modules/spring-boot-mvc/pom.xml +++ b/spring-boot-modules/spring-boot-mvc/pom.xml @@ -20,9 +20,9 @@ - jcenter-snapshots + jcenter-release jcenter - http://oss.jfrog.org/artifactory/oss-snapshot-local/ + http://oss.jfrog.org/artifactory/oss-release-local/ @@ -148,7 +148,7 @@ - 3.0.0-SNAPSHOT + 3.0.0 1.10.0 2.3.7 diff --git a/spring-mobile/pom.xml b/spring-mobile/pom.xml index 465458ba49..bb2b418a55 100644 --- a/spring-mobile/pom.xml +++ b/spring-mobile/pom.xml @@ -33,8 +33,8 @@ spring-milestones - Spring Milestones - https://repo.spring.io/libs-milestone + Spring Release + https://repo.spring.io/libs-release false From bff407ca059e733f1aea457e78a5c477a3654255 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 2 Aug 2020 03:51:32 +0530 Subject: [PATCH 190/309] used release repository --- parent-kotlin/pom.xml | 4 ++-- spring-mobile/pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/parent-kotlin/pom.xml b/parent-kotlin/pom.xml index f8a95e235a..947dd20483 100644 --- a/parent-kotlin/pom.xml +++ b/parent-kotlin/pom.xml @@ -30,8 +30,8 @@ spring-milestone - Spring Release Repository - https://repo.spring.io/release + Spring Milestone Repository + https://repo.spring.io/milestone diff --git a/spring-mobile/pom.xml b/spring-mobile/pom.xml index bb2b418a55..465458ba49 100644 --- a/spring-mobile/pom.xml +++ b/spring-mobile/pom.xml @@ -33,8 +33,8 @@ spring-milestones - Spring Release - https://repo.spring.io/libs-release + Spring Milestones + https://repo.spring.io/libs-milestone false From 80091e154ad6b6d0293ccb7997e26af601dafc01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dupire?= Date: Sun, 2 Aug 2020 13:27:31 +0200 Subject: [PATCH 191/309] [JAVA-2276] Upgraded maven-assembly-plugin version to 3.3.0 (#9801) --- spring-boot-modules/spring-boot-crud/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-crud/pom.xml b/spring-boot-modules/spring-boot-crud/pom.xml index 8ba7bab171..a4be360b0f 100644 --- a/spring-boot-modules/spring-boot-crud/pom.xml +++ b/spring-boot-modules/spring-boot-crud/pom.xml @@ -63,6 +63,7 @@ org.apache.maven.plugins maven-assembly-plugin + 3.3.0 jar-with-dependencies From 8527d5806334d266ac13e91acd0f6cf34a02bae9 Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Sun, 2 Aug 2020 20:00:53 +0430 Subject: [PATCH 192/309] BAEL-4391: Check if a file exists in Java (#9748) * Check if a file exists in Java * Simple Assertions --- core-java-modules/core-java-io-3/.gitignore | 2 + .../baeldung/existence/ExistenceUnitTest.java | 91 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 core-java-modules/core-java-io-3/.gitignore create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java diff --git a/core-java-modules/core-java-io-3/.gitignore b/core-java-modules/core-java-io-3/.gitignore new file mode 100644 index 0000000000..0c0cd871c5 --- /dev/null +++ b/core-java-modules/core-java-io-3/.gitignore @@ -0,0 +1,2 @@ +test-link* +0.* \ No newline at end of file diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java new file mode 100644 index 0000000000..c52e46e8c1 --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java @@ -0,0 +1,91 @@ +package com.baeldung.existence; + +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.concurrent.ThreadLocalRandom; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ExistenceUnitTest { + + @Test + public void givenFile_whenDoesNotExist_thenFilesReturnsFalse() { + Path path = Paths.get("does-not-exist.txt"); + + assertFalse(Files.exists(path)); + assertTrue(Files.notExists(path)); + } + + @Test + public void givenFile_whenExists_thenFilesShouldReturnTrue() throws IOException { + Path tempFile = Files.createTempFile("baeldung", "exist-nio"); + assertTrue(Files.exists(tempFile)); + assertFalse(Files.notExists(tempFile)); + + Path tempDirectory = Files.createTempDirectory("baeldung-exists"); + assertTrue(Files.exists(tempDirectory)); + assertFalse(Files.notExists(tempDirectory)); + + assertTrue(Files.isDirectory(tempDirectory)); + assertFalse(Files.isDirectory(tempFile)); + assertTrue(Files.isRegularFile(tempFile)); + + assertTrue(Files.isReadable(tempFile)); + + Files.deleteIfExists(tempFile); + Files.deleteIfExists(tempDirectory); + } + + @Test + public void givenSymbolicLink_whenTargetDoesNotExists_thenFollowOrNotBasedOnTheOptions() throws IOException { + Path target = Files.createTempFile("baeldung", "target"); + Path symbol = Paths.get("test-link-" + ThreadLocalRandom.current().nextInt()); + + Path symbolicLink = Files.createSymbolicLink(symbol, target); + assertTrue(Files.exists(symbolicLink)); + assertTrue(Files.isSymbolicLink(symbolicLink)); + assertFalse(Files.isSymbolicLink(target)); + + Files.deleteIfExists(target); + assertFalse(Files.exists(symbolicLink)); + assertTrue(Files.exists(symbolicLink, LinkOption.NOFOLLOW_LINKS)); + + Files.deleteIfExists(symbolicLink); + } + + @Test + public void givenFile_whenDoesNotExist_thenFileReturnsFalse() { + assertFalse(new File("invalid").exists()); + assertFalse(new File("invalid").isFile()); + } + + @Test + public void givenFile_whenExist_thenShouldReturnTrue() throws IOException { + Path tempFilePath = Files.createTempFile("baeldung", "exist-io"); + Path tempDirectoryPath = Files.createTempDirectory("baeldung-exists-io"); + + File tempFile = new File(tempFilePath.toString()); + File tempDirectory = new File(tempDirectoryPath.toString()); + + assertTrue(tempFile.exists()); + assertTrue(tempDirectory.exists()); + + assertTrue(tempFile.isFile()); + assertFalse(tempDirectory.isFile()); + + assertTrue(tempDirectory.isDirectory()); + assertFalse(tempFile.isDirectory()); + + assertTrue(tempFile.canRead()); + + Files.deleteIfExists(tempFilePath); + Files.deleteIfExists(tempDirectoryPath); + } +} From 353f454fe0488399998996ca82144509988a03f3 Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Sun, 2 Aug 2020 20:06:13 +0430 Subject: [PATCH 193/309] Improve How to Count the Number of Matches for a Regex? (#9788) --- .../baeldung/regex/countmatches/CountMatchesUnitTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/countmatches/CountMatchesUnitTest.java b/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/countmatches/CountMatchesUnitTest.java index 6427d11dd6..3e601a7828 100644 --- a/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/countmatches/CountMatchesUnitTest.java +++ b/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/countmatches/CountMatchesUnitTest.java @@ -1,12 +1,11 @@ package com.baeldung.regex.countmatches; -import static org.junit.Assert.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.Test; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Unit Test intended to count number of matches of a RegEx using Java 8 and 9. @@ -65,7 +64,7 @@ public class CountMatchesUnitTest { count++; } - assertNotEquals(3, count); + assertEquals(2, count); } @Test From 254319fb306b3e4595751ca67d3bec1a2658c933 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 2 Aug 2020 23:17:57 +0530 Subject: [PATCH 194/309] JAVA-2297: Update "Spring Boot custom error page" article --- .../spring-boot-basic-customization/pom.xml | 10 ++++++---- .../errorhandling/controllers/MyErrorController.java | 2 +- .../src/main/resources/application.properties | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/spring-boot-modules/spring-boot-basic-customization/pom.xml b/spring-boot-modules/spring-boot-basic-customization/pom.xml index fc34994a85..2a4b321c5f 100644 --- a/spring-boot-modules/spring-boot-basic-customization/pom.xml +++ b/spring-boot-modules/spring-boot-basic-customization/pom.xml @@ -4,11 +4,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT - ../ + org.springframework.boot + spring-boot-starter-parent + 2.3.2.RELEASE + spring-boot-basic-customization diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java index e002ac045d..8a7a3d6e45 100644 --- a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java @@ -34,7 +34,7 @@ public class MyErrorController implements ErrorController { @Override public String getErrorPath() { - return "/error"; + return null; } } diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties index 4d4a6ec7bd..53f13c4767 100644 --- a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties @@ -5,3 +5,4 @@ #spring.banner.image.height= //TODO #spring.banner.image.margin= //TODO #spring.banner.image.invert= //TODO +server.error.path=/error From 8c0fc4830c736ba3300f42d2b71d0b943fb84ff4 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Mon, 3 Aug 2020 01:00:01 +0530 Subject: [PATCH 195/309] Fixing Capitalization Issue in class names --- ...ecosmodbApplication.java => AzureCosmosDbApplication.java} | 4 ++-- ...anualTest.java => AzureCosmosDbApplicationManualTest.java} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/{AzurecosmodbApplication.java => AzureCosmosDbApplication.java} (90%) rename persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/{AzurecosmodbApplicationManualTest.java => AzureCosmosDbApplicationManualTest.java} (95%) diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplication.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java similarity index 90% rename from persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplication.java rename to persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java index 2b145d14cd..7a91cd7d33 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplication.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java @@ -13,10 +13,10 @@ import org.springframework.context.annotation.Bean; @SpringBootApplication @EnableCosmosRepositories(basePackageClasses = ProductRepository.class) -public class AzurecosmodbApplication extends AbstractCosmosConfiguration { +public class AzureCosmosDbApplication extends AbstractCosmosConfiguration { public static void main(String[] args) { - SpringApplication.run(AzurecosmodbApplication.class, args); + SpringApplication.run(AzureCosmosDbApplication.class, args); } @Value("${azure.cosmosdb.uri}") diff --git a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplicationManualTest.java similarity index 95% rename from persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java rename to persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplicationManualTest.java index 7ebdce279b..9170068173 100644 --- a/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzurecosmodbApplicationManualTest.java +++ b/persistence-modules/spring-data-cosmosdb/src/test/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplicationManualTest.java @@ -10,7 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.util.Assert; @SpringBootTest -public class AzurecosmodbApplicationManualTest { +public class AzureCosmosDbApplicationManualTest { @Autowired ProductRepository productRepository; From ebb836524dfee18e3493f360a6c3fe17c36d3c7d Mon Sep 17 00:00:00 2001 From: azhwani <> Date: Mon, 3 Aug 2020 12:46:26 +0100 Subject: [PATCH 196/309] first commit --- .../logoutredirects/LogoutApplication.java | 13 +++++++ .../controller/RestApiController.java | 20 ++++++++++ .../securityconfig/SpringSecurityConfig.java | 27 +++++++++++++ .../src/main/resources/application.properties | 4 +- .../LogoutApplicationUnitTest.java | 38 +++++++++++++++++++ 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 spring-5-security/src/main/java/com/baeldung/logoutredirects/LogoutApplication.java create mode 100644 spring-5-security/src/main/java/com/baeldung/logoutredirects/controller/RestApiController.java create mode 100644 spring-5-security/src/main/java/com/baeldung/logoutredirects/securityconfig/SpringSecurityConfig.java create mode 100644 spring-5-security/src/test/java/com/baeldung/authresolver/logoutredirects/LogoutApplicationUnitTest.java diff --git a/spring-5-security/src/main/java/com/baeldung/logoutredirects/LogoutApplication.java b/spring-5-security/src/main/java/com/baeldung/logoutredirects/LogoutApplication.java new file mode 100644 index 0000000000..ef8175ffb2 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/logoutredirects/LogoutApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.logoutredirects; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class LogoutApplication { + + public static void main(String[] args) { + SpringApplication.run(LogoutApplication.class, args); + } + +} diff --git a/spring-5-security/src/main/java/com/baeldung/logoutredirects/controller/RestApiController.java b/spring-5-security/src/main/java/com/baeldung/logoutredirects/controller/RestApiController.java new file mode 100644 index 0000000000..7d5b3ebbaa --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/logoutredirects/controller/RestApiController.java @@ -0,0 +1,20 @@ +package com.baeldung.logoutredirects.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class RestApiController { + + @GetMapping("/login") + public String login() { + return "login"; + } + + @PostMapping("/logout") + public String logout() { + return "redirect:/login"; + } + +} diff --git a/spring-5-security/src/main/java/com/baeldung/logoutredirects/securityconfig/SpringSecurityConfig.java b/spring-5-security/src/main/java/com/baeldung/logoutredirects/securityconfig/SpringSecurityConfig.java new file mode 100644 index 0000000000..64141f63d8 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/logoutredirects/securityconfig/SpringSecurityConfig.java @@ -0,0 +1,27 @@ +package com.baeldung.logoutredirects.securityconfig; + +import javax.servlet.http.HttpServletResponse; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Configuration +@EnableWebSecurity +public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests(authz -> authz.mvcMatchers("/login") + .permitAll() + .anyRequest() + .authenticated()) + .logout(logout -> logout.permitAll() + .logoutSuccessHandler((request, response, authentication) -> { + response.setStatus(HttpServletResponse.SC_OK); + })); + + } + +} diff --git a/spring-5-security/src/main/resources/application.properties b/spring-5-security/src/main/resources/application.properties index 5912b0f755..8159ace060 100644 --- a/spring-5-security/src/main/resources/application.properties +++ b/spring-5-security/src/main/resources/application.properties @@ -2,4 +2,6 @@ server.port=8081 logging.level.root=INFO -logging.level.com.baeldung.dsl.ClientErrorLoggingFilter=DEBUG \ No newline at end of file +logging.level.com.baeldung.dsl.ClientErrorLoggingFilter=DEBUG + +logging.level.org.springframework.security=DEBUG \ No newline at end of file diff --git a/spring-5-security/src/test/java/com/baeldung/authresolver/logoutredirects/LogoutApplicationUnitTest.java b/spring-5-security/src/test/java/com/baeldung/authresolver/logoutredirects/LogoutApplicationUnitTest.java new file mode 100644 index 0000000000..22ec67dea1 --- /dev/null +++ b/spring-5-security/src/test/java/com/baeldung/authresolver/logoutredirects/LogoutApplicationUnitTest.java @@ -0,0 +1,38 @@ +package com.baeldung.authresolver.logoutredirects; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.logoutredirects.securityconfig.SpringSecurityConfig; + +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; +import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.unauthenticated; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@RunWith(SpringRunner.class) +@WebMvcTest() +@ContextConfiguration(classes = { SpringSecurityConfig.class }) +public class LogoutApplicationUnitTest { + + @Autowired + private MockMvc mockMvc; + + @WithMockUser(value = "spring") + @Test + public void whenLogout_thenDisableRedirect() throws Exception { + + this.mockMvc.perform(post("/logout").with(csrf())) + .andExpect(status().isOk()) + .andExpect(jsonPath("$").doesNotExist()) + .andExpect(unauthenticated()) + .andReturn(); + } + +} \ No newline at end of file From 1cd7cca2cabd30d36c9dbef35fc8fbfd319cd8c0 Mon Sep 17 00:00:00 2001 From: azhwani <> Date: Mon, 3 Aug 2020 12:57:37 +0100 Subject: [PATCH 197/309] quick fix --- .../logoutredirects/LogoutApplicationUnitTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) rename spring-5-security/src/test/java/com/baeldung/{authresolver => }/logoutredirects/LogoutApplicationUnitTest.java (83%) diff --git a/spring-5-security/src/test/java/com/baeldung/authresolver/logoutredirects/LogoutApplicationUnitTest.java b/spring-5-security/src/test/java/com/baeldung/logoutredirects/LogoutApplicationUnitTest.java similarity index 83% rename from spring-5-security/src/test/java/com/baeldung/authresolver/logoutredirects/LogoutApplicationUnitTest.java rename to spring-5-security/src/test/java/com/baeldung/logoutredirects/LogoutApplicationUnitTest.java index 22ec67dea1..519a6bdc99 100644 --- a/spring-5-security/src/test/java/com/baeldung/authresolver/logoutredirects/LogoutApplicationUnitTest.java +++ b/spring-5-security/src/test/java/com/baeldung/logoutredirects/LogoutApplicationUnitTest.java @@ -1,16 +1,13 @@ -package com.baeldung.authresolver.logoutredirects; +package com.baeldung.logoutredirects; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; -import com.baeldung.logoutredirects.securityconfig.SpringSecurityConfig; - import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers.unauthenticated; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -18,7 +15,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @WebMvcTest() -@ContextConfiguration(classes = { SpringSecurityConfig.class }) public class LogoutApplicationUnitTest { @Autowired From 33841c2034a82feb31714f986d4cb3441f56ceda Mon Sep 17 00:00:00 2001 From: joe zhang Date: Mon, 3 Aug 2020 22:52:22 +0800 Subject: [PATCH 198/309] use utility class directly --- .../primitivetype/PrimitiveTypeUtil.java | 16 +------- .../primitivetype/PrimitiveTypeUnitTest.java | 40 ++++++++++++++++++ .../PrimitiveTypeUtilUnitTest.java | 41 ------------------- 3 files changed, 42 insertions(+), 55 deletions(-) create mode 100644 core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUnitTest.java delete mode 100644 core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilUnitTest.java diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java index 1b2083b548..9607a0008f 100644 --- a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java @@ -3,10 +3,6 @@ package com.baeldung.primitivetype; import java.util.HashMap; import java.util.Map; -import org.apache.commons.lang3.ClassUtils; - -import com.google.common.primitives.Primitives; - public class PrimitiveTypeUtil { private static final Map, Class> WRAPPER_TYPE_MAP; @@ -23,16 +19,8 @@ public class PrimitiveTypeUtil { WRAPPER_TYPE_MAP.put(Void.class, void.class); } - public boolean isPrimitiveTypeByCommonsLang(Object source) { - return ClassUtils.isPrimitiveOrWrapper(source.getClass()); - } - - public boolean isPrimitiveTypeByGuava(Object source) { - return Primitives.isWrapperType(source.getClass()); - } - - public boolean isPrimitiveType(Object source) { - return WRAPPER_TYPE_MAP.containsKey(source.getClass()); + public boolean isPrimitiveType(Class sourceClass) { + return WRAPPER_TYPE_MAP.containsKey(sourceClass); } } diff --git a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUnitTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUnitTest.java new file mode 100644 index 0000000000..5bbededbb3 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUnitTest.java @@ -0,0 +1,40 @@ +package com.baeldung.primitivetype; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.apache.commons.lang3.ClassUtils; +import org.junit.Before; +import org.junit.Test; + +import com.google.common.primitives.Primitives; + +public class PrimitiveTypeUnitTest { + + private PrimitiveTypeUtil primitiveTypeUtil; + + @Before + public void setup() { + primitiveTypeUtil = new PrimitiveTypeUtil(); + } + + @Test + public void givenAClass_whenCheckWithPrimitiveTypeUtil_thenShouldValidate() { + assertTrue(primitiveTypeUtil.isPrimitiveType(Boolean.class)); + assertFalse(primitiveTypeUtil.isPrimitiveType(String.class)); + } + + @Test + public void givenAClass_whenCheckWithCommonsLang_thenShouldValidate() { + assertTrue(ClassUtils.isPrimitiveOrWrapper(Boolean.class)); + assertTrue(ClassUtils.isPrimitiveOrWrapper(boolean.class)); + assertFalse(ClassUtils.isPrimitiveOrWrapper(String.class)); + } + + @Test + public void givenAClass_whenCheckWithGuava_thenShouldValidate() { + assertTrue(Primitives.isWrapperType(Boolean.class)); + assertFalse(Primitives.isWrapperType(String.class)); + assertFalse(Primitives.isWrapperType(boolean.class)); + } +} diff --git a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilUnitTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilUnitTest.java deleted file mode 100644 index 5cd1b9f9d7..0000000000 --- a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUtilUnitTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.primitivetype; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; - -public class PrimitiveTypeUtilUnitTest { - - private PrimitiveTypeUtil primitiveTypeUtil; - private boolean booleanVal = false; - private Long longWrapper = 1L; - private String nonPrimitiveVal = "non primitive string"; - - @Before - public void setup() { - primitiveTypeUtil = new PrimitiveTypeUtil(); - } - - @Test - public void givenObjectWhenCheckWithGuavaShouldValidate() { - assertTrue(primitiveTypeUtil.isPrimitiveTypeByGuava(booleanVal)); - assertTrue(primitiveTypeUtil.isPrimitiveTypeByGuava(longWrapper)); - assertFalse(primitiveTypeUtil.isPrimitiveTypeByGuava(nonPrimitiveVal)); - } - - @Test - public void givenObjectWhenCheckWithCommonsLangShouldValidate() { - assertTrue(primitiveTypeUtil.isPrimitiveTypeByCommonsLang(booleanVal)); - assertTrue(primitiveTypeUtil.isPrimitiveTypeByCommonsLang(longWrapper)); - assertFalse(primitiveTypeUtil.isPrimitiveTypeByCommonsLang(nonPrimitiveVal)); - } - - @Test - public void givenPrimitiveOrWrapperWhenCheckWithCustomMethodShouldReturnTrue() { - assertTrue(primitiveTypeUtil.isPrimitiveType(booleanVal)); - assertTrue(primitiveTypeUtil.isPrimitiveType(longWrapper)); - assertFalse(primitiveTypeUtil.isPrimitiveType(nonPrimitiveVal)); - } -} From 021c119be4ffcc8a028eab5bdc93f60491d71fbf Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Mon, 3 Aug 2020 21:22:23 +0200 Subject: [PATCH 199/309] JAVA-2300: Upgrade Spring Core to 5.2.8 in parent-spring-5 --- parent-spring-5/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent-spring-5/pom.xml b/parent-spring-5/pom.xml index 949e40b021..5893701c68 100644 --- a/parent-spring-5/pom.xml +++ b/parent-spring-5/pom.xml @@ -31,7 +31,7 @@ - 5.2.5.RELEASE + 5.2.8.RELEASE 5.2.3.RELEASE 1.5.10.RELEASE From 3ac4049caee949f692185dd9b33245a4b8938e9a Mon Sep 17 00:00:00 2001 From: mikr Date: Tue, 4 Aug 2020 22:39:30 +0200 Subject: [PATCH 200/309] Java-65 split persistence-modules/spring-jpa --- persistence-modules/spring-jpa-2/.gitignore | 13 ++ persistence-modules/spring-jpa-2/README.md | 19 +++ persistence-modules/spring-jpa-2/pom.xml | 152 ++++++++++++++++++ .../baeldung/config/PersistenceJPAConfig.java | 85 ++++++++++ .../config/PersistenceJPAConfigXml.java | 17 ++ .../com/baeldung/config/SpringWebConfig.java | 24 +++ .../com/baeldung/config/StudentJpaConfig.java | 67 ++++++++ .../com/baeldung/config/WebInitializer.java | 20 +++ .../com/baeldung/manytomany/model/Course.java | 0 .../manytomany/model/CourseRating.java | 0 .../manytomany/model/CourseRatingKey.java | 0 .../manytomany/model/CourseRegistration.java | 0 .../baeldung/manytomany/model/Student.java | 0 .../src/main/resources/context.xml | 1 + .../src/main/resources/logback.xml | 19 +++ .../main/resources/persistence-h2.properties | 10 ++ .../resources/persistence-student.properties | 11 ++ .../src/main/resources/persistence.xml | 42 +++++ .../src/main/resources/server.xml | 6 + .../src/main/resources/sqlfiles.properties | 1 + .../src/test/java/META-INF/persistence.xml | 20 +++ .../java/com/baeldung/SpringContextTest.java | 21 +++ .../manytomany/ManyToManyIntegrationTest.java | 0 .../ManyToManyTestConfiguration.java | 2 +- .../src/test/resources/.gitignore | 13 ++ .../src/test/resources/manytomany/db.sql | 0 .../test/resources/manytomany/test.properties | 0 .../resources/persistence-student.properties | 9 ++ persistence-modules/spring-jpa/README.md | 4 +- 29 files changed, 552 insertions(+), 4 deletions(-) create mode 100644 persistence-modules/spring-jpa-2/.gitignore create mode 100644 persistence-modules/spring-jpa-2/README.md create mode 100644 persistence-modules/spring-jpa-2/pom.xml create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfig.java create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfigXml.java create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/SpringWebConfig.java create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/StudentJpaConfig.java create mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/WebInitializer.java rename persistence-modules/{spring-jpa => spring-jpa-2}/src/main/java/com/baeldung/manytomany/model/Course.java (100%) rename persistence-modules/{spring-jpa => spring-jpa-2}/src/main/java/com/baeldung/manytomany/model/CourseRating.java (100%) rename persistence-modules/{spring-jpa => spring-jpa-2}/src/main/java/com/baeldung/manytomany/model/CourseRatingKey.java (100%) rename persistence-modules/{spring-jpa => spring-jpa-2}/src/main/java/com/baeldung/manytomany/model/CourseRegistration.java (100%) rename persistence-modules/{spring-jpa => spring-jpa-2}/src/main/java/com/baeldung/manytomany/model/Student.java (100%) create mode 100644 persistence-modules/spring-jpa-2/src/main/resources/context.xml create mode 100644 persistence-modules/spring-jpa-2/src/main/resources/logback.xml create mode 100644 persistence-modules/spring-jpa-2/src/main/resources/persistence-h2.properties create mode 100644 persistence-modules/spring-jpa-2/src/main/resources/persistence-student.properties create mode 100644 persistence-modules/spring-jpa-2/src/main/resources/persistence.xml create mode 100644 persistence-modules/spring-jpa-2/src/main/resources/server.xml create mode 100644 persistence-modules/spring-jpa-2/src/main/resources/sqlfiles.properties create mode 100644 persistence-modules/spring-jpa-2/src/test/java/META-INF/persistence.xml create mode 100644 persistence-modules/spring-jpa-2/src/test/java/com/baeldung/SpringContextTest.java rename persistence-modules/{spring-jpa => spring-jpa-2}/src/test/java/com/baeldung/manytomany/ManyToManyIntegrationTest.java (100%) rename persistence-modules/{spring-jpa => spring-jpa-2}/src/test/java/com/baeldung/manytomany/ManyToManyTestConfiguration.java (97%) create mode 100644 persistence-modules/spring-jpa-2/src/test/resources/.gitignore rename persistence-modules/{spring-jpa => spring-jpa-2}/src/test/resources/manytomany/db.sql (100%) rename persistence-modules/{spring-jpa => spring-jpa-2}/src/test/resources/manytomany/test.properties (100%) create mode 100644 persistence-modules/spring-jpa-2/src/test/resources/persistence-student.properties diff --git a/persistence-modules/spring-jpa-2/.gitignore b/persistence-modules/spring-jpa-2/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/persistence-modules/spring-jpa-2/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/README.md b/persistence-modules/spring-jpa-2/README.md new file mode 100644 index 0000000000..71b368b44a --- /dev/null +++ b/persistence-modules/spring-jpa-2/README.md @@ -0,0 +1,19 @@ +========= + +## Spring JPA Example Project + + +### Relevant Articles: +- [Many-To-Many Relationship in JPA](https://www.baeldung.com/jpa-many-to-many) +- More articles: [[<-- prev]](/spring-jpa) + + +### Eclipse Config +After importing the project into Eclipse, you may see the following error: +"No persistence xml file found in project" + +This can be ignored: +- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" +Or: +- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator + diff --git a/persistence-modules/spring-jpa-2/pom.xml b/persistence-modules/spring-jpa-2/pom.xml new file mode 100644 index 0000000000..410ed592b0 --- /dev/null +++ b/persistence-modules/spring-jpa-2/pom.xml @@ -0,0 +1,152 @@ + + + 4.0.0 + spring-jpa + 0.1-SNAPSHOT + spring-jpa + war + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + + org.springframework + spring-orm + ${org.springframework.version} + + + commons-logging + commons-logging + + + + + org.springframework + spring-context + ${org.springframework.version} + + + org.springframework + spring-webmvc + ${org.springframework.version} + + + + + + org.hibernate + hibernate-entitymanager + ${hibernate.version} + + + xml-apis + xml-apis + ${xml-apis.version} + + + org.javassist + javassist + ${javassist.version} + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + runtime + + + org.springframework.data + spring-data-jpa + ${spring-data-jpa.version} + + + com.h2database + h2 + ${h2.version} + + + + + + org.hibernate + hibernate-validator + ${hibernate-validator.version} + + + javax.el + javax.el-api + ${javax.el-api.version} + + + + + javax.servlet + jstl + ${jstl.version} + + + javax.servlet + servlet-api + provided + ${javax.servlet.servlet-api.version} + + + + + + com.google.guava + guava + ${guava.version} + + + org.assertj + assertj-core + ${assertj.version} + + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + test + + + + org.springframework + spring-test + ${org.springframework.version} + test + + + + + + + 5.1.5.RELEASE + 3.21.0-GA + + 6.0.6 + 2.1.5.RELEASE + + + 2.5 + + + 6.0.15.Final + 1.4.01 + 2.2.5 + + + 21.0 + 3.8.0 + + + \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfig.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfig.java new file mode 100644 index 0000000000..c489321122 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfig.java @@ -0,0 +1,85 @@ +package com.baeldung.config; + +import com.google.common.base.Preconditions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import java.util.Properties; + +@Configuration +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-h2.properties" }) +@ComponentScan({ "com.baeldung.persistence" }) +@EnableJpaRepositories(basePackages = "com.baeldung.persistence.dao") +public class PersistenceJPAConfig { + + @Autowired + private Environment env; + + public PersistenceJPAConfig() { + super(); + } + + // beans + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(dataSource()); + em.setPackagesToScan(new String[] { "com.baeldung.persistence.model" }); + + final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + em.setJpaVendorAdapter(vendorAdapter); + em.setJpaProperties(additionalProperties()); + + return em; + } + + @Bean + public DataSource dataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) { + final JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(emf); + return transactionManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + final Properties additionalProperties() { + final Properties hibernateProperties = new Properties(); + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + hibernateProperties.setProperty("hibernate.cache.use_second_level_cache", "false"); + + + return hibernateProperties; + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfigXml.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfigXml.java new file mode 100644 index 0000000000..95224a4662 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfigXml.java @@ -0,0 +1,17 @@ +package com.baeldung.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.ImportResource; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +// @Configuration +@EnableTransactionManagement +@ComponentScan({ "com.baeldung.persistence" }) +@ImportResource({ "classpath:jpaConfig.xml" }) +public class PersistenceJPAConfigXml { + + public PersistenceJPAConfigXml() { + super(); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/SpringWebConfig.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/SpringWebConfig.java new file mode 100644 index 0000000000..475970d1f0 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/SpringWebConfig.java @@ -0,0 +1,24 @@ +package com.baeldung.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.view.InternalResourceViewResolver; +import org.springframework.web.servlet.view.JstlView; + +@EnableWebMvc +@Configuration +@ComponentScan({ "com.baeldung.web" }) +public class SpringWebConfig extends WebMvcConfigurerAdapter { + + @Bean + public InternalResourceViewResolver viewResolver() { + InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setViewClass(JstlView.class); + viewResolver.setPrefix("/WEB-INF/views/jsp/"); + viewResolver.setSuffix(".jsp"); + return viewResolver; + } +} diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/StudentJpaConfig.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/StudentJpaConfig.java new file mode 100644 index 0000000000..54ced72dd1 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/StudentJpaConfig.java @@ -0,0 +1,67 @@ +package com.baeldung.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import java.util.Properties; + +@Configuration +@EnableJpaRepositories(basePackages = "com.baeldung.inmemory.persistence.dao") +@PropertySource("persistence-student.properties") +@EnableTransactionManagement +public class StudentJpaConfig { + + @Autowired + private Environment env; + + @Bean + public DataSource dataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName")); + dataSource.setUrl(env.getProperty("jdbc.url")); + dataSource.setUsername(env.getProperty("jdbc.user")); + dataSource.setPassword(env.getProperty("jdbc.pass")); + + return dataSource; + } + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(dataSource()); + em.setPackagesToScan(new String[] { "com.baeldung.inmemory.persistence.model" }); + em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + em.setJpaProperties(additionalProperties()); + return em; + } + + @Bean + JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { + JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(entityManagerFactory); + return transactionManager; + } + + final Properties additionalProperties() { + final Properties hibernateProperties = new Properties(); + + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + hibernateProperties.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql")); + hibernateProperties.setProperty("hibernate.cache.use_second_level_cache", env.getProperty("hibernate.cache.use_second_level_cache")); + hibernateProperties.setProperty("hibernate.cache.use_query_cache", env.getProperty("hibernate.cache.use_query_cache")); + + return hibernateProperties; + } +} diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/WebInitializer.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/WebInitializer.java new file mode 100644 index 0000000000..be81cca76b --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/WebInitializer.java @@ -0,0 +1,20 @@ +package com.baeldung.config; + +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; + +public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { + @Override + protected Class[] getRootConfigClasses() { + return new Class[] { PersistenceJPAConfig.class }; + } + + @Override + protected Class[] getServletConfigClasses() { + return new Class[] { SpringWebConfig.class }; + } + + @Override + protected String[] getServletMappings() { + return new String[] { "/" }; + } +} diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/manytomany/model/Course.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/manytomany/model/Course.java similarity index 100% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/manytomany/model/Course.java rename to persistence-modules/spring-jpa-2/src/main/java/com/baeldung/manytomany/model/Course.java diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/manytomany/model/CourseRating.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/manytomany/model/CourseRating.java similarity index 100% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/manytomany/model/CourseRating.java rename to persistence-modules/spring-jpa-2/src/main/java/com/baeldung/manytomany/model/CourseRating.java diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/manytomany/model/CourseRatingKey.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/manytomany/model/CourseRatingKey.java similarity index 100% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/manytomany/model/CourseRatingKey.java rename to persistence-modules/spring-jpa-2/src/main/java/com/baeldung/manytomany/model/CourseRatingKey.java diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/manytomany/model/CourseRegistration.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/manytomany/model/CourseRegistration.java similarity index 100% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/manytomany/model/CourseRegistration.java rename to persistence-modules/spring-jpa-2/src/main/java/com/baeldung/manytomany/model/CourseRegistration.java diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/manytomany/model/Student.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/manytomany/model/Student.java similarity index 100% rename from persistence-modules/spring-jpa/src/main/java/com/baeldung/manytomany/model/Student.java rename to persistence-modules/spring-jpa-2/src/main/java/com/baeldung/manytomany/model/Student.java diff --git a/persistence-modules/spring-jpa-2/src/main/resources/context.xml b/persistence-modules/spring-jpa-2/src/main/resources/context.xml new file mode 100644 index 0000000000..a64dfe9a61 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/resources/context.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/logback.xml b/persistence-modules/spring-jpa-2/src/main/resources/logback.xml new file mode 100644 index 0000000000..ec0dc2469a --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/persistence-h2.properties b/persistence-modules/spring-jpa-2/src/main/resources/persistence-h2.properties new file mode 100644 index 0000000000..a3060cc796 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/resources/persistence-h2.properties @@ -0,0 +1,10 @@ +# jdbc.X +jdbc.driverClassName=org.h2.Driver +jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 +jdbc.user=sa +jdbc.pass= + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/persistence-student.properties b/persistence-modules/spring-jpa-2/src/main/resources/persistence-student.properties new file mode 100644 index 0000000000..d4c82420de --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/resources/persistence-student.properties @@ -0,0 +1,11 @@ +jdbc.driverClassName=com.mysql.cj.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/myDb +jdbc.user=tutorialuser +jdbc.pass=tutorialpass + +hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + +hibernate.cache.use_second_level_cache=false +hibernate.cache.use_query_cache=false \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/persistence.xml b/persistence-modules/spring-jpa-2/src/main/resources/persistence.xml new file mode 100644 index 0000000000..57687c306d --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/resources/persistence.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + ${hibernate.hbm2ddl.auto} + ${hibernate.dialect} + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/server.xml b/persistence-modules/spring-jpa-2/src/main/resources/server.xml new file mode 100644 index 0000000000..5c61659018 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/resources/server.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/sqlfiles.properties b/persistence-modules/spring-jpa-2/src/main/resources/sqlfiles.properties new file mode 100644 index 0000000000..0bea6adad1 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/main/resources/sqlfiles.properties @@ -0,0 +1 @@ +spring.jpa.hibernate.ddl-auto=none \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/test/java/META-INF/persistence.xml b/persistence-modules/spring-jpa-2/src/test/java/META-INF/persistence.xml new file mode 100644 index 0000000000..495f076fef --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/test/java/META-INF/persistence.xml @@ -0,0 +1,20 @@ + + + + com.baeldung.persistence.model.Foo + com.baeldung.persistence.model.Bar + + + + + + + + + + + + + diff --git a/persistence-modules/spring-jpa-2/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/spring-jpa-2/src/test/java/com/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..abc73e250d --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/test/java/com/baeldung/SpringContextTest.java @@ -0,0 +1,21 @@ +package com.baeldung; + +import com.baeldung.config.PersistenceJPAConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; +import org.springframework.test.context.web.WebAppConfiguration; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PersistenceJPAConfig.class }, loader = AnnotationConfigContextLoader.class) +@WebAppConfiguration +@DirtiesContext +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/persistence-modules/spring-jpa/src/test/java/com/baeldung/manytomany/ManyToManyIntegrationTest.java b/persistence-modules/spring-jpa-2/src/test/java/com/baeldung/manytomany/ManyToManyIntegrationTest.java similarity index 100% rename from persistence-modules/spring-jpa/src/test/java/com/baeldung/manytomany/ManyToManyIntegrationTest.java rename to persistence-modules/spring-jpa-2/src/test/java/com/baeldung/manytomany/ManyToManyIntegrationTest.java diff --git a/persistence-modules/spring-jpa/src/test/java/com/baeldung/manytomany/ManyToManyTestConfiguration.java b/persistence-modules/spring-jpa-2/src/test/java/com/baeldung/manytomany/ManyToManyTestConfiguration.java similarity index 97% rename from persistence-modules/spring-jpa/src/test/java/com/baeldung/manytomany/ManyToManyTestConfiguration.java rename to persistence-modules/spring-jpa-2/src/test/java/com/baeldung/manytomany/ManyToManyTestConfiguration.java index f4635b563a..1cc3621f0d 100644 --- a/persistence-modules/spring-jpa/src/test/java/com/baeldung/manytomany/ManyToManyTestConfiguration.java +++ b/persistence-modules/spring-jpa-2/src/test/java/com/baeldung/manytomany/ManyToManyTestConfiguration.java @@ -16,7 +16,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; @Configuration -@PropertySource("classpath:/manytomany/test.properties") +@PropertySource("manytomany/test.properties") public class ManyToManyTestConfiguration { @Bean diff --git a/persistence-modules/spring-jpa-2/src/test/resources/.gitignore b/persistence-modules/spring-jpa-2/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/persistence-modules/spring-jpa/src/test/resources/manytomany/db.sql b/persistence-modules/spring-jpa-2/src/test/resources/manytomany/db.sql similarity index 100% rename from persistence-modules/spring-jpa/src/test/resources/manytomany/db.sql rename to persistence-modules/spring-jpa-2/src/test/resources/manytomany/db.sql diff --git a/persistence-modules/spring-jpa/src/test/resources/manytomany/test.properties b/persistence-modules/spring-jpa-2/src/test/resources/manytomany/test.properties similarity index 100% rename from persistence-modules/spring-jpa/src/test/resources/manytomany/test.properties rename to persistence-modules/spring-jpa-2/src/test/resources/manytomany/test.properties diff --git a/persistence-modules/spring-jpa-2/src/test/resources/persistence-student.properties b/persistence-modules/spring-jpa-2/src/test/resources/persistence-student.properties new file mode 100644 index 0000000000..3b6b580630 --- /dev/null +++ b/persistence-modules/spring-jpa-2/src/test/resources/persistence-student.properties @@ -0,0 +1,9 @@ +jdbc.driverClassName=org.h2.Driver +jdbc.url=jdbc:h2:mem:myDb;DB_CLOSE_DELAY=-1 + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create + +hibernate.cache.use_second_level_cache=false +hibernate.cache.use_query_cache=false \ No newline at end of file diff --git a/persistence-modules/spring-jpa/README.md b/persistence-modules/spring-jpa/README.md index 94a1e1f575..3eb8ae8d55 100644 --- a/persistence-modules/spring-jpa/README.md +++ b/persistence-modules/spring-jpa/README.md @@ -11,9 +11,7 @@ - [A Guide to Spring AbstractRoutingDatasource](https://www.baeldung.com/spring-abstract-routing-data-source) - [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys) - [Use Criteria Queries in a Spring Data Application](https://www.baeldung.com/spring-data-criteria-queries) -- [Many-To-Many Relationship in JPA](https://www.baeldung.com/jpa-many-to-many) -- [Spring Persistence (Hibernate and JPA) with a JNDI datasource](https://www.baeldung.com/spring-persistence-hibernate-and-jpa-with-a-jndi-datasource-2) - +- More articles: [[next -->]](/spring-jpa-2) ### Eclipse Config After importing the project into Eclipse, you may see the following error: From e176cc2d4226943d8c132fe3ca4f462bd5283747 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Tue, 4 Aug 2020 23:06:05 +0200 Subject: [PATCH 201/309] JAVA-1652: Get rid of the overriden spring-boot.version property --- spring-cloud/spring-cloud-zuul/pom.xml | 3 +-- .../spring-cloud-zuul/spring-zuul-post-filter/pom.xml | 4 ---- .../spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml | 2 -- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/spring-cloud/spring-cloud-zuul/pom.xml b/spring-cloud/spring-cloud-zuul/pom.xml index 140a1337b3..b3c66dd1c6 100644 --- a/spring-cloud/spring-cloud-zuul/pom.xml +++ b/spring-cloud/spring-cloud-zuul/pom.xml @@ -72,8 +72,7 @@ - Hoxton.RELEASE - 2.2.2.RELEASE + Hoxton.SR4 diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-post-filter/pom.xml b/spring-cloud/spring-cloud-zuul/spring-zuul-post-filter/pom.xml index 8643309645..0ca9f0d050 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-post-filter/pom.xml +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-post-filter/pom.xml @@ -18,8 +18,4 @@ - - Hoxton.SR1 - - \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml index fd6d18fc09..8873282d1e 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml @@ -48,8 +48,6 @@ - Finchley.SR1 - 2.0.6.RELEASE 2.2.0.RELEASE From e7ec3ff7bcfd8114b83aae8bb40735bd9bb90f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dupire?= Date: Wed, 5 Aug 2020 03:45:26 +0200 Subject: [PATCH 202/309] [JAVA-2276] Disabled frontend-maven-plugin for default-first and default-second profiles (#9820) * [JAVA-2276] Upgraded maven-assembly-plugin version to 3.3.0 * [JAVA-2276] Disabling frontend-maven-plugin for default-first and default-second profiles --- jhipster-5/bookstore-monolith/pom.xml | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/jhipster-5/bookstore-monolith/pom.xml b/jhipster-5/bookstore-monolith/pom.xml index 4e4c82f327..03395e47ed 100644 --- a/jhipster-5/bookstore-monolith/pom.xml +++ b/jhipster-5/bookstore-monolith/pom.xml @@ -1008,6 +1008,68 @@ + + default-first + + + + + com.github.eirslett + frontend-maven-plugin + + + + install node and npm + none + + + npm install + none + + + webpack build dev + none + + + webpack build test + none + + + + + + + + default-second + + + + + com.github.eirslett + frontend-maven-plugin + + + + install node and npm + none + + + npm install + none + + + webpack build dev + none + + + webpack build test + none + + + + + + From 4367410910e05cf1ad513bff1f720b6d55069eb3 Mon Sep 17 00:00:00 2001 From: Jordan Simpson Date: Wed, 5 Aug 2020 10:47:13 -0500 Subject: [PATCH 203/309] Added pom packaging to module's pom --- maven-modules/optional-dependencies/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/maven-modules/optional-dependencies/pom.xml b/maven-modules/optional-dependencies/pom.xml index c1bfc6fb59..12d028b2d7 100644 --- a/maven-modules/optional-dependencies/pom.xml +++ b/maven-modules/optional-dependencies/pom.xml @@ -10,6 +10,7 @@ 4.0.0 optional-dependencies + pom optional-project project-with-optionals From f3740c95c333c5b01c1f8c59f494a1cd43c67eae Mon Sep 17 00:00:00 2001 From: mdhtr Date: Wed, 5 Aug 2020 18:53:22 +0200 Subject: [PATCH 204/309] Make fields private and use getters/setters/constructors instead --- .../JacksonDeserializationUnitTest.java | 12 ++-- .../jsonldjava/jackson/Person.java | 56 +++++++++++++++++-- .../HydraJsonldSerializationUnitTest.java | 4 +- .../serialization/hydrajsonld/Person.java | 17 +++++- .../JacksonJsonLdSerializationUnitTest.java | 2 +- .../serialization/jacksonjsonld/Person.java | 17 +++++- 6 files changed, 88 insertions(+), 20 deletions(-) diff --git a/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java index 9c6b6f976a..24968f3847 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java +++ b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/JacksonDeserializationUnitTest.java @@ -42,14 +42,10 @@ public class JacksonDeserializationUnitTest { ObjectMapper objectMapper = new ObjectMapper(); Person person = objectMapper.readValue(compactContent, Person.class); - Person expectedPerson = new Person(); - expectedPerson.id = "http://example.com/person/1234"; - expectedPerson.name = "Example Name"; - expectedPerson.knows = new Link(); - expectedPerson.knows.id = "http://example.com/person/2345"; + Person expectedPerson = new Person("http://example.com/person/1234", "Example Name", new Link("http://example.com/person/2345")); - assertEquals(expectedPerson.id, person.id); - assertEquals(expectedPerson.name, person.name); - assertEquals(expectedPerson.knows.id, person.knows.id); + assertEquals(expectedPerson.getId(), person.getId()); + assertEquals(expectedPerson.getName(), person.getName()); + assertEquals(expectedPerson.getKnows().getId(), person.getKnows().getId()); } } diff --git a/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/Person.java b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/Person.java index 0cb6d43336..fefa676817 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/Person.java +++ b/json-2/src/test/java/com/baeldung/jsonld/deserialization/jsonldjava/jackson/Person.java @@ -6,14 +6,62 @@ import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Person { @JsonProperty("@id") - public String id; + private String id; @JsonProperty("http://schema.org/name") - public String name; + private String name; @JsonProperty("http://schema.org/knows") - public Link knows; + private Link knows; + + public Person() { + } + + public Person(String id, String name, Link knows) { + this.id = id; + this.name = name; + this.knows = knows; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Link getKnows() { + return knows; + } + + public void setKnows(Link knows) { + this.knows = knows; + } public static class Link { @JsonProperty("@id") - public String id; + private String id; + + public Link() { + } + + public Link(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } } } diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java index 06105d579e..33395cc438 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/HydraJsonldSerializationUnitTest.java @@ -23,9 +23,7 @@ public class HydraJsonldSerializationUnitTest { objectMapper.registerModule(getJacksonHydraSerializerModule()); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - Person person = new Person(); - person.id = "http://example.com/person/1234"; - person.name = "Example Name"; + Person person = new Person("http://example.com/person/1234", "Example Name"); String personJsonLd = objectMapper.writeValueAsString(person); diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/Person.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/Person.java index 87587d02ac..3d8573c965 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/Person.java +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/hydrajsonld/Person.java @@ -8,8 +8,21 @@ import de.escalon.hypermedia.hydra.mapping.Vocab; @Vocab("http://example.com/vocab/") @Expose("person") public class Person { + private String id; + private String name; + + public Person(String id, String name) { + this.id = id; + this.name = name; + } + @JsonProperty("@id") - public String id; + public String getId() { + return id; + } + @Expose("fullName") - public String name; + public String getName() { + return name; + } } diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java index cd41989a53..9679426acb 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/JacksonJsonLdSerializationUnitTest.java @@ -15,7 +15,7 @@ public class JacksonJsonLdSerializationUnitTest { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JsonldModule()); - Person person = new Person(); + Person person = new Person("http://example.com/person/1234", "Example Name"); String personJsonLd = objectMapper.writeValueAsString(person); assertEquals("{" diff --git a/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/Person.java b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/Person.java index d0c9e4f111..b63f49840c 100644 --- a/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/Person.java +++ b/json-2/src/test/java/com/baeldung/jsonld/serialization/jacksonjsonld/Person.java @@ -13,7 +13,20 @@ import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldType; @JsonldLink(rel = "s:knows", name = "knows", href = "http://example.com/person/2345") public class Person { @JsonldId - public String id = "http://example.com/person/1234"; + private String id; @JsonldProperty("s:name") - public String name = "Example Name"; + private String name; + + public Person(String id, String name) { + this.id = id; + this.name = name; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } } From 18c7b3000e34bdd847cb1ef3eb8ece9f3d1eca08 Mon Sep 17 00:00:00 2001 From: mdabrowski-eu Date: Thu, 6 Aug 2020 00:08:27 +0200 Subject: [PATCH 205/309] BAEL-4405 move probability examples to java-numbers-4 --- java-numbers-4/pom.xml | 52 +++++++++++++++++++ .../probability/MaleHeightGenerator.java | 0 .../baeldung/probability/RandomInvoker.java | 0 .../probability/RandomInvokerUnitTest.java | 0 4 files changed, 52 insertions(+) create mode 100644 java-numbers-4/pom.xml rename {java-numbers-3 => java-numbers-4}/src/main/java/com/baeldung/probability/MaleHeightGenerator.java (100%) rename {java-numbers-3 => java-numbers-4}/src/main/java/com/baeldung/probability/RandomInvoker.java (100%) rename {java-numbers-3 => java-numbers-4}/src/test/java/com/baeldung/probability/RandomInvokerUnitTest.java (100%) diff --git a/java-numbers-4/pom.xml b/java-numbers-4/pom.xml new file mode 100644 index 0000000000..e1722fb039 --- /dev/null +++ b/java-numbers-4/pom.xml @@ -0,0 +1,52 @@ + + 4.0.0 + java-numbers-4 + java-numbers-4 + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + + + io.vavr + vavr + ${vavr.version} + + + org.apache.commons + commons-lang3 + ${commons.version} + test + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + java-numbers-4 + + + src/main/resources + true + + + + + + 0.10.2 + 3.9 + 3.6.1 + + + diff --git a/java-numbers-3/src/main/java/com/baeldung/probability/MaleHeightGenerator.java b/java-numbers-4/src/main/java/com/baeldung/probability/MaleHeightGenerator.java similarity index 100% rename from java-numbers-3/src/main/java/com/baeldung/probability/MaleHeightGenerator.java rename to java-numbers-4/src/main/java/com/baeldung/probability/MaleHeightGenerator.java diff --git a/java-numbers-3/src/main/java/com/baeldung/probability/RandomInvoker.java b/java-numbers-4/src/main/java/com/baeldung/probability/RandomInvoker.java similarity index 100% rename from java-numbers-3/src/main/java/com/baeldung/probability/RandomInvoker.java rename to java-numbers-4/src/main/java/com/baeldung/probability/RandomInvoker.java diff --git a/java-numbers-3/src/test/java/com/baeldung/probability/RandomInvokerUnitTest.java b/java-numbers-4/src/test/java/com/baeldung/probability/RandomInvokerUnitTest.java similarity index 100% rename from java-numbers-3/src/test/java/com/baeldung/probability/RandomInvokerUnitTest.java rename to java-numbers-4/src/test/java/com/baeldung/probability/RandomInvokerUnitTest.java From ca8dd7dbc7e56091f554ff98657cb9d7ab67c045 Mon Sep 17 00:00:00 2001 From: mdabrowski-eu Date: Thu, 6 Aug 2020 00:11:13 +0200 Subject: [PATCH 206/309] BAEL-4405 better names for parameters --- .../main/java/com/baeldung/probability/RandomInvoker.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java-numbers-4/src/main/java/com/baeldung/probability/RandomInvoker.java b/java-numbers-4/src/main/java/com/baeldung/probability/RandomInvoker.java index 30be5725ab..66f82022ea 100644 --- a/java-numbers-4/src/main/java/com/baeldung/probability/RandomInvoker.java +++ b/java-numbers-4/src/main/java/com/baeldung/probability/RandomInvoker.java @@ -8,12 +8,12 @@ import java.util.function.Supplier; public class RandomInvoker { private final Lazy random = Lazy.of(SplittableRandom::new); - public T withProbability(Supplier supplier1, Supplier supplier2, int probability) { + public T withProbability(Supplier positiveCase, Supplier negativeCase, int probability) { SplittableRandom random = this.random.get(); if (random.nextInt(1, 101) <= probability) { - return supplier1.get(); + return positiveCase.get(); } else { - return supplier2.get(); + return negativeCase.get(); } } } From 54796738f8d478c07358a11802e94715ff729b4b Mon Sep 17 00:00:00 2001 From: joe zhang Date: Thu, 6 Aug 2020 23:14:19 +0800 Subject: [PATCH 207/309] update unit test --- .../primitivetype/PrimitiveTypeUtil.java | 4 ++-- .../primitivetype/PrimitiveTypeUnitTest.java | 24 +++++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java index 9607a0008f..ff70da1839 100644 --- a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/primitivetype/PrimitiveTypeUtil.java @@ -19,8 +19,8 @@ public class PrimitiveTypeUtil { WRAPPER_TYPE_MAP.put(Void.class, void.class); } - public boolean isPrimitiveType(Class sourceClass) { - return WRAPPER_TYPE_MAP.containsKey(sourceClass); + public static boolean isPrimitiveType(Object source) { + return WRAPPER_TYPE_MAP.containsKey(source.getClass()); } } diff --git a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUnitTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUnitTest.java index 5bbededbb3..b9152d3674 100644 --- a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUnitTest.java +++ b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/primitivetype/PrimitiveTypeUnitTest.java @@ -4,37 +4,31 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.apache.commons.lang3.ClassUtils; -import org.junit.Before; +import org.apache.commons.lang3.StringUtils; import org.junit.Test; import com.google.common.primitives.Primitives; public class PrimitiveTypeUnitTest { - private PrimitiveTypeUtil primitiveTypeUtil; - - @Before - public void setup() { - primitiveTypeUtil = new PrimitiveTypeUtil(); - } - @Test public void givenAClass_whenCheckWithPrimitiveTypeUtil_thenShouldValidate() { - assertTrue(primitiveTypeUtil.isPrimitiveType(Boolean.class)); - assertFalse(primitiveTypeUtil.isPrimitiveType(String.class)); + assertTrue(PrimitiveTypeUtil.isPrimitiveType(false)); + assertTrue(PrimitiveTypeUtil.isPrimitiveType(1L)); + assertFalse(PrimitiveTypeUtil.isPrimitiveType(StringUtils.EMPTY)); } @Test public void givenAClass_whenCheckWithCommonsLang_thenShouldValidate() { - assertTrue(ClassUtils.isPrimitiveOrWrapper(Boolean.class)); + assertTrue(ClassUtils.isPrimitiveOrWrapper(Boolean.FALSE.getClass())); assertTrue(ClassUtils.isPrimitiveOrWrapper(boolean.class)); - assertFalse(ClassUtils.isPrimitiveOrWrapper(String.class)); + assertFalse(ClassUtils.isPrimitiveOrWrapper(StringUtils.EMPTY.getClass())); } @Test public void givenAClass_whenCheckWithGuava_thenShouldValidate() { - assertTrue(Primitives.isWrapperType(Boolean.class)); - assertFalse(Primitives.isWrapperType(String.class)); - assertFalse(Primitives.isWrapperType(boolean.class)); + assertTrue(Primitives.isWrapperType(Boolean.FALSE.getClass())); + assertFalse(Primitives.isWrapperType(StringUtils.EMPTY.getClass())); + assertFalse(Primitives.isWrapperType(Boolean.TYPE.getClass())); } } From d444ab4d54a8aed35cc6be8cc5731df98d7388f7 Mon Sep 17 00:00:00 2001 From: karan Date: Thu, 6 Aug 2020 13:40:44 -0400 Subject: [PATCH 208/309] Fix formatting --- .../PathVariableAnnotationController.java | 136 +++++++++--------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java b/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java index 37e104f354..0cbd852095 100644 --- a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java +++ b/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java @@ -10,80 +10,80 @@ import java.util.Optional; @RestController public class PathVariableAnnotationController { - @GetMapping("/api/employees/{id}") - @ResponseBody - public String getEmployeesById(@PathVariable String id) { - return "ID: " + id; - } + @GetMapping("/api/employees/{id}") + @ResponseBody + public String getEmployeesById(@PathVariable String id) { + return "ID: " + id; + } - @GetMapping("/api/employeeswithvariable/{id}") - @ResponseBody - public String getEmployeesByIdWithVariableName(@PathVariable("id") String employeeId) { - return "ID: " + employeeId; - } + @GetMapping("/api/employeeswithvariable/{id}") + @ResponseBody + public String getEmployeesByIdWithVariableName(@PathVariable("id") String employeeId) { + return "ID: " + employeeId; + } - @GetMapping("/api/employees/{id}/{name}") - @ResponseBody - public String getEmployeesByIdAndName(@PathVariable String id, @PathVariable String name) { - return "ID: " + id + ", name: " + name; - } + @GetMapping("/api/employees/{id}/{name}") + @ResponseBody + public String getEmployeesByIdAndName(@PathVariable String id, @PathVariable String name) { + return "ID: " + id + ", name: " + name; + } - @GetMapping("/api/employeeswithmapvariable/{id}/{name}") - @ResponseBody - public String getEmployeesByIdAndNameWithMapVariable(@PathVariable Map pathVarsMap) { - String id = pathVarsMap.get("id"); - String name = pathVarsMap.get("name"); - if (id != null && name != null) { - return "ID: " + id + ", name: " + name; - } else { - return "Missing Parameters"; - } - } + @GetMapping("/api/employeeswithmapvariable/{id}/{name}") + @ResponseBody + public String getEmployeesByIdAndNameWithMapVariable(@PathVariable Map pathVarsMap) { + String id = pathVarsMap.get("id"); + String name = pathVarsMap.get("name"); + if (id != null && name != null) { + return "ID: " + id + ", name: " + name; + } else { + return "Missing Parameters"; + } + } - @GetMapping(value = { "/api/employeeswithrequired", "/api/employeeswithrequired/{id}" }) - @ResponseBody - public String getEmployeesByIdWithRequired(@PathVariable String id) { - return "ID: " + id; - } + @GetMapping(value = { "/api/employeeswithrequired", "/api/employeeswithrequired/{id}" }) + @ResponseBody + public String getEmployeesByIdWithRequired(@PathVariable String id) { + return "ID: " + id; + } - @GetMapping(value = { "/api/employeeswithrequiredfalse", "/api/employeeswithrequiredfalse/{id}" }) - @ResponseBody - public String getEmployeesByIdWithRequiredFalse(@PathVariable(required = false) String id) { - if (id != null) { - return "ID: " + id; - } else { - return "ID missing"; - } - } + @GetMapping(value = { "/api/employeeswithrequiredfalse", "/api/employeeswithrequiredfalse/{id}" }) + @ResponseBody + public String getEmployeesByIdWithRequiredFalse(@PathVariable(required = false) String id) { + if (id != null) { + return "ID: " + id; + } else { + return "ID missing"; + } + } - @GetMapping(value = { "/api/employeeswithoptional", "/api/employeeswithoptional/{id}" }) - @ResponseBody - public String getEmployeesByIdWithOptional(@PathVariable Optional id) { - if (id.isPresent()) { - return "ID: " + id.get(); - } else { - return "ID missing"; - } - } + @GetMapping(value = { "/api/employeeswithoptional", "/api/employeeswithoptional/{id}" }) + @ResponseBody + public String getEmployeesByIdWithOptional(@PathVariable Optional id) { + if (id.isPresent()) { + return "ID: " + id.get(); + } else { + return "ID missing"; + } + } - @GetMapping(value = { "/api/defaultemployeeswithoptional", "/api/defaultemployeeswithoptional/{id}" }) - @ResponseBody - public String getDefaultEmployeesByIdWithOptional(@PathVariable Optional id) { - if (id.isPresent()) { - return "ID: " + id.get(); - } else { - return "ID: Default Employee"; - } - } + @GetMapping(value = { "/api/defaultemployeeswithoptional", "/api/defaultemployeeswithoptional/{id}" }) + @ResponseBody + public String getDefaultEmployeesByIdWithOptional(@PathVariable Optional id) { + if (id.isPresent()) { + return "ID: " + id.get(); + } else { + return "ID: Default Employee"; + } + } - @GetMapping(value = { "/api/employeeswithmap/{id}", "/api/employeeswithmap" }) - @ResponseBody - public String getEmployeesByIdWithMap(@PathVariable Map pathVarsMap) { - String id = pathVarsMap.get("id"); - if (id != null) { - return "ID: " + id; - } else { - return "ID missing"; - } - } + @GetMapping(value = { "/api/employeeswithmap/{id}", "/api/employeeswithmap" }) + @ResponseBody + public String getEmployeesByIdWithMap(@PathVariable Map pathVarsMap) { + String id = pathVarsMap.get("id"); + if (id != null) { + return "ID: " + id; + } else { + return "ID missing"; + } + } } From d821719314e3d86cacb5bbb43eedb36fb5890e3e Mon Sep 17 00:00:00 2001 From: kwoyke Date: Thu, 6 Aug 2020 21:23:59 +0200 Subject: [PATCH 209/309] BAEL-4492: Use the prefered List.toArray() approach (#9831) --- .../java/collections/JavaCollectionConversionUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java b/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java index 4977c122e7..2fd31ab609 100644 --- a/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java +++ b/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java @@ -32,7 +32,7 @@ public class JavaCollectionConversionUnitTest { @Test public final void givenUsingCoreJava_whenListConvertedToArray_thenCorrect() { final List sourceList = Arrays.asList(0, 1, 2, 3, 4, 5); - final Integer[] targetArray = sourceList.toArray(new Integer[sourceList.size()]); + final Integer[] targetArray = sourceList.toArray(new Integer[0]); } @Test From fce53395e1ab473bbf486e68ac33bf927cc16fbf Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Fri, 7 Aug 2020 03:00:34 +0430 Subject: [PATCH 210/309] Applying TRW Blocks --- .../java/com/baeldung/jdbc/JdbcLiveTest.java | 44 ++++++++----------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/JdbcLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/JdbcLiveTest.java index da0c6bffe5..89fd3af864 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/JdbcLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/JdbcLiveTest.java @@ -1,26 +1,18 @@ package com.baeldung.jdbc; -import static org.junit.Assert.*; - -import java.sql.CallableStatement; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Types; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.IntStream; - import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; +import java.sql.*; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.IntStream; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public class JdbcLiveTest { private static final Logger LOG = Logger.getLogger(JdbcLiveTest.class); @@ -33,10 +25,11 @@ public class JdbcLiveTest { con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDb?noAccessToProcedureBodies=true", "user1", "pass"); - Statement stmt = con.createStatement(); + try (Statement stmt = con.createStatement()) { - String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; - stmt.execute(tableSql); + String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)"; + stmt.execute(tableSql); + } } @@ -101,10 +94,8 @@ public class JdbcLiveTest { @Test public void whenCallProcedure_thenCorrect() { - - try { - String preparedSql = "{call insertEmployee(?,?,?,?)}"; - CallableStatement cstmt = con.prepareCall(preparedSql); + String preparedSql = "{call insertEmployee(?,?,?,?)}"; + try(CallableStatement cstmt = con.prepareCall(preparedSql)) { cstmt.setString(2, "ana"); cstmt.setString(3, "tester"); cstmt.setDouble(4, 2000); @@ -121,9 +112,10 @@ public class JdbcLiveTest { public void whenReadMetadata_thenCorrect() throws SQLException { DatabaseMetaData dbmd = con.getMetaData(); - ResultSet tablesResultSet = dbmd.getTables(null, null, "%", null); - while (tablesResultSet.next()) { - LOG.info(tablesResultSet.getString("TABLE_NAME")); + try (ResultSet tablesResultSet = dbmd.getTables(null, null, "%", null)) { + while (tablesResultSet.next()) { + LOG.info(tablesResultSet.getString("TABLE_NAME")); + } } String selectSql = "SELECT * FROM employees"; From 2ca30645e8c95d1d0acd4db2573247adea883da3 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Fri, 7 Aug 2020 03:04:25 +0430 Subject: [PATCH 211/309] Polish --- .../test/java/com/baeldung/jdbc/JdbcLiveTest.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/JdbcLiveTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/JdbcLiveTest.java index 89fd3af864..81179aade9 100644 --- a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/JdbcLiveTest.java +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/jdbc/JdbcLiveTest.java @@ -5,7 +5,16 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.sql.*; +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Types; import java.util.ArrayList; import java.util.List; import java.util.stream.IntStream; @@ -95,7 +104,7 @@ public class JdbcLiveTest { @Test public void whenCallProcedure_thenCorrect() { String preparedSql = "{call insertEmployee(?,?,?,?)}"; - try(CallableStatement cstmt = con.prepareCall(preparedSql)) { + try (CallableStatement cstmt = con.prepareCall(preparedSql)) { cstmt.setString(2, "ana"); cstmt.setString(3, "tester"); cstmt.setDouble(4, 2000); From 1b2f33e4d43cde6e3a411f0ada73dc398a94bffe Mon Sep 17 00:00:00 2001 From: mdabrowski-eu Date: Fri, 7 Aug 2020 20:55:22 +0200 Subject: [PATCH 212/309] BAEL-4405 add java-numbers-4 to main pom --- pom.xml | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 1db715147a..6b8e69080f 100644 --- a/pom.xml +++ b/pom.xml @@ -343,18 +343,18 @@ animal-sniffer-mvn-plugin annotations antlr - - apache-cxf - apache-libraries - apache-olingo/olingo2 - apache-poi + + apache-cxf + apache-libraries + apache-olingo/olingo2 + apache-poi apache-rocketmq - apache-shiro + apache-shiro apache-spark apache-tapestry apache-thrift apache-tika - apache-velocity + apache-velocity asciidoctor asm @@ -448,7 +448,8 @@ java-lite java-numbers java-numbers-2 - java-numbers-3 + java-numbers-3 + java-numbers-4 java-rmi java-spi java-vavr-stream @@ -858,18 +859,18 @@ animal-sniffer-mvn-plugin annotations antlr - - apache-cxf - apache-libraries - apache-olingo/olingo2 - apache-poi + + apache-cxf + apache-libraries + apache-olingo/olingo2 + apache-poi apache-rocketmq - apache-shiro + apache-shiro apache-spark apache-tapestry apache-thrift apache-tika - apache-velocity + apache-velocity asciidoctor asm @@ -962,6 +963,7 @@ java-numbers java-numbers-2 java-numbers-3 + java-numbers-4 java-rmi java-spi java-vavr-stream From c5326ca2e81eb37864b4afb802df6e6815faceef Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:02:52 +0530 Subject: [PATCH 213/309] BAEL-4408 Adding files for BAEL-4408 --- .../src/main/webapp/WEB-INF/jsp/main.jsp | 15 +++++++++++++++ .../src/main/webapp/WEB-INF/jsp/update.jsp | 17 +++++++++++++++++ .../src/main/webapp/WEB-INF/jsp/userlogin.jsp | 18 ++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 javax-servlets/src/main/webapp/WEB-INF/jsp/main.jsp create mode 100644 javax-servlets/src/main/webapp/WEB-INF/jsp/update.jsp create mode 100644 javax-servlets/src/main/webapp/WEB-INF/jsp/userlogin.jsp diff --git a/javax-servlets/src/main/webapp/WEB-INF/jsp/main.jsp b/javax-servlets/src/main/webapp/WEB-INF/jsp/main.jsp new file mode 100644 index 0000000000..cbbb578770 --- /dev/null +++ b/javax-servlets/src/main/webapp/WEB-INF/jsp/main.jsp @@ -0,0 +1,15 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + + + +
+

Enter your User Id and Password

+ User ID:
+ Password:
+
+ + \ No newline at end of file diff --git a/javax-servlets/src/main/webapp/WEB-INF/jsp/update.jsp b/javax-servlets/src/main/webapp/WEB-INF/jsp/update.jsp new file mode 100644 index 0000000000..36ac2d277b --- /dev/null +++ b/javax-servlets/src/main/webapp/WEB-INF/jsp/update.jsp @@ -0,0 +1,17 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + + + + + Hi, User : ${sessionData.getAttribute("userId")} + +
Your User Data has been updated as below : +
User Name: ${sessionData.getAttribute("userName")} +
Age : ${sessionData.getAttribute("age")} + + + \ No newline at end of file diff --git a/javax-servlets/src/main/webapp/WEB-INF/jsp/userlogin.jsp b/javax-servlets/src/main/webapp/WEB-INF/jsp/userlogin.jsp new file mode 100644 index 0000000000..f181222f39 --- /dev/null +++ b/javax-servlets/src/main/webapp/WEB-INF/jsp/userlogin.jsp @@ -0,0 +1,18 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + + + +

Update your User Details:

+ +
+ User ID:
User Name: + Age:
+
+ + \ No newline at end of file From b81350cfae15e523f9673c410182e68ce6f858aa Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:05:45 +0530 Subject: [PATCH 214/309] BAEL-4408 BAEL-4408 files added --- .../com/baeldung/servlets/MainServlet.java | 22 ++++++++++++++ .../com/baeldung/servlets/UpdateServlet.java | 30 +++++++++++++++++++ .../baeldung/servlets/UserLoginServlet.java | 30 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 javax-servlets/src/main/java/com/baeldung/servlets/MainServlet.java create mode 100644 javax-servlets/src/main/java/com/baeldung/servlets/UpdateServlet.java create mode 100644 javax-servlets/src/main/java/com/baeldung/servlets/UserLoginServlet.java diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/MainServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/MainServlet.java new file mode 100644 index 0000000000..d4417b0b4e --- /dev/null +++ b/javax-servlets/src/main/java/com/baeldung/servlets/MainServlet.java @@ -0,0 +1,22 @@ +package com.baeldung.servlets; + +import java.io.IOException; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +@WebServlet("/main") +public class MainServlet extends HttpServlet { + + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + response.sendRedirect("main.jsp"); + } + + + + +} diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/UpdateServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/UpdateServlet.java new file mode 100644 index 0000000000..d0404d0cd4 --- /dev/null +++ b/javax-servlets/src/main/java/com/baeldung/servlets/UpdateServlet.java @@ -0,0 +1,30 @@ +package com.baeldung.servlets; + + +import java.io.IOException; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +@WebServlet("/update") +public class UpdateServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + HttpSession session = request.getSession(false); + + session.setAttribute("userName", request.getParameter("userName")); + session.setAttribute("age", request.getParameter("age")); + + request.setAttribute("sessionData", session); + RequestDispatcher requestDispather = request.getRequestDispatcher("update.jsp"); + + requestDispather.forward(request, response); + } + +} diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/UserLoginServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/UserLoginServlet.java new file mode 100644 index 0000000000..6becf04a0c --- /dev/null +++ b/javax-servlets/src/main/java/com/baeldung/servlets/UserLoginServlet.java @@ -0,0 +1,30 @@ +package com.baeldung.servlets; + + +import java.io.IOException; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +@WebServlet("/u_login") +public class UserLoginServlet extends HttpServlet { + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + HttpSession session = request.getSession(); + + session.setAttribute("userId", request.getParameter("userId")); + + request.setAttribute("id", session.getAttribute("userId")); + + RequestDispatcher requestDispather = request.getRequestDispatcher("userlogin.jsp"); + + requestDispather.forward(request, response); + + } + +} From 93bbd7881c09ea97c91cdcced2cae6cbbf920f97 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:06:35 +0530 Subject: [PATCH 215/309] README.md updated with BAEL-4408 --- javax-servlets/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/javax-servlets/README.md b/javax-servlets/README.md index 7dbe1a02ad..54f92064a0 100644 --- a/javax-servlets/README.md +++ b/javax-servlets/README.md @@ -12,3 +12,4 @@ This module contains articles about Servlets. - [Jakarta EE Servlet Exception Handling](https://www.baeldung.com/servlet-exceptions) - [Context and Servlet Initialization Parameters](https://www.baeldung.com/context-servlet-initialization-param) - [The Difference between getRequestURI and getPathInfo in HttpServletRequest](https://www.baeldung.com/http-servlet-request-requesturi-pathinfo) +- Difference between request.getSession() and request.getSession(true) From a904f90ffcc1b0678236313cebf06d4b8994c008 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:10:20 +0530 Subject: [PATCH 216/309] Delete FirstServlet.java --- .../baeldung/httpsession/FirstServlet.java | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 spring-session/http-session-example/src/main/java/com/baeldung/httpsession/FirstServlet.java diff --git a/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/FirstServlet.java b/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/FirstServlet.java deleted file mode 100644 index 950bea2c07..0000000000 --- a/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/FirstServlet.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.httpsession; - -import java.io.IOException; -import java.io.PrintWriter; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -public class FirstServlet extends HttpServlet { - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - try { - HttpSession session = request.getSession(); - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); - - String name = request.getParameter("userName"); - session.setAttribute("uname", name); - out.println("Hi " + name + " Your Session Id is : " + session.getId() + " "); - - out.println("
Second Servlet"); - - out.close(); - - } catch (Exception e) { - System.out.println(e); - } - } - -} From 2db04e302f98867c2902a5dc26fcddcfe4af74b6 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:10:35 +0530 Subject: [PATCH 217/309] Delete SecondServlet.java --- .../baeldung/httpsession/SecondServlet.java | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 spring-session/http-session-example/src/main/java/com/baeldung/httpsession/SecondServlet.java diff --git a/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/SecondServlet.java b/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/SecondServlet.java deleted file mode 100644 index 6a5ef7e9a8..0000000000 --- a/spring-session/http-session-example/src/main/java/com/baeldung/httpsession/SecondServlet.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.httpsession; - -import java.io.IOException; -import java.io.PrintWriter; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -public class SecondServlet extends HttpServlet { - - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - try { - - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); - - HttpSession session = request.getSession(true); - String name = (String) session.getAttribute("uname"); - out.println("Hi " + name + " Your Session Id is : " + session.getId()); - - out.close(); - - } catch (Exception e) { - System.out.println(e); - } - } - -} From 3c3b38df33f1102f6c7b9cb632096f6d4adb0d1d Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:11:04 +0530 Subject: [PATCH 218/309] Delete index.html --- .../http-session-example/src/main/webapp/index.html | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 spring-session/http-session-example/src/main/webapp/index.html diff --git a/spring-session/http-session-example/src/main/webapp/index.html b/spring-session/http-session-example/src/main/webapp/index.html deleted file mode 100644 index 0e5889f21a..0000000000 --- a/spring-session/http-session-example/src/main/webapp/index.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - -
- Name:

-
- - \ No newline at end of file From efac1811a34ca78fcb1320a123bfa07761fc03dc Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:11:30 +0530 Subject: [PATCH 219/309] Delete web.xml --- .../src/main/webapp/WEB-INF/web.xml | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 spring-session/http-session-example/src/main/webapp/WEB-INF/web.xml diff --git a/spring-session/http-session-example/src/main/webapp/WEB-INF/web.xml b/spring-session/http-session-example/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 2c9a4c118b..0000000000 --- a/spring-session/http-session-example/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - httpsession - - index.html - - - - - FirstServlet - com.baeldung.httpsession.FirstServlet - - - SecondServlet - com.baeldung.httpsession.SecondServlet - - - - - FirstServlet - /first - - - SecondServlet - /second - - - - \ No newline at end of file From 14d522372d6099aa4e92524cffd89ff0eca92732 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:12:12 +0530 Subject: [PATCH 220/309] Delete README.md --- spring-session/http-session-example/README.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 spring-session/http-session-example/README.md diff --git a/spring-session/http-session-example/README.md b/spring-session/http-session-example/README.md deleted file mode 100644 index 95c7a41e2d..0000000000 --- a/spring-session/http-session-example/README.md +++ /dev/null @@ -1,5 +0,0 @@ -## HttpSession - -This module contains article about Difference Between request.getSession() and request.getSession(true) - -### Relevant Articles: From 257b130ec2667fc18da4eb33a801f284b408f348 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:12:25 +0530 Subject: [PATCH 221/309] Delete pom.xml --- spring-session/http-session-example/pom.xml | 26 --------------------- 1 file changed, 26 deletions(-) delete mode 100644 spring-session/http-session-example/pom.xml diff --git a/spring-session/http-session-example/pom.xml b/spring-session/http-session-example/pom.xml deleted file mode 100644 index a77176fb4b..0000000000 --- a/spring-session/http-session-example/pom.xml +++ /dev/null @@ -1,26 +0,0 @@ - - 4.0.0 - com.baeldung.httpsession - http-session-example - war - 0.0.1-SNAPSHOT - http-session-example Maven Webapp - http://maven.apache.org - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - javax.servlet - servlet-api - 2.5 - provided - - - From 82651842c78debe7be84f9101c529d6ac1ff4477 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:13:05 +0530 Subject: [PATCH 222/309] Update README.md Removing BAEL-4408 from Readme.md --- spring-session/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-session/README.md b/spring-session/README.md index 47125a6032..65040ec734 100644 --- a/spring-session/README.md +++ b/spring-session/README.md @@ -6,4 +6,3 @@ This module contains articles about Spring Session - [Guide to Spring Session](https://www.baeldung.com/spring-session) - [Spring Session with JDBC](https://www.baeldung.com/spring-session-jdbc) - [Spring Session with MongoDB](https://www.baeldung.com/spring-session-mongodb) -- Difference Between request.getSession() and request.getSession(true) From 5e0e587888663d5972cd556707290901e64d1ce0 Mon Sep 17 00:00:00 2001 From: gupta-ashu01 <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 8 Aug 2020 15:15:01 +0530 Subject: [PATCH 223/309] Update pom.xml Removing BAEL-4408 module from pom --- spring-session/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-session/pom.xml b/spring-session/pom.xml index d5dbe28a2b..6616a0d1f3 100644 --- a/spring-session/pom.xml +++ b/spring-session/pom.xml @@ -19,7 +19,6 @@ spring-session-jdbc spring-session-redis spring-session-mongodb - http-session-example
From 15e94bb577c8895f1ed720284c95c3b3a0609da5 Mon Sep 17 00:00:00 2001 From: Rando Shtishi <42577665+rshtishi@users.noreply.github.com> Date: Sat, 8 Aug 2020 22:21:57 +0200 Subject: [PATCH 224/309] BAEL-4230 - Adding Introduction to Spring Data JDBC Project (#9665) --- persistence-modules/pom.xml | 4 ++ persistence-modules/spring-data-jdbc/pom.xml | 29 +++++++++ .../springdatajdbcintro/Application.java | 59 +++++++++++++++++++ .../springdatajdbcintro/DatabaseSeeder.java | 26 ++++++++ .../springdatajdbcintro/entity/Person.java | 57 ++++++++++++++++++ .../repository/PersonRepository.java | 23 ++++++++ .../src/main/resources/application.properties | 8 +++ .../src/main/resources/schema.sql | 5 ++ pom.xml | 2 +- 9 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/spring-data-jdbc/pom.xml create mode 100644 persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/Application.java create mode 100644 persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/DatabaseSeeder.java create mode 100644 persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/entity/Person.java create mode 100644 persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/repository/PersonRepository.java create mode 100644 persistence-modules/spring-data-jdbc/src/main/resources/application.properties create mode 100644 persistence-modules/spring-data-jdbc/src/main/resources/schema.sql diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 31b9aaaf6d..78f1afd39a 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -59,12 +59,16 @@ spring-data-elasticsearch spring-data-gemfire spring-data-geode + spring-data-jpa-annotations spring-data-jpa-crud spring-data-jpa-enterprise spring-data-jpa-filtering spring-data-jpa-query spring-data-jpa-repo + + spring-data-jdbc + spring-data-keyvalue spring-data-mongodb spring-data-neo4j diff --git a/persistence-modules/spring-data-jdbc/pom.xml b/persistence-modules/spring-data-jdbc/pom.xml new file mode 100644 index 0000000000..ff034104d7 --- /dev/null +++ b/persistence-modules/spring-data-jdbc/pom.xml @@ -0,0 +1,29 @@ + + 4.0.0 + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + spring-data-jdbc + spring-data-jdbc + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + com.h2database + h2 + runtime + + + diff --git a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/Application.java b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/Application.java new file mode 100644 index 0000000000..7f50aa87f1 --- /dev/null +++ b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/Application.java @@ -0,0 +1,59 @@ +package com.baeldung.springdatajdbcintro; + +import java.util.Optional; + +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import com.baeldung.springdatajdbcintro.entity.Person; +import com.baeldung.springdatajdbcintro.repository.PersonRepository; + +import ch.qos.logback.classic.Logger; + +@SpringBootApplication +public class Application implements CommandLineRunner { + + private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(Application.class); + + @Autowired + private PersonRepository repository; + @Autowired + private DatabaseSeeder dbSeeder; + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Override + public void run(String... arg0) throws Exception { + + LOGGER.info("@@ Inserting Data...."); + dbSeeder.insertData(); + LOGGER.info("@@ findAll() call..."); + repository.findAll() + .forEach(person -> LOGGER.info(person.toString())); + LOGGER.info("@@ findById() call..."); + Optional optionalPerson = repository.findById(1L); + optionalPerson.ifPresent(person -> LOGGER.info(person.toString())); + LOGGER.info("@@ save() call..."); + Person newPerson = new Person("Franz", "Kafka"); + Person result = repository.save(newPerson); + LOGGER.info(result.toString()); + LOGGER.info("@@ delete"); + optionalPerson.ifPresent(person -> repository.delete(person)); + LOGGER.info("@@ findAll() call..."); + repository.findAll() + .forEach(person -> LOGGER.info(person.toString())); + LOGGER.info("@@ findByFirstName() call..."); + repository.findByFirstName("Franz") + .forEach(person -> LOGGER.info(person.toString())); + LOGGER.info("@@ findByFirstName() call..."); + repository.updateByFirstName(2L, "Date Inferno"); + repository.findAll() + .forEach(person -> LOGGER.info(person.toString())); + + } +} diff --git a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/DatabaseSeeder.java b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/DatabaseSeeder.java new file mode 100644 index 0000000000..97055fd7ac --- /dev/null +++ b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/DatabaseSeeder.java @@ -0,0 +1,26 @@ +package com.baeldung.springdatajdbcintro; + +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Component; + +import ch.qos.logback.classic.Logger; + +@Component +public class DatabaseSeeder { + + private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(DatabaseSeeder.class); + + @Autowired + private JdbcTemplate jdbcTemplate; + + public void insertData() { + LOGGER.info("> Inserting data..."); + jdbcTemplate.execute("INSERT INTO Person(first_name,last_name) VALUES('Victor', 'Hygo')"); + jdbcTemplate.execute("INSERT INTO Person(first_name,last_name) VALUES('Dante', 'Alighieri')"); + jdbcTemplate.execute("INSERT INTO Person(first_name,last_name) VALUES('Stefan', 'Zweig')"); + jdbcTemplate.execute("INSERT INTO Person(first_name,last_name) VALUES('Oscar', 'Wilde')"); + } + +} diff --git a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/entity/Person.java b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/entity/Person.java new file mode 100644 index 0000000000..7c4c1eec73 --- /dev/null +++ b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/entity/Person.java @@ -0,0 +1,57 @@ +package com.baeldung.springdatajdbcintro.entity; + +import org.springframework.data.annotation.Id; + +public class Person { + + @Id + private long id; + private String firstName; + private String lastName; + + public Person() { + super(); + } + + public Person(long id, String firstName, String lastName) { + super(); + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public Person(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public String toString() { + return "Person [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + "]"; + } + +} diff --git a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/repository/PersonRepository.java b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/repository/PersonRepository.java new file mode 100644 index 0000000000..2f2329caec --- /dev/null +++ b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/repository/PersonRepository.java @@ -0,0 +1,23 @@ +package com.baeldung.springdatajdbcintro.repository; + +import java.util.List; + +import org.springframework.data.jdbc.repository.query.Modifying; +import org.springframework.data.jdbc.repository.query.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import com.baeldung.springdatajdbcintro.entity.Person; + +@Repository +public interface PersonRepository extends CrudRepository { + + @Query("select * from person where first_name=:firstName") + List findByFirstName(@Param("firstName") String firstName); + + @Modifying + @Query("UPDATE person SET first_name = :name WHERE id = :id") + boolean updateByFirstName(@Param("id") Long id, @Param("name") String name); + +} diff --git a/persistence-modules/spring-data-jdbc/src/main/resources/application.properties b/persistence-modules/spring-data-jdbc/src/main/resources/application.properties new file mode 100644 index 0000000000..45099222fc --- /dev/null +++ b/persistence-modules/spring-data-jdbc/src/main/resources/application.properties @@ -0,0 +1,8 @@ +#H2 DB +spring.jpa.hibernate.ddl-auto=none +spring.h2.console.enabled=true +spring.datasource.url=jdbc:h2:mem:persondb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=test +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect \ No newline at end of file diff --git a/persistence-modules/spring-data-jdbc/src/main/resources/schema.sql b/persistence-modules/spring-data-jdbc/src/main/resources/schema.sql new file mode 100644 index 0000000000..5618822bf9 --- /dev/null +++ b/persistence-modules/spring-data-jdbc/src/main/resources/schema.sql @@ -0,0 +1,5 @@ +create table person ( + id integer identity primary key, + first_name varchar(30), + last_name varchar(30) +); \ No newline at end of file diff --git a/pom.xml b/pom.xml index b110cb0fe0..a69ffa2798 100644 --- a/pom.xml +++ b/pom.xml @@ -1407,4 +1407,4 @@ 1.4.197
- + \ No newline at end of file From 87111ea998379a1e94b76304b77f0aabab59cfd5 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Sat, 8 Aug 2020 22:41:01 +0200 Subject: [PATCH 225/309] BAEL-4493: Use the prefered Set.toArray() approach (#9837) --- .../collections/JavaCollectionConversionUnitTest.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java b/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java index 2fd31ab609..ba640f3fb2 100644 --- a/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java +++ b/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java @@ -72,7 +72,7 @@ public class JavaCollectionConversionUnitTest { @Test public final void givenUsingCoreJava_whenSetConvertedToArray_thenCorrect() { final Set sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5); - final Integer[] targetArray = sourceSet.toArray(new Integer[sourceSet.size()]); + final Integer[] targetArray = sourceSet.toArray(new Integer[0]); } @Test @@ -94,16 +94,10 @@ public class JavaCollectionConversionUnitTest { CollectionUtils.addAll(targetSet, sourceArray); } - @Test - public final void givenUsingCommonsCollections_whenSetConvertedToArray_thenCorrect() { - final Set sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5); - final Integer[] targetArray = sourceSet.toArray(new Integer[sourceSet.size()]); - } - @Test public final void givenUsingCommonsCollections_whenSetConvertedToArrayOfPrimitives_thenCorrect() { final Set sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5); - final Integer[] targetArray = sourceSet.toArray(new Integer[sourceSet.size()]); + final Integer[] targetArray = sourceSet.toArray(new Integer[0]); final int[] primitiveTargetArray = ArrayUtils.toPrimitive(targetArray); } From 099b9e9121b7f180fe00697624019cf18720cdbc Mon Sep 17 00:00:00 2001 From: Oussama BEN MAHMOUD Date: Sun, 9 Aug 2020 02:05:27 +0200 Subject: [PATCH 226/309] BAEL-4392: Java Files Open Options --- .../openoptions/OpenOptionsUnitTest.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 core-java-modules/core-java-io-3/src/test/java/com/baeldung/openoptions/OpenOptionsUnitTest.java diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/openoptions/OpenOptionsUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/openoptions/OpenOptionsUnitTest.java new file mode 100644 index 0000000000..323c965edf --- /dev/null +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/openoptions/OpenOptionsUnitTest.java @@ -0,0 +1,96 @@ +package com.baeldung.openoptions; + +import org.hamcrest.CoreMatchers; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; + +import static org.junit.Assert.*; + +public class OpenOptionsUnitTest { + + private static final String HOME = System.getProperty("user.home"); + private static final String DUMMY_FILE_NAME = "sample.txt"; + private static final String EXISTING_FILE_NAME = "existingFile.txt"; + + private static final String DUMMY_TEXT = "This is a sample text."; + private static final String ANOTHER_DUMMY_TEXT = "This is a another text."; + + @BeforeClass + public static void beforeAll() throws IOException { + Path path = Paths.get(HOME, DUMMY_FILE_NAME); + + try (OutputStream out = Files.newOutputStream(path)) { + out.write(DUMMY_TEXT.getBytes()); + } + + Files.createFile(Paths.get(HOME, EXISTING_FILE_NAME)); + } + + @AfterClass + public static void afterAll() throws IOException { + Files.delete(Paths.get(HOME, "newfile.txt")); + Files.delete(Paths.get(HOME, "sparse.txt")); + Files.delete(Paths.get(HOME, DUMMY_FILE_NAME)); + } + + @Test + public void givenExistingPath_whenCreateNewFile_thenCorrect() throws IOException { + Path path = Paths.get(HOME, "newfile.txt"); + assertFalse(Files.exists(path)); + + Files.write(path, DUMMY_TEXT.getBytes(), StandardOpenOption.CREATE); + assertTrue(Files.exists(path)); + } + + @Test + public void givenExistingPath_whenReadExistingFile_thenCorrect() throws IOException { + Path path = Paths.get(HOME, DUMMY_FILE_NAME); + + try (InputStream in = Files.newInputStream(path); BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { + String line; + while ((line = reader.readLine()) != null) { + assertThat(line, CoreMatchers.containsString(DUMMY_TEXT)); + } + } + } + + @Test + public void givenExistingPath_whenWriteToExistingFile_thenCorrect() throws IOException { + Path path = Paths.get(HOME, DUMMY_FILE_NAME); + + try (OutputStream out = Files.newOutputStream(path, StandardOpenOption.APPEND, StandardOpenOption.WRITE)) { + out.write(ANOTHER_DUMMY_TEXT.getBytes()); + } + } + + @Test + public void givenExistingPath_whenCreateSparseFile_thenCorrect() throws IOException { + Path path = Paths.get(HOME, "sparse.txt"); + Files.write(path, DUMMY_TEXT.getBytes(), StandardOpenOption.CREATE_NEW, StandardOpenOption.SPARSE); + } + + @Test + public void givenExistingPath_whenDeleteOnClose_thenCorrect() throws IOException { + Path path = Paths.get(HOME, EXISTING_FILE_NAME); + assertTrue(Files.exists(path)); // file was already created and exists + + try (OutputStream out = Files.newOutputStream(path, StandardOpenOption.APPEND, StandardOpenOption.WRITE, StandardOpenOption.DELETE_ON_CLOSE)) { + out.write(ANOTHER_DUMMY_TEXT.getBytes()); + } + + assertFalse(Files.exists(path)); // file is deleted + } + + @Test + public void givenExistingPath_whenWriteAndSync_thenCorrect() throws IOException { + Path path = Paths.get(HOME, DUMMY_FILE_NAME); + Files.write(path, ANOTHER_DUMMY_TEXT.getBytes(), StandardOpenOption.APPEND, StandardOpenOption.WRITE, StandardOpenOption.SYNC); + } +} From d50a83197279a0fda143ac3f1bc66025c5873b42 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sat, 8 Aug 2020 21:05:32 -0400 Subject: [PATCH 227/309] BAEL-4077 Fixup styling --- .../baeldung/jpa/equality/EqualByBusinessKey.java | 14 ++++++++------ .../java/com/baeldung/jpa/equality/EqualById.java | 13 +++++++------ .../baeldung/jpa/equality/EqualByJavaDefault.java | 4 +--- .../baeldung/jpa/equality/EqualityUnitTest.java | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java index 3e34f97d77..655db4e575 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java @@ -40,15 +40,17 @@ public class EqualByBusinessKey { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (obj instanceof EqualByBusinessKey) - if (((EqualByBusinessKey) obj).getEmail() == getEmail()) + } + if (obj instanceof EqualByBusinessKey) { + if (((EqualByBusinessKey) obj).getEmail() == getEmail()) { return true; - + } + } return false; } - } diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java index f29a152f3e..cebfb5fcec 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java @@ -41,14 +41,15 @@ public class EqualById { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (obj instanceof EqualById) - return ((EqualById) obj).getId() == getId(); - + } + if (obj instanceof EqualById) { + return ((EqualById) obj).getId().equals(getId()); + } return false; } - } diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java index 04a81865c6..b312845b61 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java @@ -30,9 +30,7 @@ public class EqualByJavaDefault implements Cloneable{ this.email = email; } - public Object clone() throws - CloneNotSupportedException - { + public Object clone() throws CloneNotSupportedException { return super.clone(); } } diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java index c672c9e460..03ac11b6fd 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java @@ -71,4 +71,4 @@ public class EqualityUnitTest { Assert.assertEquals(object1, object2); Assert.assertNotEquals(object1.getId(), object2.getId()); } -} \ No newline at end of file +} From 18d7fc0bdc5b9b6b7f3de538a0a91485008df700 Mon Sep 17 00:00:00 2001 From: andrebrowne <42154231+andrebrowne@users.noreply.github.com> Date: Sat, 8 Aug 2020 21:05:32 -0400 Subject: [PATCH 228/309] BAEL-4077 Fixup styling --- persistence-modules/java-jpa-3/pom.xml | 56 ------------------- .../jpa/equality/EqualByBusinessKey.java | 14 +++-- .../com/baeldung/jpa/equality/EqualById.java | 13 +++-- .../jpa/equality/EqualByJavaDefault.java | 4 +- .../jpa/equality/EqualityUnitTest.java | 2 +- 5 files changed, 17 insertions(+), 72 deletions(-) diff --git a/persistence-modules/java-jpa-3/pom.xml b/persistence-modules/java-jpa-3/pom.xml index 562f337215..da18ae3046 100644 --- a/persistence-modules/java-jpa-3/pom.xml +++ b/persistence-modules/java-jpa-3/pom.xml @@ -66,62 +66,6 @@ -proc:none - - org.bsc.maven - maven-processor-plugin - ${maven-processor-plugin.version} - - - process - - process - - generate-sources - - target/metamodel - - org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - ${build-helper-maven-plugin.version} - - - add-source - generate-sources - - add-source - - - - target/metamodel - ${project.build.directory}/generated-sources/java/ - - - - - - - com.mysema.maven - apt-maven-plugin - 1.1.3 - - - - process - - - target/generated-sources/java - com.querydsl.apt.jpa.JPAAnnotationProcessor - - - - diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java index 3e34f97d77..655db4e575 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByBusinessKey.java @@ -40,15 +40,17 @@ public class EqualByBusinessKey { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (obj instanceof EqualByBusinessKey) - if (((EqualByBusinessKey) obj).getEmail() == getEmail()) + } + if (obj instanceof EqualByBusinessKey) { + if (((EqualByBusinessKey) obj).getEmail() == getEmail()) { return true; - + } + } return false; } - } diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java index f29a152f3e..cebfb5fcec 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualById.java @@ -41,14 +41,15 @@ public class EqualById { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (obj instanceof EqualById) - return ((EqualById) obj).getId() == getId(); - + } + if (obj instanceof EqualById) { + return ((EqualById) obj).getId().equals(getId()); + } return false; } - } diff --git a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java index 04a81865c6..b312845b61 100644 --- a/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java +++ b/persistence-modules/java-jpa-3/src/main/java/com/baeldung/jpa/equality/EqualByJavaDefault.java @@ -30,9 +30,7 @@ public class EqualByJavaDefault implements Cloneable{ this.email = email; } - public Object clone() throws - CloneNotSupportedException - { + public Object clone() throws CloneNotSupportedException { return super.clone(); } } diff --git a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java index c672c9e460..03ac11b6fd 100644 --- a/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java +++ b/persistence-modules/java-jpa-3/src/test/java/com/baeldung/jpa/equality/EqualityUnitTest.java @@ -71,4 +71,4 @@ public class EqualityUnitTest { Assert.assertEquals(object1, object2); Assert.assertNotEquals(object1.getId(), object2.getId()); } -} \ No newline at end of file +} From 164957ad0ab5baf72a686ef26851b15f6aaeb161 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Sun, 9 Aug 2020 11:38:50 +0430 Subject: [PATCH 229/309] Improvement for Spring Boot Exit Codes --- ...ExceptionExitCodeGeneratorApplication.java | 21 +++++++++++++++++++ .../FailedToStartException.java | 11 ++++++++++ 2 files changed, 32 insertions(+) create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exceptionexitgen/ExceptionExitCodeGeneratorApplication.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exceptionexitgen/FailedToStartException.java diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exceptionexitgen/ExceptionExitCodeGeneratorApplication.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exceptionexitgen/ExceptionExitCodeGeneratorApplication.java new file mode 100644 index 0000000000..a4ccb61dbb --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exceptionexitgen/ExceptionExitCodeGeneratorApplication.java @@ -0,0 +1,21 @@ +package com.baeldung.exitcode.exceptionexitgen; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class ExceptionExitCodeGeneratorApplication { + + public static void main(String[] args) { + SpringApplication.run(ExceptionExitCodeGeneratorApplication.class, args); + } + + @Bean + CommandLineRunner failApplication() { + return args -> { + throw new FailedToStartException(); + }; + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exceptionexitgen/FailedToStartException.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exceptionexitgen/FailedToStartException.java new file mode 100644 index 0000000000..04ac553153 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exceptionexitgen/FailedToStartException.java @@ -0,0 +1,11 @@ +package com.baeldung.exitcode.exceptionexitgen; + +import org.springframework.boot.ExitCodeGenerator; + +public class FailedToStartException extends RuntimeException implements ExitCodeGenerator { + + @Override + public int getExitCode() { + return 127; + } +} From 2453a731ca25192bb116554faf1d3cb133f33760 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 9 Aug 2020 19:35:21 +0530 Subject: [PATCH 230/309] make folder name and artifactId same --- jhipster-5/bookstore-monolith/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jhipster-5/bookstore-monolith/pom.xml b/jhipster-5/bookstore-monolith/pom.xml index 03395e47ed..c965fd962d 100644 --- a/jhipster-5/bookstore-monolith/pom.xml +++ b/jhipster-5/bookstore-monolith/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.baeldung.jhipster5 - bookstore + bookstore-monolith 0.0.1-SNAPSHOT war Bookstore From e23d7f8efb72c694509d3f05c6114bce2b784ba7 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sun, 9 Aug 2020 18:46:32 +0100 Subject: [PATCH 231/309] BAEL-4321 demo app for yaml to pojo --- configuration/yaml-to-pojo/README.md | 9 ++++ configuration/yaml-to-pojo/pom.xml | 54 +++++++++++++++++++ .../java/yamltopojo/demo/DemoApplication.java | 16 ++++++ .../demo/config/TshirtSizeConfig.java | 27 ++++++++++ .../demo/controller/TshirtSizeController.java | 22 ++++++++ .../demo/service/SizeConverterImpl.java | 22 ++++++++ .../demo/service/SizeConverterService.java | 8 +++ .../src/main/resources/application.yml | 30 +++++++++++ .../yamltopojo/demo/DemoApplicationTests.java | 13 +++++ .../controller/TshirtSizeControllerTest.java | 38 +++++++++++++ 10 files changed, 239 insertions(+) create mode 100644 configuration/yaml-to-pojo/README.md create mode 100644 configuration/yaml-to-pojo/pom.xml create mode 100644 configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/DemoApplication.java create mode 100644 configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java create mode 100644 configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java create mode 100644 configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java create mode 100644 configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterService.java create mode 100644 configuration/yaml-to-pojo/src/main/resources/application.yml create mode 100644 configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/DemoApplicationTests.java create mode 100644 configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java diff --git a/configuration/yaml-to-pojo/README.md b/configuration/yaml-to-pojo/README.md new file mode 100644 index 0000000000..9dba74a7e5 --- /dev/null +++ b/configuration/yaml-to-pojo/README.md @@ -0,0 +1,9 @@ +This is a demo application for using YAML configuration for defining values in a POJO class. + +The application has an endpoint to provide T-shirt size conversion for label and countrycode. + +If you run this service locally you can call this endpoint on: + +`localhost:8080/convertSize?label=M&countryCode=fr` + +It should return the size as int. \ No newline at end of file diff --git a/configuration/yaml-to-pojo/pom.xml b/configuration/yaml-to-pojo/pom.xml new file mode 100644 index 0000000000..f6b55718be --- /dev/null +++ b/configuration/yaml-to-pojo/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.2.RELEASE + + + yaml-to-pojo + demo + 0.0.1-SNAPSHOT + demo + Demo project for YAML into POJO + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.springframework.boot + spring-boot-starter-web + RELEASE + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/DemoApplication.java b/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/DemoApplication.java new file mode 100644 index 0000000000..ec8df793c2 --- /dev/null +++ b/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/DemoApplication.java @@ -0,0 +1,16 @@ +package yamltopojo.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import yamltopojo.demo.config.TshirtSizeConfig; + +@SpringBootApplication +@EnableConfigurationProperties(TshirtSizeConfig.class) +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java b/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java new file mode 100644 index 0000000000..8f8d2e5b39 --- /dev/null +++ b/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java @@ -0,0 +1,27 @@ +package yamltopojo.demo.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +import java.util.Map; + +@ConfigurationProperties(prefix = "t-shirt-size") +public class TshirtSizeConfig { + + private final Map simpleMapping; + + private final Map> complexMapping; + + + public TshirtSizeConfig(Map simpleMapping, Map> complexMapping) { + this.simpleMapping = simpleMapping; + this.complexMapping = complexMapping; + } + + public Map getSimpleMapping() { + return simpleMapping; + } + + public Map> getComplexMapping() { + return complexMapping; + } +} diff --git a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java b/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java new file mode 100644 index 0000000000..d555549bd4 --- /dev/null +++ b/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java @@ -0,0 +1,22 @@ +package yamltopojo.demo.controller; + +import org.springframework.web.bind.annotation.*; +import yamltopojo.demo.service.SizeConverterService; + +@RestController +@RequestMapping(value = "/") +public class TshirtSizeController { + + private SizeConverterService service; + + public TshirtSizeController(SizeConverterService service) { + this.service = service; + } + + @RequestMapping(value ="convertSize", method = RequestMethod.GET) + public int convertSize(@RequestParam(value = "label") final String label, + @RequestParam(value = "countryCode", required = false) final String countryCode) { + return service.convertSize(label, countryCode); + } + +} diff --git a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java b/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java new file mode 100644 index 0000000000..8f95e4253b --- /dev/null +++ b/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java @@ -0,0 +1,22 @@ +package yamltopojo.demo.service; + +import org.springframework.stereotype.Service; +import yamltopojo.demo.config.TshirtSizeConfig; + + +@Service +public class SizeConverterImpl implements SizeConverterService { + + private TshirtSizeConfig tshirtSizeConfig; + + public SizeConverterImpl(TshirtSizeConfig tshirtSizeConfig) { + this.tshirtSizeConfig = tshirtSizeConfig; + } + + public int convertSize(String label, String countryCode) { + if(countryCode == null) { + return tshirtSizeConfig.getSimpleMapping().get(label); + } + return tshirtSizeConfig.getComplexMapping().get(label).get(countryCode); + } +} diff --git a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterService.java b/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterService.java new file mode 100644 index 0000000000..3e24681cbe --- /dev/null +++ b/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterService.java @@ -0,0 +1,8 @@ +package yamltopojo.demo.service; + + +public interface SizeConverterService { + + int convertSize(String label, String countryCode); + +} diff --git a/configuration/yaml-to-pojo/src/main/resources/application.yml b/configuration/yaml-to-pojo/src/main/resources/application.yml new file mode 100644 index 0000000000..edd200389e --- /dev/null +++ b/configuration/yaml-to-pojo/src/main/resources/application.yml @@ -0,0 +1,30 @@ +t-shirt-size: + simple-mapping: + XS: 6 + S: 8 + M: 10 + L: 12 + XL: 14 + + + complex-mapping: + XS: + uk: 6 + fr: 34 + us: 2 + S: + uk: 8 + fr: 36 + us: 4 + M: + uk: 10 + fr: 38 + us: 6 + L: + uk: 12 + fr: 40 + us: 8 + XL: + uk: 14 + fr: 42 + us: 10 diff --git a/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/DemoApplicationTests.java b/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/DemoApplicationTests.java new file mode 100644 index 0000000000..dfe980c05c --- /dev/null +++ b/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/DemoApplicationTests.java @@ -0,0 +1,13 @@ +package yamltopojo.demo; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class DemoApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java b/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java new file mode 100644 index 0000000000..3c1ef6dff5 --- /dev/null +++ b/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java @@ -0,0 +1,38 @@ +package yamltopojo.demo.controller; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import yamltopojo.demo.service.SizeConverterService; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class TshirtSizeControllerTest { + + @Mock + private SizeConverterService service; + + @InjectMocks + private TshirtSizeController tested; + + @Test + void convertSize() { + + // Given + String label = "S"; + String countryCode = "fr"; + int result = 36; + + // + when(service.convertSize(label, countryCode)).thenReturn(result); + int actual = tested.convertSize(label, countryCode); + + // Then + assertEquals(actual, result); + + } +} \ No newline at end of file From 0c413754437cb84e3f024802683e8528d8f0a2ff Mon Sep 17 00:00:00 2001 From: azhwani <> Date: Mon, 10 Aug 2020 13:58:50 +0100 Subject: [PATCH 232/309] quick fix --- .../controller/RestApiController.java | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 spring-5-security/src/main/java/com/baeldung/logoutredirects/controller/RestApiController.java diff --git a/spring-5-security/src/main/java/com/baeldung/logoutredirects/controller/RestApiController.java b/spring-5-security/src/main/java/com/baeldung/logoutredirects/controller/RestApiController.java deleted file mode 100644 index 7d5b3ebbaa..0000000000 --- a/spring-5-security/src/main/java/com/baeldung/logoutredirects/controller/RestApiController.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.logoutredirects.controller; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class RestApiController { - - @GetMapping("/login") - public String login() { - return "login"; - } - - @PostMapping("/logout") - public String logout() { - return "redirect:/login"; - } - -} From e7d193055062b58f5ac91235d79b91042dd652eb Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 11:19:00 +0800 Subject: [PATCH 233/309] Update README.md --- java-numbers-3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-numbers-3/README.md b/java-numbers-3/README.md index ab0bbd995d..2cec5d52cd 100644 --- a/java-numbers-3/README.md +++ b/java-numbers-3/README.md @@ -4,7 +4,7 @@ This module contains articles about numbers in Java. ### Relevant Articles: -- [Generating Random Numbers](https://www.baeldung.com/java-generating-random-numbers) +- [Generating Random Numbers in Java](https://www.baeldung.com/java-generating-random-numbers) - [Convert Double to Long in Java](https://www.baeldung.com/java-convert-double-long) - [Check for null Before Calling Parse in Double.parseDouble](https://www.baeldung.com/java-check-null-parse-double) - [Generating Random Numbers in a Range in Java](https://www.baeldung.com/java-generating-random-numbers-in-range) From fffbcfc2c082b6f7b1469864b47c9316ca185ab5 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 11:24:33 +0800 Subject: [PATCH 234/309] Update README.md --- core-java-modules/core-java-9-new-features/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-9-new-features/README.md b/core-java-modules/core-java-9-new-features/README.md index d10d0aad2d..5af069c6f0 100644 --- a/core-java-modules/core-java-9-new-features/README.md +++ b/core-java-modules/core-java-9-new-features/README.md @@ -14,3 +14,4 @@ This module contains articles about core Java features that have been introduced - [Java 9 Reactive Streams](https://www.baeldung.com/java-9-reactive-streams) - [Multi-Release JAR Files with Maven](https://www.baeldung.com/maven-multi-release-jars) - [The Difference between RxJava API and the Java 9 Flow API](https://www.baeldung.com/rxjava-vs-java-flow-api) +- [How to Get a Name of a Method Being Executed?](https://www.baeldung.com/java-name-of-executing-method) From 03229bced14a817ff5f865143a9c7673fbbdadf4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 11:40:49 +0800 Subject: [PATCH 235/309] Update README.md --- spring-boot-modules/spring-boot-mvc-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-mvc-2/README.md b/spring-boot-modules/spring-boot-mvc-2/README.md index c42730f9cc..f9becb721f 100644 --- a/spring-boot-modules/spring-boot-mvc-2/README.md +++ b/spring-boot-modules/spring-boot-mvc-2/README.md @@ -11,4 +11,5 @@ This module contains articles about Spring Web MVC in Spring Boot projects. - [Testing REST with multiple MIME types](https://www.baeldung.com/testing-rest-api-with-multiple-media-types) - [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections) - [Spring Boot Consuming and Producing JSON](https://www.baeldung.com/spring-boot-json) +- [Serve Static Resources with Spring](https://www.baeldung.com/spring-mvc-static-resources) - More articles: [[prev -->]](/spring-boot-modules/spring-boot-mvc) From ccaeb55319f22eb457a5450fccb07cc5c9f58c28 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 12:32:27 +0800 Subject: [PATCH 236/309] Update README.md --- reactive-systems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reactive-systems/README.md b/reactive-systems/README.md index 0558dd141e..b23f4e4dc4 100644 --- a/reactive-systems/README.md +++ b/reactive-systems/README.md @@ -4,4 +4,4 @@ This module contains services for article about reactive systems in Java. Please ### Relevant Articles -- [Reactive Systems in Java](https://www.baeldung.com/) +- [Reactive Systems in Java](https://www.baeldung.com/java-reactive-systems) From bb267b5d64eef65c5fa6adf789c70a32f1d8d05e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 12:45:54 +0800 Subject: [PATCH 237/309] Update README.md --- algorithms-searching/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/algorithms-searching/README.md b/algorithms-searching/README.md index aed3c7d21f..260a4ea714 100644 --- a/algorithms-searching/README.md +++ b/algorithms-searching/README.md @@ -11,3 +11,4 @@ This module contains articles about searching algorithms. - [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search) - [Range Search Algorithm in Java](https://www.baeldung.com/java-range-search) - [Fast Pattern Matching of Strings Using Suffix Tree](https://www.baeldung.com/java-pattern-matching-suffix-tree) +- [Topological Sort of Directed Acyclic Graph](https://www.baeldung.com/cs/dag-topological-sort) From 009308131f46a10537245afc853eafb10b3603cc Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 11 Aug 2020 12:17:02 +0530 Subject: [PATCH 238/309] JAVA-2344: Update "Dockerizing with Jib" article --- jib/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jib/pom.xml b/jib/pom.xml index 1d7413cc18..15e7e44e7c 100644 --- a/jib/pom.xml +++ b/jib/pom.xml @@ -40,6 +40,6 @@ - 0.9.10 + 2.5.0 From b09abfc0bf564d74a10ba11be2e25bc5080da630 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 11 Aug 2020 13:05:01 +0530 Subject: [PATCH 239/309] JAVA-1089: Move the OAuth related lesson code from spring-boot-modules/spring-boot-security --- .../SpringBootOAuth2ResourceApplication.java | 30 ------- ...ingBootAuthorizationServerApplication.java | 47 ---------- .../config/AuthenticationMananagerConfig.java | 18 ---- .../config/AuthorizationServerConfig.java | 46 ---------- .../config/WebSecurityConfiguration.java | 17 ---- .../SpringBootOAuth2SsoApplication.java | 19 ---- ...figAuthorizationServerIntegrationTest.java | 89 ------------------- ...figAuthorizationServerIntegrationTest.java | 32 ------- .../OAuth2IntegrationTestSupport.java | 53 ----------- 9 files changed, 351 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2resource/SpringBootOAuth2ResourceApplication.java delete mode 100644 spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/SpringBootAuthorizationServerApplication.java delete mode 100644 spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthenticationMananagerConfig.java delete mode 100644 spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java delete mode 100644 spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/WebSecurityConfiguration.java delete mode 100644 spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2sso/SpringBootOAuth2SsoApplication.java delete mode 100644 spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/CustomConfigAuthorizationServerIntegrationTest.java delete mode 100644 spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/DefaultConfigAuthorizationServerIntegrationTest.java delete mode 100644 spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/OAuth2IntegrationTestSupport.java diff --git a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2resource/SpringBootOAuth2ResourceApplication.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2resource/SpringBootOAuth2ResourceApplication.java deleted file mode 100644 index 56231a28bd..0000000000 --- a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2resource/SpringBootOAuth2ResourceApplication.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.springbootsecurity.oauth2resource; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@EnableResourceServer -@SpringBootApplication(scanBasePackages = "com.baeldung.springbootsecurity.oauth2resource") -public class SpringBootOAuth2ResourceApplication { - - public static void main(String[] args) { - new SpringApplicationBuilder() - .profiles("resource") - .sources(SpringBootOAuth2ResourceApplication.class) - .build() - .run(args); - } - - @RestController - class SecuredResourceController { - - @GetMapping("/securedResource") - public String securedResource() { - return "Baeldung Secured Resource OK"; - } - - } -} diff --git a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/SpringBootAuthorizationServerApplication.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/SpringBootAuthorizationServerApplication.java deleted file mode 100644 index 04f046ff78..0000000000 --- a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/SpringBootAuthorizationServerApplication.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.springbootsecurity.oauth2server; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.annotation.CurrentSecurityContext; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.security.Principal; - -@EnableResourceServer -@EnableAuthorizationServer -@SpringBootApplication(scanBasePackages = "com.baeldung.springbootsecurity.oauth2server") -public class SpringBootAuthorizationServerApplication { - - private static final Logger logger = LoggerFactory.getLogger(SpringBootAuthorizationServerApplication.class); - - public static void main(String[] args) { - SpringApplication.run(SpringBootAuthorizationServerApplication.class, args); - } - - @RestController - class UserController { - - @GetMapping("/user") - public Principal user(Principal user) { - return user; - } - - @GetMapping("/authentication") - public Object getAuthentication(@CurrentSecurityContext(expression = "authentication") Authentication authentication) { - logger.info("authentication -> {}", authentication); - return authentication.getDetails(); - } - - @GetMapping("/principal") - public String getPrincipal(@CurrentSecurityContext(expression = "authentication.principal") Principal principal) { - logger.info("principal -> {}", principal); - return principal.getName(); - } - } -} diff --git a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthenticationMananagerConfig.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthenticationMananagerConfig.java deleted file mode 100644 index 2b4135f36d..0000000000 --- a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthenticationMananagerConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.springbootsecurity.oauth2server.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; - -@Configuration -@Profile("authz") -public class AuthenticationMananagerConfig extends WebSecurityConfigurerAdapter { - - @Bean - @Override - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java deleted file mode 100644 index 6e21987a89..0000000000 --- a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/AuthorizationServerConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.springbootsecurity.oauth2server.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; -import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; - -@Configuration -@Profile("authz") -public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { - - @Autowired - private AuthenticationManager authenticationManager; - - @Override - public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { - endpoints.authenticationManager(authenticationManager); - } - - @Override - public void configure(ClientDetailsServiceConfigurer clients) throws Exception { - clients - .inMemory() - .withClient("baeldung") - .secret(passwordEncoder().encode("baeldung")) - .authorizedGrantTypes("client_credentials", "password", "authorization_code") - .scopes("openid", "read") - .autoApprove(true) - .and() - .withClient("baeldung-admin") - .secret(passwordEncoder().encode("baeldung")) - .authorizedGrantTypes("authorization_code", "client_credentials", "refresh_token") - .scopes("read", "write") - .autoApprove(true); - } - - @Bean - public BCryptPasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } -} diff --git a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/WebSecurityConfiguration.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/WebSecurityConfiguration.java deleted file mode 100644 index 3a8c073870..0000000000 --- a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2server/config/WebSecurityConfiguration.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.springbootsecurity.oauth2server.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; - -@Configuration -@Profile("!authz") -public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter { - - @Bean - public AuthenticationManager customAuthenticationManager() throws Exception { - return authenticationManager(); - } -} diff --git a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2sso/SpringBootOAuth2SsoApplication.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2sso/SpringBootOAuth2SsoApplication.java deleted file mode 100644 index 342c246e66..0000000000 --- a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/springbootsecurity/oauth2sso/SpringBootOAuth2SsoApplication.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.springbootsecurity.oauth2sso; - -import org.springframework.boot.autoconfigure.SpringBootApplication; - -import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; -import org.springframework.boot.builder.SpringApplicationBuilder; - -@EnableOAuth2Sso -@SpringBootApplication(scanBasePackages = "com.baeldung.springbootsecurity.oauth2sso") -public class SpringBootOAuth2SsoApplication { - - public static void main(String[] args) { - new SpringApplicationBuilder() - .profiles("sso") - .sources(SpringBootOAuth2SsoApplication.class) - .build() - .run(args); - } -} diff --git a/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/CustomConfigAuthorizationServerIntegrationTest.java b/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/CustomConfigAuthorizationServerIntegrationTest.java deleted file mode 100644 index 104e115b18..0000000000 --- a/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/CustomConfigAuthorizationServerIntegrationTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.baeldung.springbootsecurity.oauth2server; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.security.oauth2.client.OAuth2RestTemplate; -import org.springframework.security.oauth2.client.resource.OAuth2AccessDeniedException; -import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; -import org.springframework.security.oauth2.common.OAuth2AccessToken; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; - -import java.net.URL; -import java.util.regex.Pattern; - -import static java.util.Collections.singletonList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = SpringBootAuthorizationServerApplication.class) -@ActiveProfiles("authz") -public class CustomConfigAuthorizationServerIntegrationTest extends OAuth2IntegrationTestSupport { - - @LocalServerPort - private int port; - - @Before - public void setUp() throws Exception { - base = new URL("http://localhost:" + port); - } - - @Test - public void givenOAuth2Context_whenAccessTokenIsRequested_ThenAccessTokenValueIsNotNull() { - ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails("baeldung", singletonList("read")); - OAuth2RestTemplate restTemplate = getOAuth2RestTemplate(resourceDetails); - - OAuth2AccessToken accessToken = restTemplate.getAccessToken(); - - assertNotNull(accessToken); - } - - @Test - public void givenOAuth2Context_whenAccessingAuthentication_ThenRespondTokenDetails() { - ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails("baeldung", singletonList("read")); - OAuth2RestTemplate restTemplate = getOAuth2RestTemplate(resourceDetails); - - String authentication = executeGetRequest(restTemplate, "/authentication"); - - Pattern pattern = Pattern.compile("\\{\"remoteAddress\":\".*" + - "\",\"sessionId\":null,\"tokenValue\":\".*" + - "\",\"tokenType\":\"Bearer\",\"decodedDetails\":null}"); - assertTrue("authentication", pattern.matcher(authentication).matches()); - } - - @Test - public void givenOAuth2Context_whenAccessingPrincipal_ThenRespondBaeldung() { - ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails("baeldung", singletonList("read")); - OAuth2RestTemplate restTemplate = getOAuth2RestTemplate(resourceDetails); - - String principal = executeGetRequest(restTemplate, "/principal"); - - assertEquals("baeldung", principal); - } - - @Test(expected = OAuth2AccessDeniedException.class) - public void givenOAuth2Context_whenAccessTokenIsRequestedWithInvalidException_ThenExceptionIsThrown() { - ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails("baeldung", singletonList("write")); - OAuth2RestTemplate restTemplate = getOAuth2RestTemplate(resourceDetails); - - restTemplate.getAccessToken(); - } - - @Test - public void givenOAuth2Context_whenAccessTokenIsRequestedByClientWithWriteScope_ThenAccessTokenIsNotNull() { - ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails("baeldung-admin", singletonList("write")); - OAuth2RestTemplate restTemplate = getOAuth2RestTemplate(resourceDetails); - - OAuth2AccessToken accessToken = restTemplate.getAccessToken(); - - assertNotNull(accessToken); - } - -} - diff --git a/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/DefaultConfigAuthorizationServerIntegrationTest.java b/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/DefaultConfigAuthorizationServerIntegrationTest.java deleted file mode 100644 index 4d7b449380..0000000000 --- a/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/DefaultConfigAuthorizationServerIntegrationTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.springbootsecurity.oauth2server; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.security.oauth2.client.OAuth2RestTemplate; -import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; -import org.springframework.security.oauth2.common.OAuth2AccessToken; -import org.springframework.test.context.junit4.SpringRunner; - -import static java.util.Arrays.asList; -import static org.junit.Assert.assertNotNull; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = SpringBootAuthorizationServerApplication.class, - properties = { "security.oauth2.client.client-id=client", "security.oauth2.client.client-secret=baeldung" }) -public class DefaultConfigAuthorizationServerIntegrationTest extends OAuth2IntegrationTestSupport { - - @Test - public void givenOAuth2Context_whenAccessTokenIsRequested_ThenAccessTokenValueIsNotNull() { - ClientCredentialsResourceDetails resourceDetails = getClientCredentialsResourceDetails("client", asList("read", "write")); - OAuth2RestTemplate restTemplate = getOAuth2RestTemplate(resourceDetails); - - OAuth2AccessToken accessToken = restTemplate.getAccessToken(); - - assertNotNull(accessToken); - - } - -} - diff --git a/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/OAuth2IntegrationTestSupport.java b/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/OAuth2IntegrationTestSupport.java deleted file mode 100644 index a005965998..0000000000 --- a/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/springbootsecurity/oauth2server/OAuth2IntegrationTestSupport.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.springbootsecurity.oauth2server; - -import org.apache.commons.io.IOUtils; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; -import org.springframework.security.oauth2.client.OAuth2RestTemplate; -import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; -import org.springframework.web.client.RequestCallback; -import org.springframework.web.client.ResponseExtractor; - -import java.net.URL; -import java.nio.charset.Charset; -import java.util.List; - -import static java.lang.String.format; -import static java.util.Collections.singletonList; -import static org.springframework.http.HttpMethod.GET; - -public class OAuth2IntegrationTestSupport { - - public static final ResponseExtractor EXTRACT_BODY_AS_STRING = clientHttpResponse -> - IOUtils.toString(clientHttpResponse.getBody(), Charset.defaultCharset()); - private static final RequestCallback DO_NOTHING_CALLBACK = request -> { - }; - - @Value("${local.server.port}") - protected int port; - - protected URL base; - - protected ClientCredentialsResourceDetails getClientCredentialsResourceDetails(final String clientId, final List scopes) { - ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails(); - resourceDetails.setAccessTokenUri(format("http://localhost:%d/oauth/token", port)); - resourceDetails.setClientId(clientId); - resourceDetails.setClientSecret("baeldung"); - resourceDetails.setScope(scopes); - resourceDetails.setGrantType("client_credentials"); - return resourceDetails; - } - - protected OAuth2RestTemplate getOAuth2RestTemplate(final ClientCredentialsResourceDetails resourceDetails) { - DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext(); - OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, clientContext); - restTemplate.setMessageConverters(singletonList(new MappingJackson2HttpMessageConverter())); - return restTemplate; - } - - protected String executeGetRequest(OAuth2RestTemplate restTemplate, String path) { - return restTemplate.execute(base.toString() + path, GET, DO_NOTHING_CALLBACK, EXTRACT_BODY_AS_STRING); - } - -} From 972db91cd9b8ceecc45da5044c8273df82e5cc7b Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 18:38:42 +0800 Subject: [PATCH 240/309] Delete README.md --- maven-modules/maven-plugins/maven-enforcer/README.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 maven-modules/maven-plugins/maven-enforcer/README.md diff --git a/maven-modules/maven-plugins/maven-enforcer/README.md b/maven-modules/maven-plugins/maven-enforcer/README.md deleted file mode 100644 index 44d43050e7..0000000000 --- a/maven-modules/maven-plugins/maven-enforcer/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Maven Enforcer Plugin](https://www.baeldung.com/maven-enforcer-plugin) From 9e17f8f8a587884630e83d80ffdaab0232ed5739 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 19:09:19 +0800 Subject: [PATCH 241/309] Update README.md --- apache-cxf/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/apache-cxf/README.md b/apache-cxf/README.md index bedd19a91a..88edaf4e13 100644 --- a/apache-cxf/README.md +++ b/apache-cxf/README.md @@ -7,4 +7,3 @@ This module contains articles about Apache CXF - [Apache CXF Support for RESTful Web Services](https://www.baeldung.com/apache-cxf-rest-api) - [A Guide to Apache CXF with Spring](https://www.baeldung.com/apache-cxf-with-spring) - [Introduction to Apache CXF](https://www.baeldung.com/introduction-to-apache-cxf) -- [Server-Sent Events (SSE) In JAX-RS](https://www.baeldung.com/java-ee-jax-rs-sse) From be2e853fd3437caeb99b2a24ef66bf81d2e90b74 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 19:11:30 +0800 Subject: [PATCH 242/309] Create README.md --- apache-cxf/sse-jaxrs/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 apache-cxf/sse-jaxrs/README.md diff --git a/apache-cxf/sse-jaxrs/README.md b/apache-cxf/sse-jaxrs/README.md new file mode 100644 index 0000000000..4d39560b46 --- /dev/null +++ b/apache-cxf/sse-jaxrs/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Server-Sent Events (SSE) In JAX-RS](https://www.baeldung.com/java-ee-jax-rs-sse) From f130f7fcbfd97272afd4362536d8b0d65d1ac255 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 19:34:04 +0800 Subject: [PATCH 243/309] Update README.md --- persistence-modules/spring-data-elasticsearch/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/persistence-modules/spring-data-elasticsearch/README.md b/persistence-modules/spring-data-elasticsearch/README.md index 9f68a25243..22126c2f00 100644 --- a/persistence-modules/spring-data-elasticsearch/README.md +++ b/persistence-modules/spring-data-elasticsearch/README.md @@ -6,7 +6,6 @@ - [Guide to Elasticsearch in Java](https://www.baeldung.com/elasticsearch-java) - [Geospatial Support in ElasticSearch](https://www.baeldung.com/elasticsearch-geo-spatial) - [A Simple Tagging Implementation with Elasticsearch](https://www.baeldung.com/elasticsearch-tagging) -- [Introduction to Spring Data Elasticsearch (evaluation)](https://www.baeldung.com/spring-data-elasticsearch-test-2) ### Build the Project with Tests Running ``` From 90feaa94ecb838a371571c228bfffb7bdc8b2367 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 19:40:24 +0800 Subject: [PATCH 244/309] Update README.md --- excelformula/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/excelformula/README.md b/excelformula/README.md index 86ddaba413..90826cabee 100644 --- a/excelformula/README.md +++ b/excelformula/README.md @@ -3,6 +3,6 @@ This module contains articles about Apache POI ### Relevant Articles: -- [Working with Microsoft Excel in Java](https://www.baeldung.com/java-microsoft-excel) + - [Read Excel Cell Value Rather Than Formula With Apache POI](https://www.baeldung.com/apache-poi-read-cell-value-formula) - [Upload and Display Excel Files with Spring MVC](https://www.baeldung.com/spring-mvc-excel-files) From 0ec048cf985e1eddad03107cbb8ca7b58451bdfc Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 19:43:49 +0800 Subject: [PATCH 245/309] Update README.md --- excelformula/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/excelformula/README.md b/excelformula/README.md index 90826cabee..a43b3148be 100644 --- a/excelformula/README.md +++ b/excelformula/README.md @@ -4,5 +4,4 @@ This module contains articles about Apache POI ### Relevant Articles: -- [Read Excel Cell Value Rather Than Formula With Apache POI](https://www.baeldung.com/apache-poi-read-cell-value-formula) - [Upload and Display Excel Files with Spring MVC](https://www.baeldung.com/spring-mvc-excel-files) From fae529d8544070adfa0da731d8a80f8767d6bb9a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 19:45:09 +0800 Subject: [PATCH 246/309] Update README.md --- excelformula/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/excelformula/README.md b/excelformula/README.md index a43b3148be..24560525cd 100644 --- a/excelformula/README.md +++ b/excelformula/README.md @@ -3,5 +3,3 @@ This module contains articles about Apache POI ### Relevant Articles: - -- [Upload and Display Excel Files with Spring MVC](https://www.baeldung.com/spring-mvc-excel-files) From 6a662c10dfc573bbd38dbc26eda0710b70c05f8a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 11 Aug 2020 19:49:05 +0800 Subject: [PATCH 247/309] Create README.md --- docker/docker-spring-boot/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docker/docker-spring-boot/README.md diff --git a/docker/docker-spring-boot/README.md b/docker/docker-spring-boot/README.md new file mode 100644 index 0000000000..78f13a3652 --- /dev/null +++ b/docker/docker-spring-boot/README.md @@ -0,0 +1,3 @@ +### Relevant Article: + +- [Creating Docker Images with Spring Boot](https://www.baeldung.com/spring-boot-docker-images) From 96502d8626ad700c89927e3e4efa896d4b332b12 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Tue, 11 Aug 2020 15:09:34 +0200 Subject: [PATCH 248/309] JAVA-2380: Fix failing integration tests in the spring-data-jpa-enterprise --- .../src/main/java/com/baeldung/boot/Application.java | 4 ++-- .../src/main/java/com/baeldung/osiv/model/BasicUser.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/Application.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/Application.java index aaca760499..d9da2c53b6 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/Application.java +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/boot/Application.java @@ -6,8 +6,8 @@ import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @SpringBootApplication -@EnableJpaRepositories("com.baeldung") -@EntityScan("com.baeldung") +@EnableJpaRepositories("com.baeldung.boot") +@EntityScan("com.baeldung.boot") public class Application { public static void main(String[] args) { diff --git a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/model/BasicUser.java b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/model/BasicUser.java index 98f4e379d4..a4f8e4e5f2 100644 --- a/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/model/BasicUser.java +++ b/persistence-modules/spring-data-jpa-enterprise/src/main/java/com/baeldung/osiv/model/BasicUser.java @@ -4,7 +4,7 @@ import javax.persistence.*; import java.util.Set; @Entity -@Table(name = "users") +@Table(name = "basic_users") public class BasicUser { @Id From ded13f14b22653a8448b62b731a28ce22110d912 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Tue, 11 Aug 2020 19:29:46 +0200 Subject: [PATCH 249/309] Feature/bael 4280 diff between lists (#9600) * BAEL-4280: Initial commit for finding diff between lists * BAEL-4280: Format * BAEL-4280: Refactor * BAEL-4280: Refactor not to use private methods * BAEL-4280: Refactor based on editor comments * BAEL-4280: Review round 2 * BAEL-4280: Use assertj * BAEL-4280: Use assertj * BAEL-4280: Shorter names for tests * BAEL-4280: Remove HashSet as its not used anymore * BAEL-4280: Use containsExactlyInAnyOrder for Set example * BAEL-4280: Remove distinct method call * BAEL-4280: Move impl to test * BAEL-4280: Use containsExactlyInAnyOrder * BAEL-4280: Rename test methods --- .../core-java-collections-list-3/pom.xml | 6 ++ .../FindDifferencesBetweenListsUnitTest.java | 96 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/difference/FindDifferencesBetweenListsUnitTest.java diff --git a/core-java-modules/core-java-collections-list-3/pom.xml b/core-java-modules/core-java-collections-list-3/pom.xml index 373190a130..e1cf645c8a 100644 --- a/core-java-modules/core-java-collections-list-3/pom.xml +++ b/core-java-modules/core-java-collections-list-3/pom.xml @@ -21,6 +21,12 @@ commons-collections4 ${commons-collections4.version} + + com.google.guava + guava + ${guava.version} + compile + org.assertj assertj-core diff --git a/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/difference/FindDifferencesBetweenListsUnitTest.java b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/difference/FindDifferencesBetweenListsUnitTest.java new file mode 100644 index 0000000000..ceeff5e442 --- /dev/null +++ b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/difference/FindDifferencesBetweenListsUnitTest.java @@ -0,0 +1,96 @@ +package com.baeldung.list.difference; + +import com.google.common.collect.Sets; +import org.apache.commons.collections4.CollectionUtils; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.*; + +public class FindDifferencesBetweenListsUnitTest { + + private static final List listOne = Arrays.asList("Jack", "Tom", "Sam", "John", "James", "Jack"); + private static final List listTwo = Arrays.asList("Jack", "Daniel", "Sam", "Alan", "James", "George"); + + @Test + public void givenLists_whenUsingPlainJavaImpl_thenDifferencesAreFound() { + List differences = new ArrayList<>(listOne); + differences.removeAll(listTwo); + assertEquals(2, differences.size()); + assertThat(differences).containsExactly("Tom", "John"); + } + + @Test + public void givenReverseLists_whenUsingPlainJavaImpl_thenDifferencesAreFound() { + List differences = new ArrayList<>(listTwo); + differences.removeAll(listOne); + assertEquals(3, differences.size()); + assertThat(differences).containsExactly("Daniel", "Alan", "George"); + } + + @Test + public void givenLists_whenUsingJavaStreams_thenDifferencesAreFound() { + List differences = listOne.stream() + .filter(element -> !listTwo.contains(element)) + .collect(Collectors.toList()); + assertEquals(2, differences.size()); + assertThat(differences).containsExactly("Tom", "John"); + } + + @Test + public void givenReverseLists_whenUsingJavaStreams_thenDifferencesAreFound() { + List differences = listTwo.stream() + .filter(element -> !listOne.contains(element)) + .collect(Collectors.toList()); + assertEquals(3, differences.size()); + assertThat(differences).containsExactly("Daniel", "Alan", "George"); + } + + @Test + public void givenLists_whenUsingGoogleGuava_thenDifferencesAreFound() { + List differences = new ArrayList<>(Sets.difference(Sets.newHashSet(listOne), Sets.newHashSet(listTwo))); + assertEquals(2, differences.size()); + assertThat(differences).containsExactlyInAnyOrder("Tom", "John"); + } + + @Test + public void givenReverseLists_whenUsingGoogleGuava_thenDifferencesAreFound() { + List differences = new ArrayList<>(Sets.difference(Sets.newHashSet(listTwo), Sets.newHashSet(listOne))); + assertEquals(3, differences.size()); + assertThat(differences).containsExactlyInAnyOrder("Daniel", "Alan", "George"); + } + + @Test + public void givenLists_whenUsingApacheCommons_thenDifferencesAreFound() { + List differences = new ArrayList<>((CollectionUtils.removeAll(listOne, listTwo))); + assertEquals(2, differences.size()); + assertThat(differences).containsExactly("Tom", "John"); + } + + @Test + public void givenReverseLists_whenUsingApacheCommons_thenDifferencesAreFound() { + List differences = new ArrayList<>((CollectionUtils.removeAll(listTwo, listOne))); + assertEquals(3, differences.size()); + assertThat(differences).containsExactly("Daniel", "Alan", "George"); + } + + @Test + public void givenLists_whenUsingPlainJavaImpl_thenDifferencesWithDuplicatesAreFound() { + List differences = new ArrayList<>(listOne); + listTwo.forEach(differences::remove); + assertThat(differences).containsExactly("Tom", "John", "Jack"); + } + + @Test + public void givenLists_whenUsingApacheCommons_thenDifferencesWithDuplicatesAreFound() { + List differences = new ArrayList<>(CollectionUtils.subtract(listOne, listTwo)); + assertEquals(3, differences.size()); + assertThat(differences).containsExactly("Tom", "John", "Jack"); + } + +} From 94f50e785ee122b1f31310a5b6f518990841fda6 Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Tue, 11 Aug 2020 22:50:22 +0430 Subject: [PATCH 250/309] ThreadLocals and Thread Pools (#9592) --- .../ThreadLocalAwareThreadPool.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalAwareThreadPool.java diff --git a/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalAwareThreadPool.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalAwareThreadPool.java new file mode 100644 index 0000000000..5a41cd9dbf --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalAwareThreadPool.java @@ -0,0 +1,25 @@ +package com.baeldung.threadlocal; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.RejectedExecutionHandler; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public class ThreadLocalAwareThreadPool extends ThreadPoolExecutor { + + public ThreadLocalAwareThreadPool(int corePoolSize, + int maximumPoolSize, + long keepAliveTime, + TimeUnit unit, + BlockingQueue workQueue, + ThreadFactory threadFactory, + RejectedExecutionHandler handler) { + super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); + } + + @Override + protected void afterExecute(Runnable r, Throwable t) { + // Call remove on each ThreadLocal + } +} From e52c8269680c821a2aa612dee9ab9f67de119588 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Tue, 11 Aug 2020 22:14:45 +0200 Subject: [PATCH 251/309] JAVA-1648: Get rid of the overriden spring-boot.version property in spring-5-security --- spring-5-security/pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/spring-5-security/pom.xml b/spring-5-security/pom.xml index 3fd31c8bc5..c486d5346b 100644 --- a/spring-5-security/pom.xml +++ b/spring-5-security/pom.xml @@ -60,8 +60,5 @@ - - 2.2.1.RELEASE - From 41964ef72e4a54bff1e79ff10592b92838af5f41 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 12 Aug 2020 00:58:10 +0430 Subject: [PATCH 252/309] Fixed the "Comparator and Comparable in Java" Article --- .../java/com/baeldung/comparable/Player.java | 2 +- .../comparator/PlayerAgeComparator.java | 2 +- .../comparator/PlayerRankingComparator.java | 2 +- .../AvoidingSubtractionUnitTest.java | 26 +++++++++++++++++++ .../comparator/Java8ComparatorUnitTest.java | 8 +++--- 5 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/AvoidingSubtractionUnitTest.java diff --git a/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparable/Player.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparable/Player.java index 68a78980f3..74d9a7577e 100644 --- a/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparable/Player.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparable/Player.java @@ -45,7 +45,7 @@ public class Player implements Comparable { @Override public int compareTo(Player otherPlayer) { - return (this.getRanking() - otherPlayer.getRanking()); + return Integer.compare(getRanking(), otherPlayer.getRanking()); } } diff --git a/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeComparator.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeComparator.java index d2e7ca1f42..56e2163f3c 100644 --- a/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeComparator.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerAgeComparator.java @@ -6,7 +6,7 @@ public class PlayerAgeComparator implements Comparator { @Override public int compare(Player firstPlayer, Player secondPlayer) { - return (firstPlayer.getAge() - secondPlayer.getAge()); + return Integer.compare(firstPlayer.getAge(), secondPlayer.getAge()); } } diff --git a/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingComparator.java b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingComparator.java index 2d42698843..56aa38d11a 100644 --- a/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingComparator.java +++ b/core-java-modules/core-java-lang/src/main/java/com/baeldung/comparator/PlayerRankingComparator.java @@ -6,7 +6,7 @@ public class PlayerRankingComparator implements Comparator { @Override public int compare(Player firstPlayer, Player secondPlayer) { - return (firstPlayer.getRanking() - secondPlayer.getRanking()); + return Integer.compare(firstPlayer.getRanking(), secondPlayer.getRanking()); } } diff --git a/core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/AvoidingSubtractionUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/AvoidingSubtractionUnitTest.java new file mode 100644 index 0000000000..fcca743ca1 --- /dev/null +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/AvoidingSubtractionUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.comparator; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class AvoidingSubtractionUnitTest { + + @Test + public void givenTwoPlayers_whenUsingSubtraction_thenOverflow() { + Comparator comparator = (p1, p2) -> p1.getRanking() - p2.getRanking(); + Player player1 = new Player(59, "John", Integer.MAX_VALUE); + Player player2 = new Player(67, "Roger", -1); + + List players = Arrays.asList(player1, player2); + players.sort(comparator); + System.out.println(players); + + assertEquals("John", players.get(0).getName()); + assertEquals("Roger", players.get(1).getName()); + } +} diff --git a/core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/Java8ComparatorUnitTest.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/Java8ComparatorUnitTest.java index 49c8749309..dac05a85b1 100644 --- a/core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/Java8ComparatorUnitTest.java +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/comparator/Java8ComparatorUnitTest.java @@ -1,14 +1,14 @@ package com.baeldung.comparator; -import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.assertEquals; public class Java8ComparatorUnitTest { @@ -28,7 +28,7 @@ public class Java8ComparatorUnitTest { @Test public void whenComparing_UsingLambda_thenSorted() { System.out.println("************** Java 8 Comaparator **************"); - Comparator byRanking = (Player player1, Player player2) -> player1.getRanking() - player2.getRanking(); + Comparator byRanking = (Player player1, Player player2) -> Integer.compare(player1.getRanking(), player2.getRanking()); System.out.println("Before Sorting : " + footballTeam); Collections.sort(footballTeam, byRanking); From e7d3347960fc47ee8e3ceb6ada579aec57d1064c Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 12 Aug 2020 01:41:12 +0430 Subject: [PATCH 253/309] Fixed the "Sorting in Java" Article --- .../collections/sorting/JavaSortingUnitTest.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-collections-2/src/test/java/com/baeldung/collections/sorting/JavaSortingUnitTest.java b/core-java-modules/core-java-collections-2/src/test/java/com/baeldung/collections/sorting/JavaSortingUnitTest.java index 2505adcea7..d474e95cb2 100644 --- a/core-java-modules/core-java-collections-2/src/test/java/com/baeldung/collections/sorting/JavaSortingUnitTest.java +++ b/core-java-modules/core-java-collections-2/src/test/java/com/baeldung/collections/sorting/JavaSortingUnitTest.java @@ -5,7 +5,16 @@ import org.apache.commons.lang3.ArrayUtils; import org.junit.Before; import org.junit.Test; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; import static org.junit.Assert.assertTrue; @@ -138,7 +147,7 @@ public class JavaSortingUnitTest { HashSet descSortedIntegersSet = new LinkedHashSet<>(Arrays.asList(255, 200, 123, 89, 88, 66, 7, 5, 1)); ArrayList list = new ArrayList<>(integersSet); - list.sort((i1, i2) -> i2 - i1); + list.sort(Comparator.reverseOrder()); integersSet = new LinkedHashSet<>(list); assertTrue(Arrays.equals(integersSet.toArray(), descSortedIntegersSet.toArray())); From 1945c8a3124f5d7c7d8a27f976453a934595e015 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 12 Aug 2020 01:50:52 +0430 Subject: [PATCH 254/309] Fixed the "Lambda Sort" Article --- .../src/main/java/com/baeldung/java8/entity/Human.java | 2 +- .../src/test/java/com/baeldung/java8/Java8SortUnitTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/entity/Human.java b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/entity/Human.java index cab8546129..98e35d0af2 100644 --- a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/entity/Human.java +++ b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/entity/Human.java @@ -37,7 +37,7 @@ public class Human { public static int compareByNameThenAge(final Human lhs, final Human rhs) { if (lhs.name.equals(rhs.name)) { - return lhs.age - rhs.age; + return Integer.compare(lhs.age, rhs.age); } else { return lhs.name.compareTo(rhs.name); } diff --git a/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java b/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java index 9e510575fc..e5f876c84b 100644 --- a/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java +++ b/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java @@ -54,7 +54,7 @@ public class Java8SortUnitTest { final List humans = Lists.newArrayList(new Human("Sarah", 12), new Human("Sarah", 10), new Human("Zack", 12)); humans.sort((lhs, rhs) -> { if (lhs.getName().equals(rhs.getName())) { - return lhs.getAge() - rhs.getAge(); + return Integer.compare(lhs.getAge(), rhs.getAge()); } else { return lhs.getName().compareTo(rhs.getName()); } From b532f998db741ffe7200cfee2fdf467bbb4eef57 Mon Sep 17 00:00:00 2001 From: Loredana Date: Wed, 12 Aug 2020 19:32:27 +0300 Subject: [PATCH 255/309] BAEL-4395 fix test --- .../com/baeldung/copydirectory/ApacheCommonsUnitTest.java | 4 ++-- .../test/java/com/baeldung/copydirectory/CoreOldUnitTest.java | 4 ++-- .../test/java/com/baeldung/copydirectory/JavaNioUnitTest.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java index 3486a9af9d..eee49a37d7 100644 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java @@ -16,10 +16,10 @@ import org.junit.jupiter.api.Test; public class ApacheCommonsUnitTest { - private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory"; + private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory3"; private final String subDirectoryName = "/childDirectory"; private final String fileName = "/file.txt"; - private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory"; + private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory3"; @BeforeEach public void createDirectoryWithSubdirectoryAndFile() throws IOException { diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java index 53ae216399..1aaca066a0 100644 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java @@ -16,10 +16,10 @@ import org.junit.jupiter.api.Test; public class CoreOldUnitTest { - private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory"; + private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory1"; private final String subDirectoryName = "/childDirectory"; private final String fileName = "/file.txt"; - private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory"; + private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory1"; @BeforeEach public void createDirectoryWithSubdirectoryAndFile() throws IOException { diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java index 8d1eea53c9..3293e90c0c 100644 --- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java +++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java @@ -16,10 +16,10 @@ import org.junit.jupiter.api.Test; public class JavaNioUnitTest { - private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory"; + private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory2"; private final String subDirectoryName = "/childDirectory"; private final String fileName = "/file.txt"; - private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory"; + private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory2"; @BeforeEach public void createDirectoryWithSubdirectoryAndFile() throws IOException { From dbe203e40aaab48257567e017d664bcda8ff6e5e Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Wed, 12 Aug 2020 19:22:31 +0100 Subject: [PATCH 256/309] BAEL-4321 move to new module and use BDD for test names --- .../java/yamltopojo/demo/DemoApplicationTests.java | 13 ------------- .../spring-boot-data-2}/README.md | 0 .../spring-boot-data-2}/pom.xml | 0 .../main/java/yamltopojo/demo/DemoApplication.java | 0 .../yamltopojo/demo/config/TshirtSizeConfig.java | 0 .../demo/controller/TshirtSizeController.java | 2 +- .../yamltopojo/demo/service/SizeConverterImpl.java | 4 ++-- .../demo/service/SizeConverterService.java | 0 .../src/main/resources/application.yml | 0 .../demo/controller/TshirtSizeControllerTest.java | 4 ++-- 10 files changed, 5 insertions(+), 18 deletions(-) delete mode 100644 configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/DemoApplicationTests.java rename {configuration/yaml-to-pojo => spring-boot-modules/spring-boot-data-2}/README.md (100%) rename {configuration/yaml-to-pojo => spring-boot-modules/spring-boot-data-2}/pom.xml (100%) rename {configuration/yaml-to-pojo => spring-boot-modules/spring-boot-data-2}/src/main/java/yamltopojo/demo/DemoApplication.java (100%) rename {configuration/yaml-to-pojo => spring-boot-modules/spring-boot-data-2}/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java (100%) rename {configuration/yaml-to-pojo => spring-boot-modules/spring-boot-data-2}/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java (93%) rename {configuration/yaml-to-pojo => spring-boot-modules/spring-boot-data-2}/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java (87%) rename {configuration/yaml-to-pojo => spring-boot-modules/spring-boot-data-2}/src/main/java/yamltopojo/demo/service/SizeConverterService.java (100%) rename {configuration/yaml-to-pojo => spring-boot-modules/spring-boot-data-2}/src/main/resources/application.yml (100%) rename {configuration/yaml-to-pojo => spring-boot-modules/spring-boot-data-2}/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java (89%) diff --git a/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/DemoApplicationTests.java b/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/DemoApplicationTests.java deleted file mode 100644 index dfe980c05c..0000000000 --- a/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/DemoApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package yamltopojo.demo; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class DemoApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/configuration/yaml-to-pojo/README.md b/spring-boot-modules/spring-boot-data-2/README.md similarity index 100% rename from configuration/yaml-to-pojo/README.md rename to spring-boot-modules/spring-boot-data-2/README.md diff --git a/configuration/yaml-to-pojo/pom.xml b/spring-boot-modules/spring-boot-data-2/pom.xml similarity index 100% rename from configuration/yaml-to-pojo/pom.xml rename to spring-boot-modules/spring-boot-data-2/pom.xml diff --git a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/DemoApplication.java b/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/DemoApplication.java similarity index 100% rename from configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/DemoApplication.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/DemoApplication.java diff --git a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java similarity index 100% rename from configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java diff --git a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java b/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java similarity index 93% rename from configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java index d555549bd4..3504579504 100644 --- a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java @@ -7,7 +7,7 @@ import yamltopojo.demo.service.SizeConverterService; @RequestMapping(value = "/") public class TshirtSizeController { - private SizeConverterService service; + private final SizeConverterService service; public TshirtSizeController(SizeConverterService service) { this.service = service; diff --git a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java b/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java similarity index 87% rename from configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java index 8f95e4253b..829950433e 100644 --- a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java @@ -7,7 +7,7 @@ import yamltopojo.demo.config.TshirtSizeConfig; @Service public class SizeConverterImpl implements SizeConverterService { - private TshirtSizeConfig tshirtSizeConfig; + private final TshirtSizeConfig tshirtSizeConfig; public SizeConverterImpl(TshirtSizeConfig tshirtSizeConfig) { this.tshirtSizeConfig = tshirtSizeConfig; @@ -17,6 +17,6 @@ public class SizeConverterImpl implements SizeConverterService { if(countryCode == null) { return tshirtSizeConfig.getSimpleMapping().get(label); } - return tshirtSizeConfig.getComplexMapping().get(label).get(countryCode); + return tshirtSizeConfig.getComplexMapping().get(label).get(countryCode.toLowerCase()); } } diff --git a/configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterService.java b/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/service/SizeConverterService.java similarity index 100% rename from configuration/yaml-to-pojo/src/main/java/yamltopojo/demo/service/SizeConverterService.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/service/SizeConverterService.java diff --git a/configuration/yaml-to-pojo/src/main/resources/application.yml b/spring-boot-modules/spring-boot-data-2/src/main/resources/application.yml similarity index 100% rename from configuration/yaml-to-pojo/src/main/resources/application.yml rename to spring-boot-modules/spring-boot-data-2/src/main/resources/application.yml diff --git a/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java similarity index 89% rename from configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java index 3c1ef6dff5..ae92d7d57f 100644 --- a/configuration/yaml-to-pojo/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java +++ b/spring-boot-modules/spring-boot-data-2/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java @@ -20,14 +20,14 @@ class TshirtSizeControllerTest { private TshirtSizeController tested; @Test - void convertSize() { + void givenSizeConverter_whenLabelIsSandCountryCodeIsFr_thenReturnCorrectSize() { // Given String label = "S"; String countryCode = "fr"; int result = 36; - // + // When when(service.convertSize(label, countryCode)).thenReturn(result); int actual = tested.convertSize(label, countryCode); From 986566727c3d4ee908271c5978de246140525e83 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Wed, 12 Aug 2020 21:40:45 +0200 Subject: [PATCH 257/309] JAVA-1640: Get rid of the overriden spring-boot.version property --- spring-5-security-oauth/pom.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml index 40d54bf668..325aacea86 100644 --- a/spring-5-security-oauth/pom.xml +++ b/spring-5-security-oauth/pom.xml @@ -37,7 +37,7 @@ org.springframework.security.oauth.boot spring-security-oauth2-autoconfigure - ${oauth-auto.version} + ${spring-boot.version} org.springframework.security @@ -65,8 +65,6 @@ - 2.1.0.RELEASE - 2.1.0.RELEASE com.baeldung.oauth2.SpringOAuthApplication From 5b3ffa4424ac1af6df151dc6ff77cc6a64dfa4ef Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Wed, 12 Aug 2020 21:16:32 +0100 Subject: [PATCH 258/309] BAEL-4321 correct parent in pom and follow test naming convention --- spring-boot-modules/spring-boot-data-2/pom.xml | 16 ++++++++-------- .../controller/TshirtSizeControllerTest.java | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spring-boot-modules/spring-boot-data-2/pom.xml b/spring-boot-modules/spring-boot-data-2/pom.xml index f6b55718be..0baaf292e8 100644 --- a/spring-boot-modules/spring-boot-data-2/pom.xml +++ b/spring-boot-modules/spring-boot-data-2/pom.xml @@ -3,16 +3,16 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 2.3.2.RELEASE - + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT + ../ - yaml-to-pojo - demo + + spring-boot-data-2 0.0.1-SNAPSHOT - demo - Demo project for YAML into POJO + spring-boot-data-2 + Spring Boot Data Module 1.8 diff --git a/spring-boot-modules/spring-boot-data-2/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java index ae92d7d57f..eb6f896be9 100644 --- a/spring-boot-modules/spring-boot-data-2/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java +++ b/spring-boot-modules/spring-boot-data-2/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java @@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) -class TshirtSizeControllerTest { +class TshirtSizeControllerUnitTest { @Mock private SizeConverterService service; @@ -20,7 +20,7 @@ class TshirtSizeControllerTest { private TshirtSizeController tested; @Test - void givenSizeConverter_whenLabelIsSandCountryCodeIsFr_thenReturnCorrectSize() { + void whenConvertSize_thenOK() { // Given String label = "S"; From 7e1461c40a650964af58464acb27d2b48da11b7c Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Wed, 12 Aug 2020 22:00:11 +0100 Subject: [PATCH 259/309] BAEL-4321 fix package name --- .../demo => com/baeldung/boot/data}/DemoApplication.java | 0 .../demo => com/baeldung/boot/data}/config/TshirtSizeConfig.java | 0 .../baeldung/boot/data}/controller/TshirtSizeController.java | 0 .../baeldung/boot/data}/service/SizeConverterImpl.java | 0 .../baeldung/boot/data}/service/SizeConverterService.java | 0 .../baeldung/boot/data}/controller/TshirtSizeControllerTest.java | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename spring-boot-modules/spring-boot-data-2/src/main/java/{yamltopojo/demo => com/baeldung/boot/data}/DemoApplication.java (100%) rename spring-boot-modules/spring-boot-data-2/src/main/java/{yamltopojo/demo => com/baeldung/boot/data}/config/TshirtSizeConfig.java (100%) rename spring-boot-modules/spring-boot-data-2/src/main/java/{yamltopojo/demo => com/baeldung/boot/data}/controller/TshirtSizeController.java (100%) rename spring-boot-modules/spring-boot-data-2/src/main/java/{yamltopojo/demo => com/baeldung/boot/data}/service/SizeConverterImpl.java (100%) rename spring-boot-modules/spring-boot-data-2/src/main/java/{yamltopojo/demo => com/baeldung/boot/data}/service/SizeConverterService.java (100%) rename spring-boot-modules/spring-boot-data-2/src/test/java/{yamltopojo/demo => com/baeldung/boot/data}/controller/TshirtSizeControllerTest.java (100%) diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/DemoApplication.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/DemoApplication.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/DemoApplication.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/DemoApplication.java diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/config/TshirtSizeConfig.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/config/TshirtSizeConfig.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/config/TshirtSizeConfig.java diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/controller/TshirtSizeController.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/controller/TshirtSizeController.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/controller/TshirtSizeController.java diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterImpl.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/service/SizeConverterImpl.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterImpl.java diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/service/SizeConverterService.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterService.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/java/yamltopojo/demo/service/SizeConverterService.java rename to spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterService.java diff --git a/spring-boot-modules/spring-boot-data-2/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/data/controller/TshirtSizeControllerTest.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/test/java/yamltopojo/demo/controller/TshirtSizeControllerTest.java rename to spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/data/controller/TshirtSizeControllerTest.java From b94d29a1cc57ada0d4ee3fc0ce31aaa70359c3aa Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Thu, 13 Aug 2020 07:19:44 +0100 Subject: [PATCH 260/309] BAEL-4321 fix package name everywhere --- .../src/main/java/com/baeldung/boot/data/DemoApplication.java | 4 ++-- .../java/com/baeldung/boot/data/config/TshirtSizeConfig.java | 2 +- .../baeldung/boot/data/controller/TshirtSizeController.java | 4 ++-- .../com/baeldung/boot/data/service/SizeConverterImpl.java | 4 ++-- .../com/baeldung/boot/data/service/SizeConverterService.java | 2 +- .../boot/data/controller/TshirtSizeControllerTest.java | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/DemoApplication.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/DemoApplication.java index ec8df793c2..125cba6283 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/DemoApplication.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/DemoApplication.java @@ -1,9 +1,9 @@ -package yamltopojo.demo; +package com.baeldung.boot.data; +import com.baeldung.boot.data.config.TshirtSizeConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import yamltopojo.demo.config.TshirtSizeConfig; @SpringBootApplication @EnableConfigurationProperties(TshirtSizeConfig.class) diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/config/TshirtSizeConfig.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/config/TshirtSizeConfig.java index 8f8d2e5b39..000f5b6826 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/config/TshirtSizeConfig.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/config/TshirtSizeConfig.java @@ -1,4 +1,4 @@ -package yamltopojo.demo.config; +package com.baeldung.boot.data.config; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/controller/TshirtSizeController.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/controller/TshirtSizeController.java index 3504579504..6446a17317 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/controller/TshirtSizeController.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/controller/TshirtSizeController.java @@ -1,7 +1,7 @@ -package yamltopojo.demo.controller; +package com.baeldung.boot.data.controller; import org.springframework.web.bind.annotation.*; -import yamltopojo.demo.service.SizeConverterService; +import com.baeldung.boot.data.service.SizeConverterService; @RestController @RequestMapping(value = "/") diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterImpl.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterImpl.java index 829950433e..ccb5a06da4 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterImpl.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterImpl.java @@ -1,7 +1,7 @@ -package yamltopojo.demo.service; +package com.baeldung.boot.data.service; import org.springframework.stereotype.Service; -import yamltopojo.demo.config.TshirtSizeConfig; +import com.baeldung.boot.data.config.TshirtSizeConfig; @Service diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterService.java b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterService.java index 3e24681cbe..91cf2bf0b4 100644 --- a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterService.java +++ b/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterService.java @@ -1,4 +1,4 @@ -package yamltopojo.demo.service; +package com.baeldung.boot.data.service; public interface SizeConverterService { diff --git a/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/data/controller/TshirtSizeControllerTest.java b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/data/controller/TshirtSizeControllerTest.java index eb6f896be9..1d60eb41c0 100644 --- a/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/data/controller/TshirtSizeControllerTest.java +++ b/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/data/controller/TshirtSizeControllerTest.java @@ -1,11 +1,11 @@ -package yamltopojo.demo.controller; +package com.baeldung.boot.data.controller; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import yamltopojo.demo.service.SizeConverterService; +import com.baeldung.boot.data.service.SizeConverterService; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; From 01b61a6bf01dce1fbba137dc77641745919cb0ec Mon Sep 17 00:00:00 2001 From: CHANDRAKANT Kumar Date: Thu, 13 Aug 2020 11:56:49 +0530 Subject: [PATCH 261/309] Adding source code for article tracked under BAEL-4109. --- pom.xml | 2 + spring-webflux-threads/.gitignore | 25 ++++ spring-webflux-threads/README.md | 7 + spring-webflux-threads/pom.xml | 87 ++++++++++++ .../com/baeldung/webflux/Application.java | 13 ++ .../java/com/baeldung/webflux/Controller.java | 128 ++++++++++++++++++ .../java/com/baeldung/webflux/Person.java | 27 ++++ .../baeldung/webflux/PersonRepository.java | 6 + .../src/main/resources/application.yml | 7 + .../src/main/resources/logback.xml | 13 ++ 10 files changed, 315 insertions(+) create mode 100644 spring-webflux-threads/.gitignore create mode 100644 spring-webflux-threads/README.md create mode 100644 spring-webflux-threads/pom.xml create mode 100644 spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java create mode 100644 spring-webflux-threads/src/main/java/com/baeldung/webflux/Controller.java create mode 100644 spring-webflux-threads/src/main/java/com/baeldung/webflux/Person.java create mode 100644 spring-webflux-threads/src/main/java/com/baeldung/webflux/PersonRepository.java create mode 100644 spring-webflux-threads/src/main/resources/application.yml create mode 100644 spring-webflux-threads/src/main/resources/logback.xml diff --git a/pom.xml b/pom.xml index a69ffa2798..3565c2dc4b 100644 --- a/pom.xml +++ b/pom.xml @@ -556,6 +556,7 @@ atomikos reactive-systems slack + spring-webflux-threads @@ -1067,6 +1068,7 @@ atomikos reactive-systems slack + spring-webflux-threads diff --git a/spring-webflux-threads/.gitignore b/spring-webflux-threads/.gitignore new file mode 100644 index 0000000000..82eca336e3 --- /dev/null +++ b/spring-webflux-threads/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/spring-webflux-threads/README.md b/spring-webflux-threads/README.md new file mode 100644 index 0000000000..ab64d897cc --- /dev/null +++ b/spring-webflux-threads/README.md @@ -0,0 +1,7 @@ +## Spring WebFlux Concurrency + +This module contains articles about consurrency model in Spring WebFlux + +### Relevant Articles: + +- [Concurrency in Spring WebFlux]() diff --git a/spring-webflux-threads/pom.xml b/spring-webflux-threads/pom.xml new file mode 100644 index 0000000000..e5b5bafd3b --- /dev/null +++ b/spring-webflux-threads/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + com.baeldung.spring + spring-webflux-threads + 1.0.0-SNAPSHOT + spring-webflux-threads + jar + Spring WebFlux AMQP Sample + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-webflux + + + + + + io.reactivex.rxjava2 + rxjava + 2.2.19 + + + org.springframework.boot + spring-boot-starter-data-mongodb-reactive + + + io.projectreactor.kafka + reactor-kafka + 1.2.2.RELEASE + + + com.fasterxml.jackson.core + jackson-databind + + + org.springframework.boot + spring-boot-starter-test + test + + + io.projectreactor + reactor-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java new file mode 100644 index 0000000000..1dfa00eae0 --- /dev/null +++ b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java @@ -0,0 +1,13 @@ +package com.baeldung.webflux; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/spring-webflux-threads/src/main/java/com/baeldung/webflux/Controller.java b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Controller.java new file mode 100644 index 0000000000..7036deb998 --- /dev/null +++ b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Controller.java @@ -0,0 +1,128 @@ +package com.baeldung.webflux; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.kafka.common.serialization.IntegerDeserializer; +import org.apache.kafka.common.serialization.IntegerSerializer; +import org.apache.kafka.common.serialization.StringDeserializer; +import org.apache.kafka.common.serialization.StringSerializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.reactive.function.client.WebClient; + +import io.reactivex.Observable; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Scheduler; +import reactor.core.scheduler.Schedulers; +import reactor.kafka.receiver.KafkaReceiver; +import reactor.kafka.receiver.ReceiverOptions; +import reactor.kafka.receiver.ReceiverRecord; +import reactor.kafka.sender.KafkaSender; +import reactor.kafka.sender.SenderOptions; +import reactor.kafka.sender.SenderRecord; + +@RestController +@RequestMapping("/") +public class Controller { + + @Autowired + private PersonRepository personRepository; + + private Scheduler scheduler = Schedulers.newBoundedElastic(5, 10, "MyThreadGroup"); + + private Logger logger = LoggerFactory.getLogger(Controller.class); + + @GetMapping("/threads/webflux") + public Flux getThreadsWebflux() { + return Flux.fromIterable(getThreads()); + } + + @GetMapping("/threads/webclient") + public Flux getThreadsWebClient() { + WebClient.create("http://localhost:8080/index") + .get() + .retrieve() + .bodyToMono(String.class) + .subscribeOn(scheduler) + .publishOn(scheduler) + .doOnNext(s -> logger.info("Response: {}", s)) + .subscribe(); + return Flux.fromIterable(getThreads()); + } + + @GetMapping("/threads/rxjava") + public Observable getIndexRxJava() { + Observable.fromIterable(Arrays.asList("Hello", "World")) + .map(s -> s.toUpperCase()) + .observeOn(io.reactivex.schedulers.Schedulers.trampoline()) + .doOnNext(s -> logger.info("String: {}", s)) + .subscribe(); + return Observable.fromIterable(getThreads()); + } + + @GetMapping("/threads/mongodb") + public Flux getIndexMongo() { + personRepository.findAll() + .doOnNext(p -> logger.info("Person: {}", p)) + .subscribe(); + return Flux.fromIterable(getThreads()); + } + + @GetMapping("/thareds/reactor-kafka") + public Flux getIndexKafka() { + Map producerProps = new HashMap<>(); + producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); + producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, IntegerSerializer.class); + producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class); + SenderOptions senderOptions = SenderOptions.create(producerProps); + KafkaSender sender = KafkaSender.create(senderOptions); + Flux> outboundFlux = Flux.range(1, 10) + .map(i -> SenderRecord.create(new ProducerRecord<>("reactive-test", i, "Message_" + i), i)); + sender.send(outboundFlux) + .subscribe(); + + Map consumerProps = new HashMap<>(); + consumerProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); + consumerProps.put(ConsumerConfig.CLIENT_ID_CONFIG, "my-consumer"); + consumerProps.put(ConsumerConfig.GROUP_ID_CONFIG, "my-group"); + consumerProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, IntegerDeserializer.class); + consumerProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); + consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); + ReceiverOptions receiverOptions = ReceiverOptions.create(consumerProps); + receiverOptions.subscription(Collections.singleton("reactive-test")); + KafkaReceiver receiver = KafkaReceiver.create(receiverOptions); + Flux> inboundFlux = receiver.receive(); + inboundFlux.subscribe(r -> { + logger.info("Received message: {}", r.value()); + r.receiverOffset() + .acknowledge(); + }); + return Flux.fromIterable(getThreads()); + } + + @GetMapping("/index") + public Mono getIndex() { + return Mono.just("Hello world!"); + } + + private List getThreads() { + return Thread.getAllStackTraces() + .keySet() + .stream() + .map(t -> String.format("%-20s \t %s \t %d \t %s\n", t.getName(), t.getState(), t.getPriority(), t.isDaemon() ? "Daemon" : "Normal")) + .collect(Collectors.toList()); + } +} diff --git a/spring-webflux-threads/src/main/java/com/baeldung/webflux/Person.java b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Person.java new file mode 100644 index 0000000000..4c6bd5f585 --- /dev/null +++ b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Person.java @@ -0,0 +1,27 @@ +package com.baeldung.webflux; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + +@Document +public class Person { + @Id + String id; + + public Person(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Override + public String toString() { + return "Person{" + "id='" + id + '\'' + '}'; + } +} diff --git a/spring-webflux-threads/src/main/java/com/baeldung/webflux/PersonRepository.java b/spring-webflux-threads/src/main/java/com/baeldung/webflux/PersonRepository.java new file mode 100644 index 0000000000..38fbd3d431 --- /dev/null +++ b/spring-webflux-threads/src/main/java/com/baeldung/webflux/PersonRepository.java @@ -0,0 +1,6 @@ +package com.baeldung.webflux; + +import org.springframework.data.mongodb.repository.ReactiveMongoRepository; + +public interface PersonRepository extends ReactiveMongoRepository { +} diff --git a/spring-webflux-threads/src/main/resources/application.yml b/spring-webflux-threads/src/main/resources/application.yml new file mode 100644 index 0000000000..5addcff6c2 --- /dev/null +++ b/spring-webflux-threads/src/main/resources/application.yml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/spring-webflux-threads/src/main/resources/logback.xml b/spring-webflux-threads/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-webflux-threads/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file From bc2352684ac2aef229726f35a8a70e22175522c7 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Thu, 13 Aug 2020 09:12:53 +0200 Subject: [PATCH 262/309] BAEL-4341 - Add AfterEach annotation instead of BeforeEach on tearDown method --- .../java/com/baeldung/systemout/SystemOutPrintlnUnitTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnUnitTest.java b/testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnUnitTest.java index 3ffc508fa5..549f0ee7b9 100644 --- a/testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnUnitTest.java +++ b/testing-modules/testing-libraries/src/test/java/com/baeldung/systemout/SystemOutPrintlnUnitTest.java @@ -4,6 +4,7 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; import org.junit.Assert; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -19,7 +20,7 @@ class SystemOutPrintlnUnitTest { System.setOut(new PrintStream(outputStreamCaptor)); } - @BeforeEach + @AfterEach public void tearDown() { System.setOut(standardOut); } From 103d36000f726710fea3272164ca2280f8943bc7 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 13 Aug 2020 12:49:18 +0530 Subject: [PATCH 263/309] JAVA-67: renamed spring-security-angular to spring-security-web-angular --- .../README.md | 0 .../client/anguarjs/app.js | 0 .../client/anguarjs/home/home.controller.js | 0 .../client/anguarjs/home/home.view.html | 0 .../client/anguarjs/index.html | 0 .../client/anguarjs/login/login.controller.js | 0 .../client/anguarjs/login/login.view.html | 0 .../client/angular2/app.css | 0 .../client/angular2/app/app.component.html | 0 .../client/angular2/app/app.component.ts | 0 .../client/angular2/app/app.module.ts | 0 .../client/angular2/app/app.routing.ts | 0 .../client/angular2/app/home/home.component.html | 0 .../client/angular2/app/home/home.component.ts | 0 .../client/angular2/app/login/login.component.html | 0 .../client/angular2/app/login/login.component.ts | 0 .../client/angular2/app/main.ts | 0 .../client/angular2/index.html | 0 .../client/angular2/package.json | 0 .../client/angular2/systemjs.config.js | 0 .../client/angular2/tsconfig.json | 0 .../client/angular4/.angular-cli.json | 0 .../client/angular4/package.json | 0 .../client/angular4/src/app/app.component.html | 0 .../client/angular4/src/app/app.component.ts | 0 .../client/angular4/src/app/app.module.ts | 0 .../client/angular4/src/app/app.routing.ts | 0 .../client/angular4/src/app/home/home.component.html | 0 .../client/angular4/src/app/home/home.component.ts | 0 .../client/angular4/src/app/login/login.component.html | 0 .../client/angular4/src/app/login/login.component.ts | 0 .../client/angular4/src/index.html | 0 .../client/angular4/src/main.ts | 0 .../client/angular4/src/polyfills.ts | 0 .../client/angular4/src/styles.css | 0 .../client/angular4/src/tsconfig.app.json | 0 .../client/angular4/tsconfig.json | 0 .../client/angular4/tslint.json | 0 .../client/angular5/.angular-cli.json | 0 .../client/angular5/package.json | 0 .../client/angular5/src/app/app.component.html | 0 .../client/angular5/src/app/app.component.ts | 0 .../client/angular5/src/app/app.module.ts | 0 .../client/angular5/src/app/app.routing.ts | 0 .../client/angular5/src/app/home/home.component.html | 0 .../client/angular5/src/app/home/home.component.ts | 0 .../client/angular5/src/app/login/login.component.html | 0 .../client/angular5/src/app/login/login.component.ts | 0 .../client/angular5/src/index.html | 0 .../client/angular5/src/main.ts | 0 .../client/angular5/src/polyfills.ts | 0 .../client/angular5/src/styles.css | 0 .../client/angular5/src/tsconfig.app.json | 0 .../client/angular5/tsconfig.json | 0 .../client/angular5/tslint.json | 0 .../client/angular6/angular.json | 0 .../client/angular6/package.json | 0 .../client/angular6/src/app/app.component.html | 0 .../client/angular6/src/app/app.component.ts | 0 .../client/angular6/src/app/app.module.ts | 0 .../client/angular6/src/app/app.routing.ts | 0 .../client/angular6/src/app/home/home.component.html | 0 .../client/angular6/src/app/home/home.component.ts | 0 .../client/angular6/src/app/login/login.component.html | 0 .../client/angular6/src/app/login/login.component.ts | 0 .../client/angular6/src/index.html | 0 .../client/angular6/src/main.ts | 0 .../client/angular6/src/polyfills.ts | 0 .../client/angular6/src/styles.css | 0 .../client/angular6/src/tsconfig.app.json | 0 .../client/angular6/tsconfig.json | 0 .../client/angular6/tslint.json | 0 .../server/pom.xml | 0 .../basicauth/SpringBootSecurityApplication.java | 0 .../basicauth/config/BasicAuthConfiguration.java | 0 .../springbootsecurityrest/controller/UserController.java | 0 .../main/java/com/baeldung/springbootsecurityrest/vo/User.java | 0 .../server/src/main/resources/application.properties | 0 .../server/src/main/resources/logback.xml | 0 .../server/src/test/java/com/baeldung/SpringContextTest.java | 0 .../BasicAuthConfigurationIntegrationTest.java | 0 81 files changed, 0 insertions(+), 0 deletions(-) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/README.md (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/anguarjs/app.js (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/anguarjs/home/home.controller.js (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/anguarjs/home/home.view.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/anguarjs/index.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/anguarjs/login/login.controller.js (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/anguarjs/login/login.view.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/app.css (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/app/app.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/app/app.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/app/app.module.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/app/app.routing.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/app/home/home.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/app/home/home.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/app/login/login.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/app/login/login.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/app/main.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/index.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/package.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/systemjs.config.js (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular2/tsconfig.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/.angular-cli.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/package.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/app/app.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/app/app.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/app/app.module.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/app/app.routing.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/app/home/home.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/app/home/home.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/app/login/login.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/app/login/login.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/index.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/main.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/polyfills.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/styles.css (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/src/tsconfig.app.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/tsconfig.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular4/tslint.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/.angular-cli.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/package.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/app/app.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/app/app.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/app/app.module.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/app/app.routing.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/app/home/home.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/app/home/home.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/app/login/login.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/app/login/login.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/index.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/main.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/polyfills.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/styles.css (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/src/tsconfig.app.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/tsconfig.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular5/tslint.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/angular.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/package.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/app/app.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/app/app.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/app/app.module.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/app/app.routing.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/app/home/home.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/app/home/home.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/app/login/login.component.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/app/login/login.component.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/index.html (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/main.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/polyfills.ts (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/styles.css (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/src/tsconfig.app.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/tsconfig.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/client/angular6/tslint.json (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/server/pom.xml (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/SpringBootSecurityApplication.java (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/config/BasicAuthConfiguration.java (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/server/src/main/java/com/baeldung/springbootsecurityrest/controller/UserController.java (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/server/src/main/java/com/baeldung/springbootsecurityrest/vo/User.java (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/server/src/main/resources/application.properties (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/server/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/server/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-angular => spring-security-web-angular}/server/src/test/java/com/baeldung/springbootsecurityrest/BasicAuthConfigurationIntegrationTest.java (100%) diff --git a/spring-security-modules/spring-security-angular/README.md b/spring-security-modules/spring-security-web-angular/README.md similarity index 100% rename from spring-security-modules/spring-security-angular/README.md rename to spring-security-modules/spring-security-web-angular/README.md diff --git a/spring-security-modules/spring-security-angular/client/anguarjs/app.js b/spring-security-modules/spring-security-web-angular/client/anguarjs/app.js similarity index 100% rename from spring-security-modules/spring-security-angular/client/anguarjs/app.js rename to spring-security-modules/spring-security-web-angular/client/anguarjs/app.js diff --git a/spring-security-modules/spring-security-angular/client/anguarjs/home/home.controller.js b/spring-security-modules/spring-security-web-angular/client/anguarjs/home/home.controller.js similarity index 100% rename from spring-security-modules/spring-security-angular/client/anguarjs/home/home.controller.js rename to spring-security-modules/spring-security-web-angular/client/anguarjs/home/home.controller.js diff --git a/spring-security-modules/spring-security-angular/client/anguarjs/home/home.view.html b/spring-security-modules/spring-security-web-angular/client/anguarjs/home/home.view.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/anguarjs/home/home.view.html rename to spring-security-modules/spring-security-web-angular/client/anguarjs/home/home.view.html diff --git a/spring-security-modules/spring-security-angular/client/anguarjs/index.html b/spring-security-modules/spring-security-web-angular/client/anguarjs/index.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/anguarjs/index.html rename to spring-security-modules/spring-security-web-angular/client/anguarjs/index.html diff --git a/spring-security-modules/spring-security-angular/client/anguarjs/login/login.controller.js b/spring-security-modules/spring-security-web-angular/client/anguarjs/login/login.controller.js similarity index 100% rename from spring-security-modules/spring-security-angular/client/anguarjs/login/login.controller.js rename to spring-security-modules/spring-security-web-angular/client/anguarjs/login/login.controller.js diff --git a/spring-security-modules/spring-security-angular/client/anguarjs/login/login.view.html b/spring-security-modules/spring-security-web-angular/client/anguarjs/login/login.view.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/anguarjs/login/login.view.html rename to spring-security-modules/spring-security-web-angular/client/anguarjs/login/login.view.html diff --git a/spring-security-modules/spring-security-angular/client/angular2/app.css b/spring-security-modules/spring-security-web-angular/client/angular2/app.css similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/app.css rename to spring-security-modules/spring-security-web-angular/client/angular2/app.css diff --git a/spring-security-modules/spring-security-angular/client/angular2/app/app.component.html b/spring-security-modules/spring-security-web-angular/client/angular2/app/app.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/app/app.component.html rename to spring-security-modules/spring-security-web-angular/client/angular2/app/app.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular2/app/app.component.ts b/spring-security-modules/spring-security-web-angular/client/angular2/app/app.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/app/app.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular2/app/app.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular2/app/app.module.ts b/spring-security-modules/spring-security-web-angular/client/angular2/app/app.module.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/app/app.module.ts rename to spring-security-modules/spring-security-web-angular/client/angular2/app/app.module.ts diff --git a/spring-security-modules/spring-security-angular/client/angular2/app/app.routing.ts b/spring-security-modules/spring-security-web-angular/client/angular2/app/app.routing.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/app/app.routing.ts rename to spring-security-modules/spring-security-web-angular/client/angular2/app/app.routing.ts diff --git a/spring-security-modules/spring-security-angular/client/angular2/app/home/home.component.html b/spring-security-modules/spring-security-web-angular/client/angular2/app/home/home.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/app/home/home.component.html rename to spring-security-modules/spring-security-web-angular/client/angular2/app/home/home.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular2/app/home/home.component.ts b/spring-security-modules/spring-security-web-angular/client/angular2/app/home/home.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/app/home/home.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular2/app/home/home.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular2/app/login/login.component.html b/spring-security-modules/spring-security-web-angular/client/angular2/app/login/login.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/app/login/login.component.html rename to spring-security-modules/spring-security-web-angular/client/angular2/app/login/login.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular2/app/login/login.component.ts b/spring-security-modules/spring-security-web-angular/client/angular2/app/login/login.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/app/login/login.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular2/app/login/login.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular2/app/main.ts b/spring-security-modules/spring-security-web-angular/client/angular2/app/main.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/app/main.ts rename to spring-security-modules/spring-security-web-angular/client/angular2/app/main.ts diff --git a/spring-security-modules/spring-security-angular/client/angular2/index.html b/spring-security-modules/spring-security-web-angular/client/angular2/index.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/index.html rename to spring-security-modules/spring-security-web-angular/client/angular2/index.html diff --git a/spring-security-modules/spring-security-angular/client/angular2/package.json b/spring-security-modules/spring-security-web-angular/client/angular2/package.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/package.json rename to spring-security-modules/spring-security-web-angular/client/angular2/package.json diff --git a/spring-security-modules/spring-security-angular/client/angular2/systemjs.config.js b/spring-security-modules/spring-security-web-angular/client/angular2/systemjs.config.js similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/systemjs.config.js rename to spring-security-modules/spring-security-web-angular/client/angular2/systemjs.config.js diff --git a/spring-security-modules/spring-security-angular/client/angular2/tsconfig.json b/spring-security-modules/spring-security-web-angular/client/angular2/tsconfig.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular2/tsconfig.json rename to spring-security-modules/spring-security-web-angular/client/angular2/tsconfig.json diff --git a/spring-security-modules/spring-security-angular/client/angular4/.angular-cli.json b/spring-security-modules/spring-security-web-angular/client/angular4/.angular-cli.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/.angular-cli.json rename to spring-security-modules/spring-security-web-angular/client/angular4/.angular-cli.json diff --git a/spring-security-modules/spring-security-angular/client/angular4/package.json b/spring-security-modules/spring-security-web-angular/client/angular4/package.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/package.json rename to spring-security-modules/spring-security-web-angular/client/angular4/package.json diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/app/app.component.html b/spring-security-modules/spring-security-web-angular/client/angular4/src/app/app.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/app/app.component.html rename to spring-security-modules/spring-security-web-angular/client/angular4/src/app/app.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/app/app.component.ts b/spring-security-modules/spring-security-web-angular/client/angular4/src/app/app.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/app/app.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular4/src/app/app.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/app/app.module.ts b/spring-security-modules/spring-security-web-angular/client/angular4/src/app/app.module.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/app/app.module.ts rename to spring-security-modules/spring-security-web-angular/client/angular4/src/app/app.module.ts diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/app/app.routing.ts b/spring-security-modules/spring-security-web-angular/client/angular4/src/app/app.routing.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/app/app.routing.ts rename to spring-security-modules/spring-security-web-angular/client/angular4/src/app/app.routing.ts diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/app/home/home.component.html b/spring-security-modules/spring-security-web-angular/client/angular4/src/app/home/home.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/app/home/home.component.html rename to spring-security-modules/spring-security-web-angular/client/angular4/src/app/home/home.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/app/home/home.component.ts b/spring-security-modules/spring-security-web-angular/client/angular4/src/app/home/home.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/app/home/home.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular4/src/app/home/home.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/app/login/login.component.html b/spring-security-modules/spring-security-web-angular/client/angular4/src/app/login/login.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/app/login/login.component.html rename to spring-security-modules/spring-security-web-angular/client/angular4/src/app/login/login.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/app/login/login.component.ts b/spring-security-modules/spring-security-web-angular/client/angular4/src/app/login/login.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/app/login/login.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular4/src/app/login/login.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/index.html b/spring-security-modules/spring-security-web-angular/client/angular4/src/index.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/index.html rename to spring-security-modules/spring-security-web-angular/client/angular4/src/index.html diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/main.ts b/spring-security-modules/spring-security-web-angular/client/angular4/src/main.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/main.ts rename to spring-security-modules/spring-security-web-angular/client/angular4/src/main.ts diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/polyfills.ts b/spring-security-modules/spring-security-web-angular/client/angular4/src/polyfills.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/polyfills.ts rename to spring-security-modules/spring-security-web-angular/client/angular4/src/polyfills.ts diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/styles.css b/spring-security-modules/spring-security-web-angular/client/angular4/src/styles.css similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/styles.css rename to spring-security-modules/spring-security-web-angular/client/angular4/src/styles.css diff --git a/spring-security-modules/spring-security-angular/client/angular4/src/tsconfig.app.json b/spring-security-modules/spring-security-web-angular/client/angular4/src/tsconfig.app.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/src/tsconfig.app.json rename to spring-security-modules/spring-security-web-angular/client/angular4/src/tsconfig.app.json diff --git a/spring-security-modules/spring-security-angular/client/angular4/tsconfig.json b/spring-security-modules/spring-security-web-angular/client/angular4/tsconfig.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/tsconfig.json rename to spring-security-modules/spring-security-web-angular/client/angular4/tsconfig.json diff --git a/spring-security-modules/spring-security-angular/client/angular4/tslint.json b/spring-security-modules/spring-security-web-angular/client/angular4/tslint.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular4/tslint.json rename to spring-security-modules/spring-security-web-angular/client/angular4/tslint.json diff --git a/spring-security-modules/spring-security-angular/client/angular5/.angular-cli.json b/spring-security-modules/spring-security-web-angular/client/angular5/.angular-cli.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/.angular-cli.json rename to spring-security-modules/spring-security-web-angular/client/angular5/.angular-cli.json diff --git a/spring-security-modules/spring-security-angular/client/angular5/package.json b/spring-security-modules/spring-security-web-angular/client/angular5/package.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/package.json rename to spring-security-modules/spring-security-web-angular/client/angular5/package.json diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/app/app.component.html b/spring-security-modules/spring-security-web-angular/client/angular5/src/app/app.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/app/app.component.html rename to spring-security-modules/spring-security-web-angular/client/angular5/src/app/app.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/app/app.component.ts b/spring-security-modules/spring-security-web-angular/client/angular5/src/app/app.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/app/app.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular5/src/app/app.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/app/app.module.ts b/spring-security-modules/spring-security-web-angular/client/angular5/src/app/app.module.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/app/app.module.ts rename to spring-security-modules/spring-security-web-angular/client/angular5/src/app/app.module.ts diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/app/app.routing.ts b/spring-security-modules/spring-security-web-angular/client/angular5/src/app/app.routing.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/app/app.routing.ts rename to spring-security-modules/spring-security-web-angular/client/angular5/src/app/app.routing.ts diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/app/home/home.component.html b/spring-security-modules/spring-security-web-angular/client/angular5/src/app/home/home.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/app/home/home.component.html rename to spring-security-modules/spring-security-web-angular/client/angular5/src/app/home/home.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/app/home/home.component.ts b/spring-security-modules/spring-security-web-angular/client/angular5/src/app/home/home.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/app/home/home.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular5/src/app/home/home.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/app/login/login.component.html b/spring-security-modules/spring-security-web-angular/client/angular5/src/app/login/login.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/app/login/login.component.html rename to spring-security-modules/spring-security-web-angular/client/angular5/src/app/login/login.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/app/login/login.component.ts b/spring-security-modules/spring-security-web-angular/client/angular5/src/app/login/login.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/app/login/login.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular5/src/app/login/login.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/index.html b/spring-security-modules/spring-security-web-angular/client/angular5/src/index.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/index.html rename to spring-security-modules/spring-security-web-angular/client/angular5/src/index.html diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/main.ts b/spring-security-modules/spring-security-web-angular/client/angular5/src/main.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/main.ts rename to spring-security-modules/spring-security-web-angular/client/angular5/src/main.ts diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/polyfills.ts b/spring-security-modules/spring-security-web-angular/client/angular5/src/polyfills.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/polyfills.ts rename to spring-security-modules/spring-security-web-angular/client/angular5/src/polyfills.ts diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/styles.css b/spring-security-modules/spring-security-web-angular/client/angular5/src/styles.css similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/styles.css rename to spring-security-modules/spring-security-web-angular/client/angular5/src/styles.css diff --git a/spring-security-modules/spring-security-angular/client/angular5/src/tsconfig.app.json b/spring-security-modules/spring-security-web-angular/client/angular5/src/tsconfig.app.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/src/tsconfig.app.json rename to spring-security-modules/spring-security-web-angular/client/angular5/src/tsconfig.app.json diff --git a/spring-security-modules/spring-security-angular/client/angular5/tsconfig.json b/spring-security-modules/spring-security-web-angular/client/angular5/tsconfig.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/tsconfig.json rename to spring-security-modules/spring-security-web-angular/client/angular5/tsconfig.json diff --git a/spring-security-modules/spring-security-angular/client/angular5/tslint.json b/spring-security-modules/spring-security-web-angular/client/angular5/tslint.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular5/tslint.json rename to spring-security-modules/spring-security-web-angular/client/angular5/tslint.json diff --git a/spring-security-modules/spring-security-angular/client/angular6/angular.json b/spring-security-modules/spring-security-web-angular/client/angular6/angular.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/angular.json rename to spring-security-modules/spring-security-web-angular/client/angular6/angular.json diff --git a/spring-security-modules/spring-security-angular/client/angular6/package.json b/spring-security-modules/spring-security-web-angular/client/angular6/package.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/package.json rename to spring-security-modules/spring-security-web-angular/client/angular6/package.json diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/app/app.component.html b/spring-security-modules/spring-security-web-angular/client/angular6/src/app/app.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/app/app.component.html rename to spring-security-modules/spring-security-web-angular/client/angular6/src/app/app.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/app/app.component.ts b/spring-security-modules/spring-security-web-angular/client/angular6/src/app/app.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/app/app.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular6/src/app/app.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/app/app.module.ts b/spring-security-modules/spring-security-web-angular/client/angular6/src/app/app.module.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/app/app.module.ts rename to spring-security-modules/spring-security-web-angular/client/angular6/src/app/app.module.ts diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/app/app.routing.ts b/spring-security-modules/spring-security-web-angular/client/angular6/src/app/app.routing.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/app/app.routing.ts rename to spring-security-modules/spring-security-web-angular/client/angular6/src/app/app.routing.ts diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/app/home/home.component.html b/spring-security-modules/spring-security-web-angular/client/angular6/src/app/home/home.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/app/home/home.component.html rename to spring-security-modules/spring-security-web-angular/client/angular6/src/app/home/home.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/app/home/home.component.ts b/spring-security-modules/spring-security-web-angular/client/angular6/src/app/home/home.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/app/home/home.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular6/src/app/home/home.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/app/login/login.component.html b/spring-security-modules/spring-security-web-angular/client/angular6/src/app/login/login.component.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/app/login/login.component.html rename to spring-security-modules/spring-security-web-angular/client/angular6/src/app/login/login.component.html diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/app/login/login.component.ts b/spring-security-modules/spring-security-web-angular/client/angular6/src/app/login/login.component.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/app/login/login.component.ts rename to spring-security-modules/spring-security-web-angular/client/angular6/src/app/login/login.component.ts diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/index.html b/spring-security-modules/spring-security-web-angular/client/angular6/src/index.html similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/index.html rename to spring-security-modules/spring-security-web-angular/client/angular6/src/index.html diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/main.ts b/spring-security-modules/spring-security-web-angular/client/angular6/src/main.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/main.ts rename to spring-security-modules/spring-security-web-angular/client/angular6/src/main.ts diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/polyfills.ts b/spring-security-modules/spring-security-web-angular/client/angular6/src/polyfills.ts similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/polyfills.ts rename to spring-security-modules/spring-security-web-angular/client/angular6/src/polyfills.ts diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/styles.css b/spring-security-modules/spring-security-web-angular/client/angular6/src/styles.css similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/styles.css rename to spring-security-modules/spring-security-web-angular/client/angular6/src/styles.css diff --git a/spring-security-modules/spring-security-angular/client/angular6/src/tsconfig.app.json b/spring-security-modules/spring-security-web-angular/client/angular6/src/tsconfig.app.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/src/tsconfig.app.json rename to spring-security-modules/spring-security-web-angular/client/angular6/src/tsconfig.app.json diff --git a/spring-security-modules/spring-security-angular/client/angular6/tsconfig.json b/spring-security-modules/spring-security-web-angular/client/angular6/tsconfig.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/tsconfig.json rename to spring-security-modules/spring-security-web-angular/client/angular6/tsconfig.json diff --git a/spring-security-modules/spring-security-angular/client/angular6/tslint.json b/spring-security-modules/spring-security-web-angular/client/angular6/tslint.json similarity index 100% rename from spring-security-modules/spring-security-angular/client/angular6/tslint.json rename to spring-security-modules/spring-security-web-angular/client/angular6/tslint.json diff --git a/spring-security-modules/spring-security-angular/server/pom.xml b/spring-security-modules/spring-security-web-angular/server/pom.xml similarity index 100% rename from spring-security-modules/spring-security-angular/server/pom.xml rename to spring-security-modules/spring-security-web-angular/server/pom.xml diff --git a/spring-security-modules/spring-security-angular/server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/SpringBootSecurityApplication.java b/spring-security-modules/spring-security-web-angular/server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/SpringBootSecurityApplication.java similarity index 100% rename from spring-security-modules/spring-security-angular/server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/SpringBootSecurityApplication.java rename to spring-security-modules/spring-security-web-angular/server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/SpringBootSecurityApplication.java diff --git a/spring-security-modules/spring-security-angular/server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/config/BasicAuthConfiguration.java b/spring-security-modules/spring-security-web-angular/server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/config/BasicAuthConfiguration.java similarity index 100% rename from spring-security-modules/spring-security-angular/server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/config/BasicAuthConfiguration.java rename to spring-security-modules/spring-security-web-angular/server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/config/BasicAuthConfiguration.java diff --git a/spring-security-modules/spring-security-angular/server/src/main/java/com/baeldung/springbootsecurityrest/controller/UserController.java b/spring-security-modules/spring-security-web-angular/server/src/main/java/com/baeldung/springbootsecurityrest/controller/UserController.java similarity index 100% rename from spring-security-modules/spring-security-angular/server/src/main/java/com/baeldung/springbootsecurityrest/controller/UserController.java rename to spring-security-modules/spring-security-web-angular/server/src/main/java/com/baeldung/springbootsecurityrest/controller/UserController.java diff --git a/spring-security-modules/spring-security-angular/server/src/main/java/com/baeldung/springbootsecurityrest/vo/User.java b/spring-security-modules/spring-security-web-angular/server/src/main/java/com/baeldung/springbootsecurityrest/vo/User.java similarity index 100% rename from spring-security-modules/spring-security-angular/server/src/main/java/com/baeldung/springbootsecurityrest/vo/User.java rename to spring-security-modules/spring-security-web-angular/server/src/main/java/com/baeldung/springbootsecurityrest/vo/User.java diff --git a/spring-security-modules/spring-security-angular/server/src/main/resources/application.properties b/spring-security-modules/spring-security-web-angular/server/src/main/resources/application.properties similarity index 100% rename from spring-security-modules/spring-security-angular/server/src/main/resources/application.properties rename to spring-security-modules/spring-security-web-angular/server/src/main/resources/application.properties diff --git a/spring-security-modules/spring-security-angular/server/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-angular/server/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-angular/server/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-angular/server/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-angular/server/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-web-angular/server/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-angular/server/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-web-angular/server/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/spring-security-angular/server/src/test/java/com/baeldung/springbootsecurityrest/BasicAuthConfigurationIntegrationTest.java b/spring-security-modules/spring-security-web-angular/server/src/test/java/com/baeldung/springbootsecurityrest/BasicAuthConfigurationIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-angular/server/src/test/java/com/baeldung/springbootsecurityrest/BasicAuthConfigurationIntegrationTest.java rename to spring-security-modules/spring-security-web-angular/server/src/test/java/com/baeldung/springbootsecurityrest/BasicAuthConfigurationIntegrationTest.java From 36a2c6edb1ac65222ee6c1fded19c34357f6f57c Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 13 Aug 2020 12:51:16 +0530 Subject: [PATCH 264/309] JAVA-67: renamed spring-security-mvc to spring-security-web-mvc --- .../.gitignore | 0 .../README.md | 0 .../{spring-security-mvc => spring-security-web-mvc}/pom.xml | 4 ++-- .../baeldung/clearsitedata/LogoutClearSiteDataController.java | 0 .../java/com/baeldung/clearsitedata/SpringSecurityConfig.java | 0 .../src/main/java/com/baeldung/clearsitedata/WebConfig.java | 0 .../java/com/baeldung/monitoring/MetricRegistrySingleton.java | 0 .../security/MySimpleUrlAuthenticationSuccessHandler.java | 0 .../java/com/baeldung/session/SpringSessionApplication.java | 0 .../src/main/java/com/baeldung/session/bean/Constants.java | 0 .../src/main/java/com/baeldung/session/bean/Foo.java | 0 .../main/java/com/baeldung/session/filter/SessionFilter.java | 0 .../baeldung/session/security/config/SecSecurityConfig.java | 0 .../src/main/java/com/baeldung/session/web/FooController.java | 0 .../java/com/baeldung/session/web/SessionRestController.java | 0 .../baeldung/session/web/config/MainWebAppInitializer.java | 0 .../main/java/com/baeldung/session/web/config/MvcConfig.java | 0 .../java/com/baeldung/web/SessionListenerWithMetrics.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/webSecurityConfig.xml | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/anonymous.jsp | 0 .../src/main/webapp/WEB-INF/view/console.jsp | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/view/invalidSession.jsp | 0 .../src/main/webapp/WEB-INF/view/login.jsp | 0 .../src/main/webapp/WEB-INF/view/sessionExpired.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../clearsitedata/LogoutClearSiteDataControllerUnitTest.java | 0 .../com/baeldung/session/SessionConfigurationLiveTest.java | 0 .../src/test/resources/.gitignore | 0 33 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/.gitignore (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/README.md (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/pom.xml (97%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/clearsitedata/LogoutClearSiteDataController.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/clearsitedata/SpringSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/clearsitedata/WebConfig.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/monitoring/MetricRegistrySingleton.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/session/SpringSessionApplication.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/session/bean/Constants.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/session/bean/Foo.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/session/filter/SessionFilter.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/session/security/config/SecSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/session/web/FooController.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/session/web/SessionRestController.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/session/web/config/MainWebAppInitializer.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/session/web/config/MvcConfig.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/java/com/baeldung/web/SessionListenerWithMetrics.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/resources/application.properties (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/resources/webSecurityConfig.xml (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/webapp/WEB-INF/view/anonymous.jsp (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/webapp/WEB-INF/view/console.jsp (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/webapp/WEB-INF/view/invalidSession.jsp (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/webapp/WEB-INF/view/login.jsp (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/webapp/WEB-INF/view/sessionExpired.jsp (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/main/webapp/WEB-INF/web.xml (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/test/java/com/baeldung/clearsitedata/LogoutClearSiteDataControllerUnitTest.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/test/java/com/baeldung/session/SessionConfigurationLiveTest.java (100%) rename spring-security-modules/{spring-security-mvc => spring-security-web-mvc}/src/test/resources/.gitignore (100%) diff --git a/spring-security-modules/spring-security-mvc/.gitignore b/spring-security-modules/spring-security-web-mvc/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc/.gitignore rename to spring-security-modules/spring-security-web-mvc/.gitignore diff --git a/spring-security-modules/spring-security-mvc/README.md b/spring-security-modules/spring-security-web-mvc/README.md similarity index 100% rename from spring-security-modules/spring-security-mvc/README.md rename to spring-security-modules/spring-security-web-mvc/README.md diff --git a/spring-security-modules/spring-security-mvc/pom.xml b/spring-security-modules/spring-security-web-mvc/pom.xml similarity index 97% rename from spring-security-modules/spring-security-mvc/pom.xml rename to spring-security-modules/spring-security-web-mvc/pom.xml index d97825975f..2651b3a0f2 100644 --- a/spring-security-modules/spring-security-mvc/pom.xml +++ b/spring-security-modules/spring-security-web-mvc/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-security-mvc + spring-security-web-mvc 0.1-SNAPSHOT - spring-security-mvc + spring-security-web-mvc jar diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/LogoutClearSiteDataController.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/clearsitedata/LogoutClearSiteDataController.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/LogoutClearSiteDataController.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/clearsitedata/LogoutClearSiteDataController.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/SpringSecurityConfig.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/clearsitedata/SpringSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/SpringSecurityConfig.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/clearsitedata/SpringSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/WebConfig.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/clearsitedata/WebConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/WebConfig.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/clearsitedata/WebConfig.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/monitoring/MetricRegistrySingleton.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/monitoring/MetricRegistrySingleton.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/monitoring/MetricRegistrySingleton.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/monitoring/MetricRegistrySingleton.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/SpringSessionApplication.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/SpringSessionApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/SpringSessionApplication.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/SpringSessionApplication.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/bean/Constants.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/bean/Constants.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/bean/Constants.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/bean/Constants.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/bean/Foo.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/bean/Foo.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/bean/Foo.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/bean/Foo.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/filter/SessionFilter.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/filter/SessionFilter.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/filter/SessionFilter.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/filter/SessionFilter.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/security/config/SecSecurityConfig.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/security/config/SecSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/security/config/SecSecurityConfig.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/security/config/SecSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/web/FooController.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/web/FooController.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/web/FooController.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/web/FooController.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/web/SessionRestController.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/web/SessionRestController.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/web/SessionRestController.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/web/SessionRestController.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/web/config/MainWebAppInitializer.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/web/config/MainWebAppInitializer.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/web/config/MainWebAppInitializer.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/web/config/MainWebAppInitializer.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/web/config/MvcConfig.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/web/config/MvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/session/web/config/MvcConfig.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/session/web/config/MvcConfig.java diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/web/SessionListenerWithMetrics.java b/spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/web/SessionListenerWithMetrics.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/web/SessionListenerWithMetrics.java rename to spring-security-modules/spring-security-web-mvc/src/main/java/com/baeldung/web/SessionListenerWithMetrics.java diff --git a/spring-security-modules/spring-security-mvc/src/main/resources/application.properties b/spring-security-modules/spring-security-web-mvc/src/main/resources/application.properties similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/resources/application.properties rename to spring-security-modules/spring-security-web-mvc/src/main/resources/application.properties diff --git a/spring-security-modules/spring-security-mvc/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-mvc/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-mvc/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-mvc/src/main/resources/webSecurityConfig.xml b/spring-security-modules/spring-security-web-mvc/src/main/resources/webSecurityConfig.xml similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/resources/webSecurityConfig.xml rename to spring-security-modules/spring-security-web-mvc/src/main/resources/webSecurityConfig.xml diff --git a/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/anonymous.jsp b/spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/anonymous.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/anonymous.jsp rename to spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/anonymous.jsp diff --git a/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/console.jsp b/spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/console.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/console.jsp rename to spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/console.jsp diff --git a/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/invalidSession.jsp b/spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/invalidSession.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/invalidSession.jsp rename to spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/invalidSession.jsp diff --git a/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/login.jsp b/spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/login.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/login.jsp rename to spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/login.jsp diff --git a/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/sessionExpired.jsp b/spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/sessionExpired.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/view/sessionExpired.jsp rename to spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/view/sessionExpired.jsp diff --git a/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/web.xml rename to spring-security-modules/spring-security-web-mvc/src/main/webapp/WEB-INF/web.xml diff --git a/spring-security-modules/spring-security-mvc/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-web-mvc/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-web-mvc/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/spring-security-mvc/src/test/java/com/baeldung/clearsitedata/LogoutClearSiteDataControllerUnitTest.java b/spring-security-modules/spring-security-web-mvc/src/test/java/com/baeldung/clearsitedata/LogoutClearSiteDataControllerUnitTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/test/java/com/baeldung/clearsitedata/LogoutClearSiteDataControllerUnitTest.java rename to spring-security-modules/spring-security-web-mvc/src/test/java/com/baeldung/clearsitedata/LogoutClearSiteDataControllerUnitTest.java diff --git a/spring-security-modules/spring-security-mvc/src/test/java/com/baeldung/session/SessionConfigurationLiveTest.java b/spring-security-modules/spring-security-web-mvc/src/test/java/com/baeldung/session/SessionConfigurationLiveTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc/src/test/java/com/baeldung/session/SessionConfigurationLiveTest.java rename to spring-security-modules/spring-security-web-mvc/src/test/java/com/baeldung/session/SessionConfigurationLiveTest.java diff --git a/spring-security-modules/spring-security-mvc/src/test/resources/.gitignore b/spring-security-modules/spring-security-web-mvc/src/test/resources/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc/src/test/resources/.gitignore rename to spring-security-modules/spring-security-web-mvc/src/test/resources/.gitignore From 787bbd4f2c5e6d2213ca276a7c95d31c80cef48f Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 13 Aug 2020 12:52:53 +0530 Subject: [PATCH 265/309] JAVA-67:renamed spring-security-mvc-boot-1 to spring-security-web-boot-1 --- .../README.md | 0 .../WebContent/META-INF/MANIFEST.MF | 0 .../pom.xml | 4 ++-- .../src/main/java/com/baeldung/relationships/AppConfig.java | 0 .../java/com/baeldung/relationships/SpringSecurityConfig.java | 0 .../main/java/com/baeldung/relationships/models/AppUser.java | 0 .../main/java/com/baeldung/relationships/models/Tweet.java | 0 .../baeldung/relationships/repositories/TweetRepository.java | 0 .../baeldung/relationships/repositories/UserRepository.java | 0 .../com/baeldung/relationships/security/AppUserPrincipal.java | 0 .../security/AuthenticationSuccessHandlerImpl.java | 0 .../relationships/security/CustomUserDetailsService.java | 0 .../com/baeldung/relationships/util/DummyContentUtil.java | 0 .../src/main/java/com/baeldung/roles/custom/Application.java | 0 .../baeldung/roles/custom/config/MethodSecurityConfig.java | 0 .../main/java/com/baeldung/roles/custom/config/MvcConfig.java | 0 .../java/com/baeldung/roles/custom/config/SecurityConfig.java | 0 .../java/com/baeldung/roles/custom/persistence/SetupData.java | 0 .../roles/custom/persistence/dao/OrganizationRepository.java | 0 .../roles/custom/persistence/dao/PrivilegeRepository.java | 0 .../baeldung/roles/custom/persistence/dao/UserRepository.java | 0 .../java/com/baeldung/roles/custom/persistence/model/Foo.java | 0 .../baeldung/roles/custom/persistence/model/Organization.java | 0 .../baeldung/roles/custom/persistence/model/Privilege.java | 0 .../com/baeldung/roles/custom/persistence/model/User.java | 0 .../security/CustomMethodSecurityExpressionHandler.java | 0 .../custom/security/CustomMethodSecurityExpressionRoot.java | 0 .../roles/custom/security/CustomPermissionEvaluator.java | 0 .../roles/custom/security/MySecurityExpressionRoot.java | 0 .../baeldung/roles/custom/security/MyUserDetailsService.java | 0 .../com/baeldung/roles/custom/security/MyUserPrincipal.java | 0 .../java/com/baeldung/roles/custom/web/MainController.java | 0 .../src/main/java/com/baeldung/roles/ip/IpApplication.java | 0 .../roles/ip/config/CustomIpAuthenticationProvider.java | 0 .../java/com/baeldung/roles/ip/config/SecurityConfig.java | 0 .../java/com/baeldung/roles/ip/config/SecurityXmlConfig.java | 0 .../main/java/com/baeldung/roles/ip/web/MainController.java | 0 .../roles/rolesauthorities/CustomAuthenticationProvider.java | 0 .../roles/rolesauthorities/MyLogoutSuccessHandler.java | 0 .../baeldung/roles/rolesauthorities/MyUserDetailsService.java | 0 .../roles/rolesauthorities/RolesAuthoritiesApplication.java | 0 .../com/baeldung/roles/rolesauthorities/config/MvcConfig.java | 0 .../roles/rolesauthorities/config/SecurityConfig.java | 0 .../com/baeldung/roles/rolesauthorities/model/Privilege.java | 0 .../java/com/baeldung/roles/rolesauthorities/model/Role.java | 0 .../java/com/baeldung/roles/rolesauthorities/model/User.java | 0 .../roles/rolesauthorities/persistence/IUserService.java | 0 .../rolesauthorities/persistence/PrivilegeRepository.java | 0 .../roles/rolesauthorities/persistence/RoleRepository.java | 0 .../roles/rolesauthorities/persistence/SetupDataLoader.java | 0 .../roles/rolesauthorities/persistence/UserRepository.java | 0 .../roles/rolesauthorities/persistence/UserService.java | 0 .../main/java/com/baeldung/roles/voter/MinuteBasedVoter.java | 0 .../main/java/com/baeldung/roles/voter/VoterApplication.java | 0 .../main/java/com/baeldung/roles/voter/VoterMvcConfig.java | 0 .../main/java/com/baeldung/roles/voter/WebSecurityConfig.java | 0 .../main/java/com/baeldung/roles/voter/XmlSecurityConfig.java | 0 .../src/main/resources/application-defaults.properties | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/persistence-h2.properties | 0 .../src/main/resources/spring-security-custom-voter.xml | 0 .../src/main/resources/spring-security-ip.xml | 0 .../src/main/resources/templates/403.html | 0 .../src/main/resources/templates/index.html | 0 .../src/main/resources/templates/login.html | 0 .../src/main/resources/templates/loginAdmin.html | 0 .../src/main/resources/templates/loginUser.html | 0 .../src/main/resources/templates/multipleHttpElems/login.html | 0 .../templates/multipleHttpElems/loginWithWarning.html | 0 .../templates/multipleHttpElems/multipleHttpLinks.html | 0 .../resources/templates/multipleHttpElems/myAdminPage.html | 0 .../resources/templates/multipleHttpElems/myGuestPage.html | 0 .../templates/multipleHttpElems/myPrivateUserPage.html | 0 .../resources/templates/multipleHttpElems/myUserPage.html | 0 .../src/main/resources/templates/private.html | 0 .../src/main/resources/templates/rolesauthorities/home.html | 0 .../src/main/resources/templates/rolesauthorities/login.html | 0 .../templates/rolesauthorities/protectedbyauthority.html | 0 .../templates/rolesauthorities/protectedbynothing.html | 0 .../resources/templates/rolesauthorities/protectedbyrole.html | 0 .../src/main/resources/templates/ssl/welcome.html | 0 .../relationships/SpringDataWithSecurityIntegrationTest.java | 0 .../src/test/java/com/baeldung/roles/SpringContextTest.java | 0 .../test/java/com/baeldung/roles/web/ApplicationLiveTest.java | 0 .../roles/web/CustomUserDetailsServiceIntegrationTest.java | 0 .../src/test/java/com/baeldung/roles/web/IpLiveTest.java | 0 87 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/README.md (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/WebContent/META-INF/MANIFEST.MF (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/pom.xml (98%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/relationships/AppConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/relationships/SpringSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/relationships/models/AppUser.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/relationships/models/Tweet.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/relationships/repositories/TweetRepository.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/relationships/repositories/UserRepository.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/relationships/security/AppUserPrincipal.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/relationships/security/AuthenticationSuccessHandlerImpl.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/relationships/security/CustomUserDetailsService.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/relationships/util/DummyContentUtil.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/Application.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/config/MethodSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/config/MvcConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/config/SecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/persistence/SetupData.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/persistence/dao/OrganizationRepository.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/persistence/dao/PrivilegeRepository.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/persistence/dao/UserRepository.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/persistence/model/Foo.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/persistence/model/Organization.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/persistence/model/Privilege.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/persistence/model/User.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionHandler.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionRoot.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/security/CustomPermissionEvaluator.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/security/MySecurityExpressionRoot.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/security/MyUserDetailsService.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/security/MyUserPrincipal.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/custom/web/MainController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/ip/IpApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/ip/config/CustomIpAuthenticationProvider.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/ip/config/SecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/ip/config/SecurityXmlConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/ip/web/MainController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/CustomAuthenticationProvider.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/MyLogoutSuccessHandler.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/MyUserDetailsService.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/RolesAuthoritiesApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/config/MvcConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/config/SecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/model/Privilege.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/model/Role.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/model/User.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/persistence/IUserService.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/persistence/PrivilegeRepository.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/persistence/RoleRepository.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/persistence/SetupDataLoader.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserRepository.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserService.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/voter/MinuteBasedVoter.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/voter/VoterApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/voter/VoterMvcConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/voter/WebSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/java/com/baeldung/roles/voter/XmlSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/application-defaults.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/application.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/persistence-h2.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/spring-security-custom-voter.xml (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/spring-security-ip.xml (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/403.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/index.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/login.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/loginAdmin.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/loginUser.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/multipleHttpElems/login.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/multipleHttpElems/loginWithWarning.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/multipleHttpElems/multipleHttpLinks.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/multipleHttpElems/myAdminPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/multipleHttpElems/myGuestPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/multipleHttpElems/myPrivateUserPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/multipleHttpElems/myUserPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/private.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/rolesauthorities/home.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/rolesauthorities/login.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/rolesauthorities/protectedbyauthority.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/rolesauthorities/protectedbynothing.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/rolesauthorities/protectedbyrole.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/main/resources/templates/ssl/welcome.html (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/test/java/com/baeldung/relationships/SpringDataWithSecurityIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/test/java/com/baeldung/roles/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/test/java/com/baeldung/roles/web/ApplicationLiveTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/test/java/com/baeldung/roles/web/CustomUserDetailsServiceIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-1 => spring-security-web-boot-1}/src/test/java/com/baeldung/roles/web/IpLiveTest.java (100%) diff --git a/spring-security-modules/spring-security-mvc-boot-1/README.md b/spring-security-modules/spring-security-web-boot-1/README.md similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/README.md rename to spring-security-modules/spring-security-web-boot-1/README.md diff --git a/spring-security-modules/spring-security-mvc-boot-1/WebContent/META-INF/MANIFEST.MF b/spring-security-modules/spring-security-web-boot-1/WebContent/META-INF/MANIFEST.MF similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/WebContent/META-INF/MANIFEST.MF rename to spring-security-modules/spring-security-web-boot-1/WebContent/META-INF/MANIFEST.MF diff --git a/spring-security-modules/spring-security-mvc-boot-1/pom.xml b/spring-security-modules/spring-security-web-boot-1/pom.xml similarity index 98% rename from spring-security-modules/spring-security-mvc-boot-1/pom.xml rename to spring-security-modules/spring-security-web-boot-1/pom.xml index 7ad18376ec..1f80b62765 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/pom.xml +++ b/spring-security-modules/spring-security-web-boot-1/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-security-mvc-boot-1 + spring-security-web-boot-1 0.0.1-SNAPSHOT - spring-security-mvc-boot-1 + spring-security-web-boot-1 war Spring Security MVC Boot - 1 diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/AppConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/AppConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/AppConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/AppConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/SpringSecurityConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/SpringSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/SpringSecurityConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/SpringSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/models/AppUser.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/models/AppUser.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/models/AppUser.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/models/AppUser.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/models/Tweet.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/models/Tweet.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/models/Tweet.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/models/Tweet.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/repositories/TweetRepository.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/repositories/TweetRepository.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/repositories/TweetRepository.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/repositories/TweetRepository.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/repositories/UserRepository.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/repositories/UserRepository.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/repositories/UserRepository.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/repositories/UserRepository.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/AppUserPrincipal.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/security/AppUserPrincipal.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/AppUserPrincipal.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/security/AppUserPrincipal.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/AuthenticationSuccessHandlerImpl.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/security/AuthenticationSuccessHandlerImpl.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/AuthenticationSuccessHandlerImpl.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/security/AuthenticationSuccessHandlerImpl.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/CustomUserDetailsService.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/security/CustomUserDetailsService.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/CustomUserDetailsService.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/security/CustomUserDetailsService.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/util/DummyContentUtil.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/util/DummyContentUtil.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/util/DummyContentUtil.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/relationships/util/DummyContentUtil.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/Application.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/Application.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/Application.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/Application.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/MethodSecurityConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/config/MethodSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/MethodSecurityConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/config/MethodSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/MvcConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/config/MvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/MvcConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/config/MvcConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/SecurityConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/config/SecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/SecurityConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/config/SecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/SetupData.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/SetupData.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/SetupData.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/SetupData.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/OrganizationRepository.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/OrganizationRepository.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/OrganizationRepository.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/OrganizationRepository.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/PrivilegeRepository.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/PrivilegeRepository.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/PrivilegeRepository.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/PrivilegeRepository.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/UserRepository.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/UserRepository.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/UserRepository.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/UserRepository.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Foo.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Foo.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Foo.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Foo.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Organization.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Organization.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Organization.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Organization.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Privilege.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Privilege.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Privilege.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Privilege.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/User.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/User.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/User.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/User.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionHandler.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionHandler.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionHandler.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionRoot.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionRoot.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionRoot.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionRoot.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomPermissionEvaluator.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomPermissionEvaluator.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomPermissionEvaluator.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomPermissionEvaluator.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MySecurityExpressionRoot.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/MySecurityExpressionRoot.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MySecurityExpressionRoot.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/MySecurityExpressionRoot.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserDetailsService.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserDetailsService.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserDetailsService.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserDetailsService.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserPrincipal.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserPrincipal.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserPrincipal.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserPrincipal.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/web/MainController.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/web/MainController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/web/MainController.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/custom/web/MainController.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/IpApplication.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/ip/IpApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/IpApplication.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/ip/IpApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/CustomIpAuthenticationProvider.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/ip/config/CustomIpAuthenticationProvider.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/CustomIpAuthenticationProvider.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/ip/config/CustomIpAuthenticationProvider.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityXmlConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityXmlConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityXmlConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityXmlConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/web/MainController.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/ip/web/MainController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/web/MainController.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/ip/web/MainController.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/CustomAuthenticationProvider.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/CustomAuthenticationProvider.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/CustomAuthenticationProvider.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/CustomAuthenticationProvider.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyLogoutSuccessHandler.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyLogoutSuccessHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyLogoutSuccessHandler.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyLogoutSuccessHandler.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyUserDetailsService.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyUserDetailsService.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyUserDetailsService.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyUserDetailsService.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/RolesAuthoritiesApplication.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/RolesAuthoritiesApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/RolesAuthoritiesApplication.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/RolesAuthoritiesApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/MvcConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/MvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/MvcConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/MvcConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/SecurityConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/SecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/SecurityConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/SecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Privilege.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Privilege.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Privilege.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Privilege.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Role.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Role.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Role.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Role.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/User.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/User.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/User.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/User.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/IUserService.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/IUserService.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/IUserService.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/IUserService.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/PrivilegeRepository.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/PrivilegeRepository.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/PrivilegeRepository.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/PrivilegeRepository.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/RoleRepository.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/RoleRepository.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/RoleRepository.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/RoleRepository.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/SetupDataLoader.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/SetupDataLoader.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/SetupDataLoader.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/SetupDataLoader.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserRepository.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserRepository.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserRepository.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserRepository.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserService.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserService.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserService.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserService.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/MinuteBasedVoter.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/voter/MinuteBasedVoter.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/MinuteBasedVoter.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/voter/MinuteBasedVoter.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/VoterApplication.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/voter/VoterApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/VoterApplication.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/voter/VoterApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/VoterMvcConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/voter/VoterMvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/VoterMvcConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/voter/VoterMvcConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/WebSecurityConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/voter/WebSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/WebSecurityConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/voter/WebSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/XmlSecurityConfig.java b/spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/voter/XmlSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/XmlSecurityConfig.java rename to spring-security-modules/spring-security-web-boot-1/src/main/java/com/baeldung/roles/voter/XmlSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/application-defaults.properties b/spring-security-modules/spring-security-web-boot-1/src/main/resources/application-defaults.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/application-defaults.properties rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/application-defaults.properties diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/application.properties b/spring-security-modules/spring-security-web-boot-1/src/main/resources/application.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/application.properties rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/application.properties diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-boot-1/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/persistence-h2.properties b/spring-security-modules/spring-security-web-boot-1/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/persistence-h2.properties rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/persistence-h2.properties diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/spring-security-custom-voter.xml b/spring-security-modules/spring-security-web-boot-1/src/main/resources/spring-security-custom-voter.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/spring-security-custom-voter.xml rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/spring-security-custom-voter.xml diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/spring-security-ip.xml b/spring-security-modules/spring-security-web-boot-1/src/main/resources/spring-security-ip.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/spring-security-ip.xml rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/spring-security-ip.xml diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/403.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/403.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/403.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/403.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/index.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/index.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/index.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/index.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/login.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/login.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/login.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/login.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/loginAdmin.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/loginAdmin.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/loginAdmin.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/loginAdmin.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/loginUser.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/loginUser.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/loginUser.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/loginUser.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/login.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/login.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/login.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/login.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/loginWithWarning.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/loginWithWarning.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/loginWithWarning.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/loginWithWarning.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/multipleHttpLinks.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/multipleHttpLinks.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/multipleHttpLinks.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/multipleHttpLinks.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/myAdminPage.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/myAdminPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/myAdminPage.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/myAdminPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/myGuestPage.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/myGuestPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/myGuestPage.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/myGuestPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/myPrivateUserPage.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/myPrivateUserPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/myPrivateUserPage.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/myPrivateUserPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/myUserPage.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/myUserPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/multipleHttpElems/myUserPage.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/multipleHttpElems/myUserPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/private.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/private.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/private.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/private.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/rolesauthorities/home.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/rolesauthorities/home.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/rolesauthorities/home.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/rolesauthorities/home.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/rolesauthorities/login.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/rolesauthorities/login.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/rolesauthorities/login.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/rolesauthorities/login.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/rolesauthorities/protectedbyauthority.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/rolesauthorities/protectedbyauthority.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/rolesauthorities/protectedbyauthority.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/rolesauthorities/protectedbyauthority.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/rolesauthorities/protectedbynothing.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/rolesauthorities/protectedbynothing.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/rolesauthorities/protectedbynothing.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/rolesauthorities/protectedbynothing.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/rolesauthorities/protectedbyrole.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/rolesauthorities/protectedbyrole.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/rolesauthorities/protectedbyrole.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/rolesauthorities/protectedbyrole.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/ssl/welcome.html b/spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/ssl/welcome.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/resources/templates/ssl/welcome.html rename to spring-security-modules/spring-security-web-boot-1/src/main/resources/templates/ssl/welcome.html diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/relationships/SpringDataWithSecurityIntegrationTest.java b/spring-security-modules/spring-security-web-boot-1/src/test/java/com/baeldung/relationships/SpringDataWithSecurityIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/relationships/SpringDataWithSecurityIntegrationTest.java rename to spring-security-modules/spring-security-web-boot-1/src/test/java/com/baeldung/relationships/SpringDataWithSecurityIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/SpringContextTest.java b/spring-security-modules/spring-security-web-boot-1/src/test/java/com/baeldung/roles/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/SpringContextTest.java rename to spring-security-modules/spring-security-web-boot-1/src/test/java/com/baeldung/roles/SpringContextTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/ApplicationLiveTest.java b/spring-security-modules/spring-security-web-boot-1/src/test/java/com/baeldung/roles/web/ApplicationLiveTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/ApplicationLiveTest.java rename to spring-security-modules/spring-security-web-boot-1/src/test/java/com/baeldung/roles/web/ApplicationLiveTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/CustomUserDetailsServiceIntegrationTest.java b/spring-security-modules/spring-security-web-boot-1/src/test/java/com/baeldung/roles/web/CustomUserDetailsServiceIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/CustomUserDetailsServiceIntegrationTest.java rename to spring-security-modules/spring-security-web-boot-1/src/test/java/com/baeldung/roles/web/CustomUserDetailsServiceIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/IpLiveTest.java b/spring-security-modules/spring-security-web-boot-1/src/test/java/com/baeldung/roles/web/IpLiveTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/IpLiveTest.java rename to spring-security-modules/spring-security-web-boot-1/src/test/java/com/baeldung/roles/web/IpLiveTest.java From 8eede4e9f239ef347ce1ff3a8079955f757a5386 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 13 Aug 2020 12:54:12 +0530 Subject: [PATCH 266/309] JAVA-67:renamed spring-security-mvc-boot-2 to spring-security-web-boot-2 --- .../README.md | 0 .../WebContent/META-INF/MANIFEST.MF | 0 .../pom.xml | 4 ++-- .../CustomLogoutApplication.java | 0 .../customlogouthandler/MvcConfiguration.java | 0 .../customlogouthandler/services/UserCache.java | 0 .../com/baeldung/customlogouthandler/user/User.java | 0 .../customlogouthandler/user/UserUtils.java | 0 .../web/CustomLogoutHandler.java | 0 .../customlogouthandler/web/UserController.java | 0 .../h2/H2JdbcAuthenticationApplication.java | 0 .../h2/config/SecurityConfiguration.java | 0 .../jdbcauthentication/h2/web/UserController.java | 0 .../mysql/MySqlJdbcAuthenticationApplication.java | 0 .../mysql/config/SecurityConfiguration.java | 0 .../mysql/web/UserController.java | 0 .../PostgreJdbcAuthenticationApplication.java | 0 .../postgre/config/SecurityConfiguration.java | 0 .../postgre/web/UserController.java | 0 .../com/baeldung/loginredirect/LoginPageFilter.java | 0 .../loginredirect/LoginPageInterceptor.java | 0 .../loginredirect/LoginRedirectApplication.java | 0 .../loginredirect/LoginRedirectMvcConfig.java | 0 .../loginredirect/LoginRedirectSecurityConfig.java | 0 .../com/baeldung/loginredirect/UsersController.java | 0 .../CustomAuthenticationProvider.java | 0 .../MultipleAuthController.java | 0 .../MultipleAuthProvidersApplication.java | 0 .../MultipleAuthProvidersSecurityConfig.java | 0 .../MultipleEntryPointsApplication.java | 0 .../MultipleEntryPointsSecurityConfig.java | 0 .../multipleentrypoints/PagesController.java | 0 .../multiplelogin/MultipleLoginApplication.java | 0 .../multiplelogin/MultipleLoginMvcConfig.java | 0 .../multiplelogin/MultipleLoginSecurityConfig.java | 0 .../com/baeldung/multiplelogin/UsersController.java | 0 .../com/baeldung/ssl/HttpsEnabledApplication.java | 0 .../main/java/com/baeldung/ssl/SecurityConfig.java | 0 .../java/com/baeldung/ssl/WelcomeController.java | 0 .../application-customlogouthandler.properties | 0 .../main/resources/application-defaults.properties | 0 .../src/main/resources/application-mysql.properties | 0 .../main/resources/application-postgre.properties | 0 .../src/main/resources/application-ssl.properties | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/data-mysql.sql | 0 .../src/main/resources/data-postgre.sql | 0 .../src/main/resources/keystore/baeldung.p12 | Bin .../src/main/resources/logback.xml | 0 .../src/main/resources/persistence-h2.properties | 0 .../src/main/resources/schema-mysql.sql | 0 .../src/main/resources/schema-postgre.sql | 0 .../resources/spring-security-login-redirect.xml | 0 .../spring-security-multiple-auth-providers.xml | 0 .../resources/spring-security-multiple-entry.xml | 0 .../src/main/resources/templates/403.html | 0 .../src/main/resources/templates/adminPage.html | 0 .../src/main/resources/templates/index.html | 0 .../src/main/resources/templates/login.html | 0 .../src/main/resources/templates/loginAdmin.html | 0 .../src/main/resources/templates/loginUser.html | 0 .../templates/multipleHttpElems/login.html | 0 .../multipleHttpElems/loginWithWarning.html | 0 .../multipleHttpElems/multipleHttpLinks.html | 0 .../templates/multipleHttpElems/myAdminPage.html | 0 .../templates/multipleHttpElems/myGuestPage.html | 0 .../multipleHttpElems/myPrivateUserPage.html | 0 .../templates/multipleHttpElems/myUserPage.html | 0 .../src/main/resources/templates/private.html | 0 .../main/resources/templates/protectedLinks.html | 0 .../src/main/resources/templates/ssl/welcome.html | 0 .../src/main/resources/templates/userMainPage.html | 0 .../src/main/resources/templates/userPage.html | 0 .../CustomLogoutHandlerIntegrationTest.java | 0 .../jdbcauthentication/h2/SpringContextTest.java | 0 .../h2/web/UserControllerLiveTest.java | 0 .../mysql/web/UserControllerLiveTest.java | 0 .../postgre/web/UserControllerLiveTest.java | 0 .../web/HttpsApplicationIntegrationTest.java | 0 ...ipleAuthProvidersApplicationIntegrationTest.java | 0 .../web/MultipleEntryPointsIntegrationTest.java | 0 .../test/resources/customlogouthandler/after.sql | 0 .../customlogouthandler/application.properties | 0 .../test/resources/customlogouthandler/before.sql | 0 84 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/README.md (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/WebContent/META-INF/MANIFEST.MF (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/pom.xml (99%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/customlogouthandler/CustomLogoutApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/customlogouthandler/MvcConfiguration.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/customlogouthandler/services/UserCache.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/customlogouthandler/user/User.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/customlogouthandler/user/UserUtils.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/customlogouthandler/web/CustomLogoutHandler.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/customlogouthandler/web/UserController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/jdbcauthentication/h2/web/UserController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/jdbcauthentication/mysql/web/UserController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/jdbcauthentication/postgre/web/UserController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/loginredirect/LoginPageFilter.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/loginredirect/LoginRedirectApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/loginredirect/LoginRedirectMvcConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/loginredirect/LoginRedirectSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/loginredirect/UsersController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multipleauthproviders/CustomAuthenticationProvider.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multipleentrypoints/PagesController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multiplelogin/MultipleLoginApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multiplelogin/MultipleLoginMvcConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multiplelogin/MultipleLoginSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/multiplelogin/UsersController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/ssl/HttpsEnabledApplication.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/ssl/SecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/java/com/baeldung/ssl/WelcomeController.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/application-customlogouthandler.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/application-defaults.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/application-mysql.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/application-postgre.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/application-ssl.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/application.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/data-mysql.sql (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/data-postgre.sql (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/keystore/baeldung.p12 (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/persistence-h2.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/schema-mysql.sql (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/schema-postgre.sql (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/spring-security-login-redirect.xml (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/spring-security-multiple-auth-providers.xml (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/spring-security-multiple-entry.xml (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/403.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/adminPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/index.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/login.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/loginAdmin.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/loginUser.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/multipleHttpElems/login.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/multipleHttpElems/loginWithWarning.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/multipleHttpElems/multipleHttpLinks.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/multipleHttpElems/myAdminPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/multipleHttpElems/myGuestPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/multipleHttpElems/myPrivateUserPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/multipleHttpElems/myUserPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/private.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/protectedLinks.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/ssl/welcome.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/userMainPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/main/resources/templates/userPage.html (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/java/com/baeldung/customlogouthandler/CustomLogoutHandlerIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/java/com/baeldung/jdbcauthentication/h2/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/java/com/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/java/com/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/java/com/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/java/com/baeldung/web/HttpsApplicationIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/java/com/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/java/com/baeldung/web/MultipleEntryPointsIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/resources/customlogouthandler/after.sql (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/resources/customlogouthandler/application.properties (100%) rename spring-security-modules/{spring-security-mvc-boot-2 => spring-security-web-boot-2}/src/test/resources/customlogouthandler/before.sql (100%) diff --git a/spring-security-modules/spring-security-mvc-boot-2/README.md b/spring-security-modules/spring-security-web-boot-2/README.md similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/README.md rename to spring-security-modules/spring-security-web-boot-2/README.md diff --git a/spring-security-modules/spring-security-mvc-boot-2/WebContent/META-INF/MANIFEST.MF b/spring-security-modules/spring-security-web-boot-2/WebContent/META-INF/MANIFEST.MF similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/WebContent/META-INF/MANIFEST.MF rename to spring-security-modules/spring-security-web-boot-2/WebContent/META-INF/MANIFEST.MF diff --git a/spring-security-modules/spring-security-mvc-boot-2/pom.xml b/spring-security-modules/spring-security-web-boot-2/pom.xml similarity index 99% rename from spring-security-modules/spring-security-mvc-boot-2/pom.xml rename to spring-security-modules/spring-security-web-boot-2/pom.xml index 668eb04cd9..ca357509a3 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/pom.xml +++ b/spring-security-modules/spring-security-web-boot-2/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-security-mvc-boot-2 + spring-security-web-boot-2 0.0.1-SNAPSHOT - spring-security-mvc-boot-2 + spring-security-web-boot-2 war Spring Security MVC Boot - 2 diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/CustomLogoutApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/CustomLogoutApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/CustomLogoutApplication.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/CustomLogoutApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/MvcConfiguration.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/MvcConfiguration.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/MvcConfiguration.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/MvcConfiguration.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/services/UserCache.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/services/UserCache.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/services/UserCache.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/services/UserCache.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/user/User.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/user/User.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/user/User.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/user/User.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/user/UserUtils.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/user/UserUtils.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/user/UserUtils.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/user/UserUtils.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/web/CustomLogoutHandler.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/web/CustomLogoutHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/web/CustomLogoutHandler.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/web/CustomLogoutHandler.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/web/UserController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/web/UserController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/customlogouthandler/web/UserController.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/customlogouthandler/web/UserController.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/web/UserController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/web/UserController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/web/UserController.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/web/UserController.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/web/UserController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/web/UserController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/web/UserController.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/web/UserController.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/web/UserController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/web/UserController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/web/UserController.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/web/UserController.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageFilter.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageFilter.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageFilter.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageFilter.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginPageInterceptor.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectApplication.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectMvcConfig.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectMvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectMvcConfig.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectMvcConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectSecurityConfig.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectSecurityConfig.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/LoginRedirectSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/UsersController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/UsersController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/loginredirect/UsersController.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/loginredirect/UsersController.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/CustomAuthenticationProvider.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleauthproviders/CustomAuthenticationProvider.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/CustomAuthenticationProvider.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleauthproviders/CustomAuthenticationProvider.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthController.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthController.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/PagesController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleentrypoints/PagesController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/PagesController.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multipleentrypoints/PagesController.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginApplication.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginMvcConfig.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginMvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginMvcConfig.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginMvcConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginSecurityConfig.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginSecurityConfig.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/UsersController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multiplelogin/UsersController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/UsersController.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/multiplelogin/UsersController.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/HttpsEnabledApplication.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/ssl/HttpsEnabledApplication.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/HttpsEnabledApplication.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/ssl/HttpsEnabledApplication.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/SecurityConfig.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/ssl/SecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/SecurityConfig.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/ssl/SecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/WelcomeController.java b/spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/ssl/WelcomeController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/WelcomeController.java rename to spring-security-modules/spring-security-web-boot-2/src/main/java/com/baeldung/ssl/WelcomeController.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application-customlogouthandler.properties b/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-customlogouthandler.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application-customlogouthandler.properties rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/application-customlogouthandler.properties diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application-defaults.properties b/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-defaults.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application-defaults.properties rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/application-defaults.properties diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application-mysql.properties b/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-mysql.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application-mysql.properties rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/application-mysql.properties diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application-postgre.properties b/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-postgre.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application-postgre.properties rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/application-postgre.properties diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application-ssl.properties b/spring-security-modules/spring-security-web-boot-2/src/main/resources/application-ssl.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application-ssl.properties rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/application-ssl.properties diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application.properties b/spring-security-modules/spring-security-web-boot-2/src/main/resources/application.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/application.properties rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/application.properties diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/data-mysql.sql b/spring-security-modules/spring-security-web-boot-2/src/main/resources/data-mysql.sql similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/data-mysql.sql rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/data-mysql.sql diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/data-postgre.sql b/spring-security-modules/spring-security-web-boot-2/src/main/resources/data-postgre.sql similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/data-postgre.sql rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/data-postgre.sql diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/keystore/baeldung.p12 b/spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/baeldung.p12 similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/keystore/baeldung.p12 rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/keystore/baeldung.p12 diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-boot-2/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/persistence-h2.properties b/spring-security-modules/spring-security-web-boot-2/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/persistence-h2.properties rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/persistence-h2.properties diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/schema-mysql.sql b/spring-security-modules/spring-security-web-boot-2/src/main/resources/schema-mysql.sql similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/schema-mysql.sql rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/schema-mysql.sql diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/schema-postgre.sql b/spring-security-modules/spring-security-web-boot-2/src/main/resources/schema-postgre.sql similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/schema-postgre.sql rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/schema-postgre.sql diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/spring-security-login-redirect.xml b/spring-security-modules/spring-security-web-boot-2/src/main/resources/spring-security-login-redirect.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/spring-security-login-redirect.xml rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/spring-security-login-redirect.xml diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/spring-security-multiple-auth-providers.xml b/spring-security-modules/spring-security-web-boot-2/src/main/resources/spring-security-multiple-auth-providers.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/spring-security-multiple-auth-providers.xml rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/spring-security-multiple-auth-providers.xml diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/spring-security-multiple-entry.xml b/spring-security-modules/spring-security-web-boot-2/src/main/resources/spring-security-multiple-entry.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/spring-security-multiple-entry.xml rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/spring-security-multiple-entry.xml diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/403.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/403.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/403.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/403.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/adminPage.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/adminPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/adminPage.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/adminPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/index.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/index.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/index.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/index.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/login.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/login.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/login.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/login.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/loginAdmin.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/loginAdmin.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/loginAdmin.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/loginAdmin.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/loginUser.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/loginUser.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/loginUser.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/loginUser.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/login.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/login.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/login.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/login.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/loginWithWarning.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/loginWithWarning.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/loginWithWarning.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/loginWithWarning.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/multipleHttpLinks.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/multipleHttpLinks.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/multipleHttpLinks.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/multipleHttpLinks.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/myAdminPage.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/myAdminPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/myAdminPage.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/myAdminPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/myGuestPage.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/myGuestPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/myGuestPage.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/myGuestPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/myPrivateUserPage.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/myPrivateUserPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/myPrivateUserPage.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/myPrivateUserPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/myUserPage.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/myUserPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/multipleHttpElems/myUserPage.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/multipleHttpElems/myUserPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/private.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/private.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/private.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/private.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/protectedLinks.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/protectedLinks.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/protectedLinks.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/protectedLinks.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/ssl/welcome.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/ssl/welcome.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/ssl/welcome.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/ssl/welcome.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/userMainPage.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/userMainPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/userMainPage.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/userMainPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/userPage.html b/spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/userPage.html similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/resources/templates/userPage.html rename to spring-security-modules/spring-security-web-boot-2/src/main/resources/templates/userPage.html diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/customlogouthandler/CustomLogoutHandlerIntegrationTest.java b/spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/customlogouthandler/CustomLogoutHandlerIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/customlogouthandler/CustomLogoutHandlerIntegrationTest.java rename to spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/customlogouthandler/CustomLogoutHandlerIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/SpringContextTest.java b/spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/SpringContextTest.java rename to spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/SpringContextTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java b/spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java rename to spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java b/spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java rename to spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java b/spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java rename to spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/HttpsApplicationIntegrationTest.java b/spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/web/HttpsApplicationIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/HttpsApplicationIntegrationTest.java rename to spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/web/HttpsApplicationIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java b/spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java rename to spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/MultipleEntryPointsIntegrationTest.java b/spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/web/MultipleEntryPointsIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/MultipleEntryPointsIntegrationTest.java rename to spring-security-modules/spring-security-web-boot-2/src/test/java/com/baeldung/web/MultipleEntryPointsIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/resources/customlogouthandler/after.sql b/spring-security-modules/spring-security-web-boot-2/src/test/resources/customlogouthandler/after.sql similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/resources/customlogouthandler/after.sql rename to spring-security-modules/spring-security-web-boot-2/src/test/resources/customlogouthandler/after.sql diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/resources/customlogouthandler/application.properties b/spring-security-modules/spring-security-web-boot-2/src/test/resources/customlogouthandler/application.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/resources/customlogouthandler/application.properties rename to spring-security-modules/spring-security-web-boot-2/src/test/resources/customlogouthandler/application.properties diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/resources/customlogouthandler/before.sql b/spring-security-modules/spring-security-web-boot-2/src/test/resources/customlogouthandler/before.sql similarity index 100% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/resources/customlogouthandler/before.sql rename to spring-security-modules/spring-security-web-boot-2/src/test/resources/customlogouthandler/before.sql From fe7894fae0257be7e962513a7917d69f5f218695 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 13 Aug 2020 12:55:25 +0530 Subject: [PATCH 267/309] JAVA-67:renamed spring-security-mvc-custom to spring-security-web-mvc-custom --- .../.gitignore | 0 .../README.md | 0 .../pom.xml | 4 ++-- .../security/MySimpleUrlAuthenticationSuccessHandler.java | 0 .../src/main/java/com/baeldung/spring/MvcConfig.java | 0 .../main/java/com/baeldung/spring/MyUserDetailsService.java | 0 .../src/main/java/com/baeldung/spring/SecSecurityConfig.java | 0 .../main/java/com/baeldung/web/controller/BankController.java | 0 .../main/java/com/baeldung/web/controller/FooController.java | 0 .../java/com/baeldung/web/controller/LoginController.java | 0 .../java/com/baeldung/web/controller/PrintUserController.java | 0 .../src/main/java/com/baeldung/web/dto/Foo.java | 0 .../java/com/baeldung/web/interceptor/LoggerInterceptor.java | 0 .../com/baeldung/web/interceptor/SessionTimerInterceptor.java | 0 .../java/com/baeldung/web/interceptor/UserInterceptor.java | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/webSecurityConfig.xml | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/anonymous.jsp | 0 .../src/main/webapp/WEB-INF/view/console.jsp | 0 .../src/main/webapp/WEB-INF/view/csrfHome.jsp | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/view/login.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../baeldung/security/csrf/CsrfAbstractIntegrationTest.java | 0 .../baeldung/security/csrf/CsrfDisabledIntegrationTest.java | 0 .../baeldung/security/csrf/CsrfEnabledIntegrationTest.java | 0 .../com/baeldung/security/spring/ManualSecurityConfig.java | 0 .../security/spring/ManualSecurityIntegrationTest.java | 0 .../com/baeldung/security/spring/SecurityWithCsrfConfig.java | 0 .../baeldung/security/spring/SecurityWithoutCsrfConfig.java | 0 .../web/interceptor/LoggerInterceptorIntegrationTest.java | 0 .../interceptor/SessionTimerInterceptorIntegrationTest.java | 0 .../web/interceptor/UserInterceptorIntegrationTest.java | 0 .../src/test/resources/.gitignore | 0 36 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/.gitignore (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/README.md (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/pom.xml (98%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/spring/MvcConfig.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/spring/MyUserDetailsService.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/spring/SecSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/web/controller/BankController.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/web/controller/FooController.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/web/controller/LoginController.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/web/controller/PrintUserController.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/web/dto/Foo.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/web/interceptor/LoggerInterceptor.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/web/interceptor/SessionTimerInterceptor.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/java/com/baeldung/web/interceptor/UserInterceptor.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/resources/webSecurityConfig.xml (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/webapp/WEB-INF/view/anonymous.jsp (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/webapp/WEB-INF/view/console.jsp (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/webapp/WEB-INF/view/csrfHome.jsp (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/webapp/WEB-INF/view/login.jsp (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/main/webapp/WEB-INF/web.xml (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/security/csrf/CsrfAbstractIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/security/csrf/CsrfDisabledIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/security/csrf/CsrfEnabledIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/security/spring/ManualSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/security/spring/ManualSecurityIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/security/spring/SecurityWithCsrfConfig.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/security/spring/SecurityWithoutCsrfConfig.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/java/com/baeldung/web/interceptor/UserInterceptorIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-custom => spring-security-web-mvc-custom}/src/test/resources/.gitignore (100%) diff --git a/spring-security-modules/spring-security-mvc-custom/.gitignore b/spring-security-modules/spring-security-web-mvc-custom/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/.gitignore rename to spring-security-modules/spring-security-web-mvc-custom/.gitignore diff --git a/spring-security-modules/spring-security-mvc-custom/README.md b/spring-security-modules/spring-security-web-mvc-custom/README.md similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/README.md rename to spring-security-modules/spring-security-web-mvc-custom/README.md diff --git a/spring-security-modules/spring-security-mvc-custom/pom.xml b/spring-security-modules/spring-security-web-mvc-custom/pom.xml similarity index 98% rename from spring-security-modules/spring-security-mvc-custom/pom.xml rename to spring-security-modules/spring-security-web-mvc-custom/pom.xml index fe8c749c59..bd4a800bc5 100644 --- a/spring-security-modules/spring-security-mvc-custom/pom.xml +++ b/spring-security-modules/spring-security-web-mvc-custom/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - spring-security-mvc-custom + spring-security-web-mvc-custom 0.1-SNAPSHOT - spring-security-mvc-custom + spring-security-web-mvc-custom war diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MyUserDetailsService.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/spring/MyUserDetailsService.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MyUserDetailsService.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/spring/MyUserDetailsService.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/SecSecurityConfig.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/spring/SecSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/SecSecurityConfig.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/spring/SecSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/BankController.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/controller/BankController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/BankController.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/controller/BankController.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/FooController.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/controller/FooController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/FooController.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/controller/FooController.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/LoginController.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/controller/LoginController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/LoginController.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/controller/LoginController.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/PrintUserController.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/controller/PrintUserController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/PrintUserController.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/controller/PrintUserController.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/dto/Foo.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/dto/Foo.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/dto/Foo.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/dto/Foo.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/LoggerInterceptor.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/interceptor/LoggerInterceptor.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/LoggerInterceptor.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/interceptor/LoggerInterceptor.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/SessionTimerInterceptor.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/interceptor/SessionTimerInterceptor.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/SessionTimerInterceptor.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/interceptor/SessionTimerInterceptor.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/UserInterceptor.java b/spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/interceptor/UserInterceptor.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/UserInterceptor.java rename to spring-security-modules/spring-security-web-mvc-custom/src/main/java/com/baeldung/web/interceptor/UserInterceptor.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-mvc-custom/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-mvc-custom/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/resources/webSecurityConfig.xml b/spring-security-modules/spring-security-web-mvc-custom/src/main/resources/webSecurityConfig.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/resources/webSecurityConfig.xml rename to spring-security-modules/spring-security-web-mvc-custom/src/main/resources/webSecurityConfig.xml diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/anonymous.jsp b/spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/view/anonymous.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/anonymous.jsp rename to spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/view/anonymous.jsp diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/console.jsp b/spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/view/console.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/console.jsp rename to spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/view/console.jsp diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/csrfHome.jsp b/spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/view/csrfHome.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/csrfHome.jsp rename to spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/view/csrfHome.jsp diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/login.jsp b/spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/view/login.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/login.jsp rename to spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/view/login.jsp diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/web.xml rename to spring-security-modules/spring-security-web-mvc-custom/src/main/webapp/WEB-INF/web.xml diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfAbstractIntegrationTest.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfAbstractIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfAbstractIntegrationTest.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfAbstractIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfDisabledIntegrationTest.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfDisabledIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfDisabledIntegrationTest.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfDisabledIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfEnabledIntegrationTest.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfEnabledIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfEnabledIntegrationTest.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfEnabledIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityConfig.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityConfig.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityIntegrationTest.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityIntegrationTest.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithCsrfConfig.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithCsrfConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithCsrfConfig.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithCsrfConfig.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithoutCsrfConfig.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithoutCsrfConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithoutCsrfConfig.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithoutCsrfConfig.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/UserInterceptorIntegrationTest.java b/spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/web/interceptor/UserInterceptorIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/UserInterceptorIntegrationTest.java rename to spring-security-modules/spring-security-web-mvc-custom/src/test/java/com/baeldung/web/interceptor/UserInterceptorIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/resources/.gitignore b/spring-security-modules/spring-security-web-mvc-custom/src/test/resources/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc-custom/src/test/resources/.gitignore rename to spring-security-modules/spring-security-web-mvc-custom/src/test/resources/.gitignore From ab84d1c6d04ca9d16d256e62e8815f17fd25ce57 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 13 Aug 2020 12:56:26 +0530 Subject: [PATCH 268/309] JAVA-67:renamed spring-security-mvc-digest-auth to spring-security-web-digest-auth --- .../.gitignore | 0 .../README.md | 0 .../pom.xml | 4 ++-- .../com/baeldung/basic/MyBasicAuthenticationEntryPoint.java | 0 .../HttpComponentsClientHttpRequestFactoryDigestAuth.java | 0 .../src/main/java/com/baeldung/spring/ClientConfig.java | 0 .../src/main/java/com/baeldung/spring/MvcConfig.java | 0 .../src/main/java/com/baeldung/spring/SecSecurityConfig.java | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/webSecurityConfig.xml | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../src/test/java/com/baeldung/client/RawClientLiveTest.java | 0 .../src/test/resources/.gitignore | 0 16 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/.gitignore (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/README.md (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/pom.xml (98%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/main/java/com/baeldung/spring/ClientConfig.java (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/main/java/com/baeldung/spring/MvcConfig.java (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/main/java/com/baeldung/spring/SecSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/main/resources/webSecurityConfig.xml (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/main/webapp/WEB-INF/web.xml (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/test/java/com/baeldung/client/RawClientLiveTest.java (100%) rename spring-security-modules/{spring-security-mvc-digest-auth => spring-security-web-digest-auth}/src/test/resources/.gitignore (100%) diff --git a/spring-security-modules/spring-security-mvc-digest-auth/.gitignore b/spring-security-modules/spring-security-web-digest-auth/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/.gitignore rename to spring-security-modules/spring-security-web-digest-auth/.gitignore diff --git a/spring-security-modules/spring-security-mvc-digest-auth/README.md b/spring-security-modules/spring-security-web-digest-auth/README.md similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/README.md rename to spring-security-modules/spring-security-web-digest-auth/README.md diff --git a/spring-security-modules/spring-security-mvc-digest-auth/pom.xml b/spring-security-modules/spring-security-web-digest-auth/pom.xml similarity index 98% rename from spring-security-modules/spring-security-mvc-digest-auth/pom.xml rename to spring-security-modules/spring-security-web-digest-auth/pom.xml index 8061235c71..2579a11f97 100644 --- a/spring-security-modules/spring-security-mvc-digest-auth/pom.xml +++ b/spring-security-modules/spring-security-web-digest-auth/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - spring-security-mvc-digest-auth + spring-security-web-digest-auth 0.1-SNAPSHOT - spring-security-mvc-digest-auth + spring-security-web-digest-auth war diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java b/spring-security-modules/spring-security-web-digest-auth/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java rename to spring-security-modules/spring-security-web-digest-auth/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java b/spring-security-modules/spring-security-web-digest-auth/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java rename to spring-security-modules/spring-security-web-digest-auth/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/ClientConfig.java b/spring-security-modules/spring-security-web-digest-auth/src/main/java/com/baeldung/spring/ClientConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/ClientConfig.java rename to spring-security-modules/spring-security-web-digest-auth/src/main/java/com/baeldung/spring/ClientConfig.java diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/MvcConfig.java b/spring-security-modules/spring-security-web-digest-auth/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/MvcConfig.java rename to spring-security-modules/spring-security-web-digest-auth/src/main/java/com/baeldung/spring/MvcConfig.java diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java b/spring-security-modules/spring-security-web-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java rename to spring-security-modules/spring-security-web-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-digest-auth/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-digest-auth/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/resources/webSecurityConfig.xml b/spring-security-modules/spring-security-web-digest-auth/src/main/resources/webSecurityConfig.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/resources/webSecurityConfig.xml rename to spring-security-modules/spring-security-web-digest-auth/src/main/resources/webSecurityConfig.xml diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-security-modules/spring-security-web-digest-auth/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-security-modules/spring-security-web-digest-auth/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-security-modules/spring-security-web-digest-auth/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-security-modules/spring-security-web-digest-auth/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-web-digest-auth/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/webapp/WEB-INF/web.xml rename to spring-security-modules/spring-security-web-digest-auth/src/main/webapp/WEB-INF/web.xml diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-web-digest-auth/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-web-digest-auth/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/test/java/com/baeldung/client/RawClientLiveTest.java b/spring-security-modules/spring-security-web-digest-auth/src/test/java/com/baeldung/client/RawClientLiveTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/test/java/com/baeldung/client/RawClientLiveTest.java rename to spring-security-modules/spring-security-web-digest-auth/src/test/java/com/baeldung/client/RawClientLiveTest.java diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/test/resources/.gitignore b/spring-security-modules/spring-security-web-digest-auth/src/test/resources/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc-digest-auth/src/test/resources/.gitignore rename to spring-security-modules/spring-security-web-digest-auth/src/test/resources/.gitignore From daed0a310a4adc5b711fd84210a360ac0d3957f6 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 13 Aug 2020 12:57:25 +0530 Subject: [PATCH 269/309] JAVA-67: module pom changes as per renamed modules --- spring-security-modules/pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index 472c6b6e0d..d7b5844e6f 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -16,14 +16,14 @@ spring-security-acl spring-security-auth0 - spring-security-angular/server + spring-security-web-angular/server spring-security-config spring-security-core - spring-security-mvc - spring-security-mvc-boot-1 - spring-security-mvc-boot-2 - spring-security-mvc-custom - spring-security-mvc-digest-auth + spring-security-web-mvc + spring-security-web-boot-1 + spring-security-web-boot-2 + spring-security-web-mvc-custom + spring-security-web-digest-auth spring-security-mvc-jsonview spring-security-ldap spring-security-mvc-login From 6ce7fee3ffca103d84bba26f1dce438a5718b321 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Thu, 13 Aug 2020 11:38:50 +0200 Subject: [PATCH 270/309] BAEL-4541: Fix typos in the spring-kafka module (#9857) --- .../spring/kafka/KafkaApplication.java | 30 +++++++++---------- .../spring/kafka/KafkaTopicConfig.java | 4 +-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spring-kafka/src/main/java/com/baeldung/spring/kafka/KafkaApplication.java b/spring-kafka/src/main/java/com/baeldung/spring/kafka/KafkaApplication.java index fde56bebc0..9b79f716e9 100644 --- a/spring-kafka/src/main/java/com/baeldung/spring/kafka/KafkaApplication.java +++ b/spring-kafka/src/main/java/com/baeldung/spring/kafka/KafkaApplication.java @@ -30,23 +30,23 @@ public class KafkaApplication { MessageListener listener = context.getBean(MessageListener.class); /* * Sending a Hello World message to topic 'baeldung'. - * Must be recieved by both listeners with group foo + * Must be received by both listeners with group foo * and bar with containerFactory fooKafkaListenerContainerFactory * and barKafkaListenerContainerFactory respectively. - * It will also be recieved by the listener with - * headersKafkaListenerContainerFactory as container factory + * It will also be received by the listener with + * headersKafkaListenerContainerFactory as container factory. */ producer.sendMessage("Hello, World!"); listener.latch.await(10, TimeUnit.SECONDS); /* - * Sending message to a topic with 5 partition, + * Sending message to a topic with 5 partitions, * each message to a different partition. But as per * listener configuration, only the messages from * partition 0 and 3 will be consumed. */ for (int i = 0; i < 5; i++) { - producer.sendMessageToPartion("Hello To Partioned Topic!", i); + producer.sendMessageToPartition("Hello To Partitioned Topic!", i); } listener.partitionLatch.await(10, TimeUnit.SECONDS); @@ -61,7 +61,7 @@ public class KafkaApplication { /* * Sending message to 'greeting' topic. This will send - * and recieved a java object with the help of + * and received a java object with the help of * greetingKafkaListenerContainerFactory. */ producer.sendGreetingMessage(new Greeting("Greetings", "World!")); @@ -92,7 +92,7 @@ public class KafkaApplication { private String topicName; @Value(value = "${partitioned.topic.name}") - private String partionedTopicName; + private String partitionedTopicName; @Value(value = "${filtered.topic.name}") private String filteredTopicName; @@ -119,8 +119,8 @@ public class KafkaApplication { }); } - public void sendMessageToPartion(String message, int partition) { - kafkaTemplate.send(partionedTopicName, partition, null, message); + public void sendMessageToPartition(String message, int partition) { + kafkaTemplate.send(partitionedTopicName, partition, null, message); } public void sendMessageToFiltered(String message) { @@ -144,37 +144,37 @@ public class KafkaApplication { @KafkaListener(topics = "${message.topic.name}", groupId = "foo", containerFactory = "fooKafkaListenerContainerFactory") public void listenGroupFoo(String message) { - System.out.println("Received Messasge in group 'foo': " + message); + System.out.println("Received Message in group 'foo': " + message); latch.countDown(); } @KafkaListener(topics = "${message.topic.name}", groupId = "bar", containerFactory = "barKafkaListenerContainerFactory") public void listenGroupBar(String message) { - System.out.println("Received Messasge in group 'bar': " + message); + System.out.println("Received Message in group 'bar': " + message); latch.countDown(); } @KafkaListener(topics = "${message.topic.name}", containerFactory = "headersKafkaListenerContainerFactory") public void listenWithHeaders(@Payload String message, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition) { - System.out.println("Received Messasge: " + message + " from partition: " + partition); + System.out.println("Received Message: " + message + " from partition: " + partition); latch.countDown(); } @KafkaListener(topicPartitions = @TopicPartition(topic = "${partitioned.topic.name}", partitions = { "0", "3" }), containerFactory = "partitionsKafkaListenerContainerFactory") - public void listenToParition(@Payload String message, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition) { + public void listenToPartition(@Payload String message, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition) { System.out.println("Received Message: " + message + " from partition: " + partition); this.partitionLatch.countDown(); } @KafkaListener(topics = "${filtered.topic.name}", containerFactory = "filterKafkaListenerContainerFactory") public void listenWithFilter(String message) { - System.out.println("Recieved Message in filtered listener: " + message); + System.out.println("Received Message in filtered listener: " + message); this.filterLatch.countDown(); } @KafkaListener(topics = "${greeting.topic.name}", containerFactory = "greetingKafkaListenerContainerFactory") public void greetingListener(Greeting greeting) { - System.out.println("Recieved greeting message: " + greeting); + System.out.println("Received greeting message: " + greeting); this.greetingLatch.countDown(); } diff --git a/spring-kafka/src/main/java/com/baeldung/spring/kafka/KafkaTopicConfig.java b/spring-kafka/src/main/java/com/baeldung/spring/kafka/KafkaTopicConfig.java index fb60fadde4..00e4147cd0 100644 --- a/spring-kafka/src/main/java/com/baeldung/spring/kafka/KafkaTopicConfig.java +++ b/spring-kafka/src/main/java/com/baeldung/spring/kafka/KafkaTopicConfig.java @@ -20,7 +20,7 @@ public class KafkaTopicConfig { private String topicName; @Value(value = "${partitioned.topic.name}") - private String partionedTopicName; + private String partitionedTopicName; @Value(value = "${filtered.topic.name}") private String filteredTopicName; @@ -42,7 +42,7 @@ public class KafkaTopicConfig { @Bean public NewTopic topic2() { - return new NewTopic(partionedTopicName, 6, (short) 1); + return new NewTopic(partitionedTopicName, 6, (short) 1); } @Bean From ee2eae1056be8334bff0c83a119c778d5374557d Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 13 Aug 2020 16:07:42 +0530 Subject: [PATCH 271/309] JAVA-67: README updated for next-prev links --- spring-security-modules/spring-security-web-boot-1/README.md | 2 +- spring-security-modules/spring-security-web-boot-2/README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-security-modules/spring-security-web-boot-1/README.md b/spring-security-modules/spring-security-web-boot-1/README.md index f2c161d387..042fedf62b 100644 --- a/spring-security-modules/spring-security-web-boot-1/README.md +++ b/spring-security-modules/spring-security-web-boot-1/README.md @@ -13,5 +13,5 @@ The "REST With Spring" Classes: http://github.learnspringsecurity.com - [Granted Authority Versus Role in Spring Security](https://www.baeldung.com/spring-security-granted-authority-vs-role) - [Spring Security – Whitelist IP Range](https://www.baeldung.com/spring-security-whitelist-ip-range) - [Find the Registered Spring Security Filters](https://www.baeldung.com/spring-security-registered-filters) -- More articles: [[next -->]](/../spring-security-mvc-boot-2) +- More articles: [[next -->]](/spring-security-modules/spring-security-web-boot-2) diff --git a/spring-security-modules/spring-security-web-boot-2/README.md b/spring-security-modules/spring-security-web-boot-2/README.md index bbbf514c90..f5fc3a890d 100644 --- a/spring-security-modules/spring-security-web-boot-2/README.md +++ b/spring-security-modules/spring-security-web-boot-2/README.md @@ -14,3 +14,4 @@ The "REST With Spring" Classes: http://github.learnspringsecurity.com - [Spring Security: Exploring JDBC Authentication](https://www.baeldung.com/spring-security-jdbc-authentication) - [Spring Security Custom Logout Handler](https://www.baeldung.com/spring-security-custom-logout-handler) - [Redirecting Logged-in Users with Spring Security](https://www.baeldung.com/spring-security-redirect-logged-in) +- More articles: [[<-- prev]](/spring-security-modules/spring-security-web-boot-1) From a0ee1712e6645250e83153f6b7787daed718af8b Mon Sep 17 00:00:00 2001 From: sahilsingla112 Date: Thu, 13 Aug 2020 19:07:46 +0530 Subject: [PATCH 272/309] BAEL-4431-jdbcmetadata: Article about extracting metadata using JDBC (#9815) * BAEL-4431-jdbcmetadata: Article about extracting metadata using JDBC * BAEL-4431-jdbcmetadata: Review comments, fixed formatting issues by using the recommended intelij formatter Co-authored-by: sahil.singla --- .../baeldung/jdbcmetadata/DatabaseConfig.java | 49 ++++++++ .../jdbcmetadata/JdbcMetadataApplication.java | 30 +++++ .../jdbcmetadata/MetadataExtractor.java | 113 ++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/DatabaseConfig.java create mode 100644 persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/JdbcMetadataApplication.java create mode 100644 persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/MetadataExtractor.java diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/DatabaseConfig.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/DatabaseConfig.java new file mode 100644 index 0000000000..8ad689041e --- /dev/null +++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/DatabaseConfig.java @@ -0,0 +1,49 @@ +package com.baeldung.jdbcmetadata; + +import org.apache.log4j.Logger; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class DatabaseConfig { + private static final Logger LOG = Logger.getLogger(DatabaseConfig.class); + + private Connection connection; + + public DatabaseConfig() { + try { + Class.forName("org.h2.Driver"); + String url = "jdbc:h2:mem:testdb"; + connection = DriverManager.getConnection(url, "sa", ""); + } catch (ClassNotFoundException | SQLException e) { + LOG.error(e); + } + } + + public Connection getConnection() { + return connection; + } + + public void init() { + createTables(); + createViews(); + } + + private void createTables() { + try { + connection.createStatement().executeUpdate("create table CUSTOMER (ID int primary key auto_increment, NAME VARCHAR(45))"); + connection.createStatement().executeUpdate("create table CUST_ADDRESS (ID VARCHAR(36), CUST_ID int, ADDRESS VARCHAR(45), FOREIGN KEY (CUST_ID) REFERENCES CUSTOMER(ID))"); + } catch (SQLException e) { + LOG.error(e); + } + } + + private void createViews() { + try { + connection.createStatement().executeUpdate("CREATE VIEW CUSTOMER_VIEW AS SELECT * FROM CUSTOMER"); + } catch (SQLException e) { + LOG.error(e); + } + } +} diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/JdbcMetadataApplication.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/JdbcMetadataApplication.java new file mode 100644 index 0000000000..591a14f3b5 --- /dev/null +++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/JdbcMetadataApplication.java @@ -0,0 +1,30 @@ +package com.baeldung.jdbcmetadata; + +import org.apache.log4j.Logger; + +import java.sql.SQLException; + +public class JdbcMetadataApplication { + + private static final Logger LOG = Logger.getLogger(JdbcMetadataApplication.class); + + public static void main(String[] args) { + DatabaseConfig databaseConfig = new DatabaseConfig(); + databaseConfig.init(); + try { + MetadataExtractor metadataExtractor = new MetadataExtractor(databaseConfig.getConnection()); + metadataExtractor.extractTableInfo(); + metadataExtractor.extractSystemTables(); + metadataExtractor.extractViews(); + String tableName = "CUSTOMER"; + metadataExtractor.extractColumnInfo(tableName); + metadataExtractor.extractPrimaryKeys(tableName); + metadataExtractor.extractForeignKeys("CUST_ADDRESS"); + metadataExtractor.extractDatabaseInfo(); + metadataExtractor.extractUserName(); + metadataExtractor.extractSupportedFeatures(); + } catch (SQLException e) { + LOG.error("Error while executing SQL statements", e); + } + } +} diff --git a/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/MetadataExtractor.java b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/MetadataExtractor.java new file mode 100644 index 0000000000..27c615aebc --- /dev/null +++ b/persistence-modules/core-java-persistence/src/main/java/com/baeldung/jdbcmetadata/MetadataExtractor.java @@ -0,0 +1,113 @@ +package com.baeldung.jdbcmetadata; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class MetadataExtractor { + private final DatabaseMetaData databaseMetaData; + + public MetadataExtractor(Connection connection) throws SQLException { + this.databaseMetaData = connection.getMetaData(); + DatabaseMetaData databaseMetaData = connection.getMetaData(); + } + + public void extractTableInfo() throws SQLException { + ResultSet resultSet = databaseMetaData.getTables(null, null, "CUST%", new String[] { "TABLE" }); + while (resultSet.next()) { + // Print the names of existing tables + System.out.println(resultSet.getString("TABLE_NAME")); + System.out.println(resultSet.getString("REMARKS")); + } + } + + public void extractSystemTables() throws SQLException { + ResultSet resultSet = databaseMetaData.getTables(null, null, null, new String[] { "SYSTEM TABLE" }); + while (resultSet.next()) { + // Print the names of system tables + System.out.println(resultSet.getString("TABLE_NAME")); + } + } + + public void extractViews() throws SQLException { + ResultSet resultSet = databaseMetaData.getTables(null, null, null, new String[] { "VIEW" }); + while (resultSet.next()) { + // Print the names of existing views + System.out.println(resultSet.getString("TABLE_NAME")); + } + } + + public void extractColumnInfo(String tableName) throws SQLException { + ResultSet columns = databaseMetaData.getColumns(null, null, tableName, null); + + while (columns.next()) { + String columnName = columns.getString("COLUMN_NAME"); + String columnSize = columns.getString("COLUMN_SIZE"); + String datatype = columns.getString("DATA_TYPE"); + String isNullable = columns.getString("IS_NULLABLE"); + String isAutoIncrement = columns.getString("IS_AUTOINCREMENT"); + System.out.println(String.format("ColumnName: %s, columnSize: %s, datatype: %s, isColumnNullable: %s, isAutoIncrementEnabled: %s", columnName, columnSize, datatype, isNullable, isAutoIncrement)); + } + } + + public void extractPrimaryKeys(String tableName) throws SQLException { + ResultSet primaryKeys = databaseMetaData.getPrimaryKeys(null, null, tableName); + while (primaryKeys.next()) { + String primaryKeyColumnName = primaryKeys.getString("COLUMN_NAME"); + String primaryKeyName = primaryKeys.getString("PK_NAME"); + System.out.println(String.format("columnName:%s, pkName:%s", primaryKeyColumnName, primaryKeyName)); + } + } + + public void fun() throws SQLException { + + } + + public void extractForeignKeys(String tableName) throws SQLException { + ResultSet foreignKeys = databaseMetaData.getImportedKeys(null, null, tableName); + while (foreignKeys.next()) { + String pkTableName = foreignKeys.getString("PKTABLE_NAME"); + String fkTableName = foreignKeys.getString("FKTABLE_NAME"); + String pkColumnName = foreignKeys.getString("PKCOLUMN_NAME"); + String fkColumnName = foreignKeys.getString("FKCOLUMN_NAME"); + System.out.println(String.format("pkTableName:%s, fkTableName:%s, pkColumnName:%s, fkColumnName:%s", pkTableName, fkTableName, pkColumnName, fkColumnName)); + } + } + + public void extractDatabaseInfo() throws SQLException { + String productName = databaseMetaData.getDatabaseProductName(); + String productVersion = databaseMetaData.getDatabaseProductVersion(); + + String driverName = databaseMetaData.getDriverName(); + String driverVersion = databaseMetaData.getDriverVersion(); + + System.out.println(String.format("Product name:%s, Product version:%s", productName, productVersion)); + System.out.println(String.format("Driver name:%s, Driver Version:%s", driverName, driverVersion)); + } + + public void extractUserName() throws SQLException { + String userName = databaseMetaData.getUserName(); + System.out.println(userName); + ResultSet schemas = databaseMetaData.getSchemas(); + while (schemas.next()) { + String table_schem = schemas.getString("TABLE_SCHEM"); + String table_catalog = schemas.getString("TABLE_CATALOG"); + System.out.println(String.format("Table_schema:%s, Table_catalog:%s", table_schem, table_catalog)); + } + } + + public void extractSupportedFeatures() throws SQLException { + System.out.println("Supports scrollable & Updatable Result Set: " + databaseMetaData.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)); + System.out.println("Supports Full Outer Joins: " + databaseMetaData.supportsFullOuterJoins()); + System.out.println("Supports Stored Procedures: " + databaseMetaData.supportsStoredProcedures()); + System.out.println("Supports Subqueries in 'EXISTS': " + databaseMetaData.supportsSubqueriesInExists()); + System.out.println("Supports Transactions: " + databaseMetaData.supportsTransactions()); + System.out.println("Supports Core SQL Grammar: " + databaseMetaData.supportsCoreSQLGrammar()); + System.out.println("Supports Batch Updates: " + databaseMetaData.supportsBatchUpdates()); + System.out.println("Supports Column Aliasing: " + databaseMetaData.supportsColumnAliasing()); + System.out.println("Supports Savepoints: " + databaseMetaData.supportsSavepoints()); + System.out.println("Supports Union All: " + databaseMetaData.supportsUnionAll()); + System.out.println("Supports Union: " + databaseMetaData.supportsUnion()); + } +} From ad7f2cbefa6146205cc9d9bfcd1d30a65b1ac832 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 13 Aug 2020 17:09:19 +0300 Subject: [PATCH 273/309] Update README.md --- algorithms-searching/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/algorithms-searching/README.md b/algorithms-searching/README.md index 260a4ea714..aed3c7d21f 100644 --- a/algorithms-searching/README.md +++ b/algorithms-searching/README.md @@ -11,4 +11,3 @@ This module contains articles about searching algorithms. - [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search) - [Range Search Algorithm in Java](https://www.baeldung.com/java-range-search) - [Fast Pattern Matching of Strings Using Suffix Tree](https://www.baeldung.com/java-pattern-matching-suffix-tree) -- [Topological Sort of Directed Acyclic Graph](https://www.baeldung.com/cs/dag-topological-sort) From 2fe9016a23b0e6860a0b17e5a5c63c1ce11d5d3a Mon Sep 17 00:00:00 2001 From: root Date: Thu, 13 Aug 2020 16:10:01 +0000 Subject: [PATCH 274/309] final comments --- .../main/java/com/baeldung/loadedclasslisting/Launcher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java index 30db6b0bb7..bd9573d6b5 100644 --- a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java +++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java @@ -11,9 +11,9 @@ public class Launcher { } private static void printClassesLoadedBy(String classLoaderType) { + System.out.println(classLoaderType + " ClassLoader : "); Class[] classes = ListLoadedClassesAgent.listLoadedClasses(classLoaderType); Arrays.asList(classes) - .forEach(clazz -> System.out.println( - classLoaderType + " ClassLoader : " + clazz.getCanonicalName())); + .forEach(clazz -> System.out.println(clazz.getCanonicalName())); } } From 2addd74680639e4864a45ea35d2a02280bfa0dbe Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 13 Aug 2020 22:07:42 +0200 Subject: [PATCH 275/309] JAVA-1638: Get rid of the overriden spring-boot.version property --- spring-5-reactive-oauth/pom.xml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/spring-5-reactive-oauth/pom.xml b/spring-5-reactive-oauth/pom.xml index e9882a6d32..15f5dcacaa 100644 --- a/spring-5-reactive-oauth/pom.xml +++ b/spring-5-reactive-oauth/pom.xml @@ -7,7 +7,7 @@ 1.0.0-SNAPSHOT spring-5-reactive-oauth jar - WebFluc and Spring Security OAuth + WebFlux and Spring Security OAuth com.baeldung @@ -64,8 +64,4 @@ - - 2.1.0.RELEASE - - From 925c5655b7093c65ef690224f0713d5ed1abb48e Mon Sep 17 00:00:00 2001 From: CHANDRAKANT Kumar Date: Fri, 14 Aug 2020 12:46:33 +0530 Subject: [PATCH 276/309] Incorporated review comments on the pull request. --- spring-webflux-threads/pom.xml | 5 ++++- .../src/main/java/com/baeldung/webflux/Controller.java | 2 +- spring-webflux-threads/src/main/resources/application.yml | 7 ------- 3 files changed, 5 insertions(+), 9 deletions(-) delete mode 100644 spring-webflux-threads/src/main/resources/application.yml diff --git a/spring-webflux-threads/pom.xml b/spring-webflux-threads/pom.xml index e5b5bafd3b..15224fcd14 100644 --- a/spring-webflux-threads/pom.xml +++ b/spring-webflux-threads/pom.xml @@ -7,7 +7,7 @@ 1.0.0-SNAPSHOT spring-webflux-threads jar - Spring WebFlux AMQP Sample + Spring WebFlux Threads Sample com.baeldung @@ -20,6 +20,7 @@ org.springframework.boot spring-boot-starter-webflux + + + @@ -53,10 +47,10 @@ test - - one.util - streamex - ${streamex.version} + + one.util + streamex + ${streamex.version} net.bytebuddy diff --git a/libraries-5/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java b/libraries-5/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java index d8bc46985d..e4ac8a3a95 100644 --- a/libraries-5/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java +++ b/libraries-5/src/test/java/com/baeldung/pact/PactConsumerDrivenContractUnitTest.java @@ -5,8 +5,6 @@ import au.com.dius.pact.consumer.PactProviderRuleMk2; import au.com.dius.pact.consumer.PactVerification; import au.com.dius.pact.consumer.dsl.PactDslWithProvider; import au.com.dius.pact.model.RequestResponsePact; - -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.springframework.http.HttpEntity; @@ -28,15 +26,30 @@ public class PactConsumerDrivenContractUnitTest { @Pact(consumer = "test_consumer") public RequestResponsePact createPact(PactDslWithProvider builder) { - Map headers = new HashMap(); + Map headers = new HashMap<>(); headers.put("Content-Type", "application/json"); - return builder.given("test GET").uponReceiving("GET REQUEST").path("/pact").method("GET").willRespondWith().status(200).headers(headers).body("{\"condition\": true, \"name\": \"tom\"}").given("test POST").uponReceiving("POST REQUEST").method("POST") - .headers(headers).body("{\"name\": \"Michael\"}").path("/pact").willRespondWith().status(201).toPact(); + return builder + .given("test GET") + .uponReceiving("GET REQUEST") + .path("/pact") + .method("GET") + .willRespondWith() + .status(200) + .headers(headers) + .body("{\"condition\": true, \"name\": \"tom\"}") + .given("test POST") + .uponReceiving("POST REQUEST") + .method("POST") + .headers(headers) + .body("{\"name\": \"Michael\"}") + .path("/pact") + .willRespondWith() + .status(201) + .toPact(); } @Test - @Ignore @PactVerification() public void givenGet_whenSendRequest_shouldReturn200WithProperHeaderAndBody() { // when From 459662daf6bd4df19e8275664796708dff9c8dd2 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Fri, 14 Aug 2020 17:36:57 +0200 Subject: [PATCH 280/309] BAEL-4543: Use the prefered toArray() approach (#9869) --- .../java/collections/JavaCollectionConversionUnitTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java b/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java index ba640f3fb2..7b856309f1 100644 --- a/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java +++ b/java-collections-conversions/src/test/java/com/baeldung/java/collections/JavaCollectionConversionUnitTest.java @@ -144,7 +144,7 @@ public class JavaCollectionConversionUnitTest { final Map sourceMap = createMap(); final Collection values = sourceMap.values(); - final String[] targetArray = values.toArray(new String[values.size()]); + final String[] targetArray = values.toArray(new String[0]); } @Test From 9ca1a0064a74209d83a784811883a13e013c6430 Mon Sep 17 00:00:00 2001 From: Maiklins Date: Fri, 14 Aug 2020 17:41:36 +0200 Subject: [PATCH 281/309] CS-378 Find kth smallest element in union of two sorted arrays (#9812) * CS-378 Find the Kth Smallest Element in the Union of Two Sorted Arrays * CS-378 Fix name of unit test * CS-378 Update merge algorithm to operate only on two input arrays Co-authored-by: mikr --- .../algorithms/kthsmallest/KthSmallest.java | 126 ++++++++ .../kthsmallest/KthSmallestUnitTest.java | 288 ++++++++++++++++++ 2 files changed, 414 insertions(+) create mode 100644 algorithms-searching/src/main/java/com/baeldung/algorithms/kthsmallest/KthSmallest.java create mode 100644 algorithms-searching/src/test/java/com/baeldung/algorithms/kthsmallest/KthSmallestUnitTest.java diff --git a/algorithms-searching/src/main/java/com/baeldung/algorithms/kthsmallest/KthSmallest.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/kthsmallest/KthSmallest.java new file mode 100644 index 0000000000..2bd1a20ce0 --- /dev/null +++ b/algorithms-searching/src/main/java/com/baeldung/algorithms/kthsmallest/KthSmallest.java @@ -0,0 +1,126 @@ +package com.baeldung.algorithms.kthsmallest; + +import java.util.Arrays; +import java.util.NoSuchElementException; + +import static java.lang.Math.max; +import static java.lang.Math.min; + +public class KthSmallest { + + public static int findKthSmallestElement(int k, int[] list1, int[] list2) throws NoSuchElementException, IllegalArgumentException { + + checkInput(k, list1, list2); + + // we are looking for the minimum value + if(k == 1) { + return min(list1[0], list2[0]); + } + + // we are looking for the maximum value + if(list1.length + list2.length == k) { + return max(list1[list1.length-1], list2[list2.length-1]); + } + + // swap lists if needed to make sure we take at least one element from list1 + if(k <= list2.length && list2[k-1] < list1[0]) { + int[] list1_ = list1; + list1 = list2; + list2 = list1_; + } + + // correct left boundary if k is bigger than the size of list2 + int left = k < list2.length ? 0 : k - list2.length - 1; + + // the inital right boundary cannot exceed the list1 + int right = min(k-1, list1.length - 1); + + int nElementsList1, nElementsList2; + + // binary search + do { + nElementsList1 = ((left + right) / 2) + 1; + nElementsList2 = k - nElementsList1; + + if(nElementsList2 > 0) { + if (list1[nElementsList1 - 1] > list2[nElementsList2 - 1]) { + right = nElementsList1 - 2; + } else { + left = nElementsList1; + } + } + } while(!kthSmallesElementFound(list1, list2, nElementsList1, nElementsList2)); + + return nElementsList2 == 0 ? list1[nElementsList1-1] : max(list1[nElementsList1-1], list2[nElementsList2-1]); + } + + private static boolean kthSmallesElementFound(int[] list1, int[] list2, int nElementsList1, int nElementsList2) { + + // we do not take any element from the second list + if(nElementsList2 < 1) { + return true; + } + + if(list1[nElementsList1-1] == list2[nElementsList2-1]) { + return true; + } + + if(nElementsList1 == list1.length) { + return list1[nElementsList1-1] <= list2[nElementsList2]; + } + + if(nElementsList2 == list2.length) { + return list2[nElementsList2-1] <= list1[nElementsList1]; + } + + return list1[nElementsList1-1] <= list2[nElementsList2] && list2[nElementsList2-1] <= list1[nElementsList1]; + } + + + private static void checkInput(int k, int[] list1, int[] list2) throws NoSuchElementException, IllegalArgumentException { + + if(list1 == null || list2 == null || k < 1) { + throw new IllegalArgumentException(); + } + + if(list1.length == 0 || list2.length == 0) { + throw new IllegalArgumentException(); + } + + if(k > list1.length + list2.length) { + throw new NoSuchElementException(); + } + } + + public static int getKthElementSorted(int[] list1, int[] list2, int k) { + + int length1 = list1.length, length2 = list2.length; + int[] combinedArray = new int[length1 + length2]; + System.arraycopy(list1, 0, combinedArray, 0, list1.length); + System.arraycopy(list2, 0, combinedArray, list1.length, list2.length); + Arrays.sort(combinedArray); + + return combinedArray[k-1]; + } + + public static int getKthElementMerge(int[] list1, int[] list2, int k) { + + int i1 = 0, i2 = 0; + + while(i1 < list1.length && i2 < list2.length && (i1 + i2) < k) { + if(list1[i1] < list2[i2]) { + i1++; + } else { + i2++; + } + } + + if((i1 + i2) < k) { + return i1 < list1.length ? list1[k - i2 - 1] : list2[k - i1 - 1]; + } else if(i1 > 0 && i2 > 0) { + return Math.max(list1[i1-1], list2[i2-1]); + } else { + return i1 == 0 ? list2[i2-1] : list1[i1-1]; + } + } +} diff --git a/algorithms-searching/src/test/java/com/baeldung/algorithms/kthsmallest/KthSmallestUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/kthsmallest/KthSmallestUnitTest.java new file mode 100644 index 0000000000..740e89d8e7 --- /dev/null +++ b/algorithms-searching/src/test/java/com/baeldung/algorithms/kthsmallest/KthSmallestUnitTest.java @@ -0,0 +1,288 @@ +package com.baeldung.algorithms.kthsmallest; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; + +import java.util.*; + +import static com.baeldung.algorithms.kthsmallest.KthSmallest.*; +import static org.junit.jupiter.api.Assertions.*; + +public class KthSmallestUnitTest { + + @Nested + class Exceptions { + + @Test + public void when_at_least_one_list_is_null_then_an_exception_is_thrown() { + + Executable executable1 = () -> findKthSmallestElement(1, null, null); + Executable executable2 = () -> findKthSmallestElement(1, new int[]{2}, null); + Executable executable3 = () -> findKthSmallestElement(1, null, new int[]{2}); + + assertThrows(IllegalArgumentException.class, executable1); + assertThrows(IllegalArgumentException.class, executable2); + assertThrows(IllegalArgumentException.class, executable3); + } + + @Test + public void when_at_least_one_list_is_empty_then_an_exception_is_thrown() { + + Executable executable1 = () -> findKthSmallestElement(1, new int[]{}, new int[]{2}); + Executable executable2 = () -> findKthSmallestElement(1, new int[]{2}, new int[]{}); + Executable executable3 = () -> findKthSmallestElement(1, new int[]{}, new int[]{}); + + assertThrows(IllegalArgumentException.class, executable1); + assertThrows(IllegalArgumentException.class, executable2); + assertThrows(IllegalArgumentException.class, executable3); + } + + @Test + public void when_k_is_smaller_than_0_then_an_exception_is_thrown() { + Executable executable1 = () -> findKthSmallestElement(-1, new int[]{2}, new int[]{2}); + assertThrows(IllegalArgumentException.class, executable1); + } + + @Test + public void when_k_is_smaller_than_1_then_an_exception_is_thrown() { + Executable executable1 = () -> findKthSmallestElement(0, new int[]{2}, new int[]{2}); + assertThrows(IllegalArgumentException.class, executable1); + } + + @Test + public void when_k_bigger_then_the_two_lists_then_an_exception_is_thrown() { + Executable executable1 = () -> findKthSmallestElement(6, new int[]{1, 5, 6}, new int[]{2, 5}); + assertThrows(NoSuchElementException.class, executable1); + } + + } + + @Nested + class K_is_smaller_than_the_size_of_list1_and_the_size_of_list2 { + + @Test + public void when_k_is_1_then_the_smallest_element_is_returned_from_list1() { + int result = findKthSmallestElement(1, new int[]{2, 7}, new int[]{3, 5}); + assertEquals(2, result); + } + + @Test + public void when_k_is_1_then_the_smallest_element_is_returned_list2() { + int result = findKthSmallestElement(1, new int[]{3, 5}, new int[]{2, 7}); + assertEquals(2, result); + } + + @Test + public void when_kth_element_is_smallest_element_and_occurs_in_both_lists() { + int[] list1 = new int[]{1, 2, 3}; + int[] list2 = new int[]{1, 2, 3}; + int result = findKthSmallestElement(1, list1, list2); + assertEquals(1, result); + } + + @Test + public void when_kth_element_is_smallest_element_and_occurs_in_both_lists2() { + int[] list1 = new int[]{1, 2, 3}; + int[] list2 = new int[]{1, 2, 3}; + int result = findKthSmallestElement(2, list1, list2); + assertEquals(1, result); + } + + @Test + public void when_kth_element_is_largest_element_and_occurs_in_both_lists_1() { + int[] list1 = new int[]{1, 2, 3}; + int[] list2 = new int[]{1, 2, 3}; + int result = findKthSmallestElement(5, list1, list2); + assertEquals(3, result); + } + + @Test + public void when_kth_element_is_largest_element_and_occurs_in_both_lists_2() { + int[] list1 = new int[]{1, 2, 3}; + int[] list2 = new int[]{1, 2, 3}; + int result = findKthSmallestElement(6, list1, list2); + assertEquals(3, result); + } + + @Test + public void when_kth_element_and_occurs_in_both_lists() { + int[] list1 = new int[]{1, 2, 3}; + int[] list2 = new int[]{0, 2, 3}; + int result = findKthSmallestElement(3, list1, list2); + assertEquals(2, result); + } + + @Test + public void and_kth_element_is_in_first_list() { + int[] list1 = new int[]{1,2,3,4}; + int[] list2 = new int[]{1,3,4,5}; + int result = findKthSmallestElement(3, list1, list2); + assertEquals(2, result); + } + + @Test + public void and_kth_is_in_second_list() { + int[] list1 = new int[]{1,3,4,4}; + int[] list2 = new int[]{1,2,4,5}; + int result = findKthSmallestElement(3, list1, list2); + assertEquals(2, result); + } + + @Test + public void and_elements_in_first_list_are_all_smaller_than_second_list() { + int[] list1 = new int[]{1,3,7,9}; + int[] list2 = new int[]{11,12,14,15}; + int result = findKthSmallestElement(3, list1, list2); + assertEquals(7, result); + } + + @Test + public void and_elements_in_first_list_are_all_smaller_than_second_list2() { + int[] list1 = new int[]{1,3,7,9}; + int[] list2 = new int[]{11,12,14,15}; + int result = findKthSmallestElement(4, list1, list2); + assertEquals(9, result); + } + + @Test + public void and_only_elements_from_second_list_are_part_of_result() { + int[] list1 = new int[]{11,12,14,15}; + int[] list2 = new int[]{1,3,7,9}; + int result = findKthSmallestElement(3, list1, list2); + assertEquals(7, result); + } + + @Test + public void and_only_elements_from_second_list_are_part_of_result2() { + int[] list1 = new int[]{11,12,14,15}; + int[] list2 = new int[]{1,3,7,9}; + int result = findKthSmallestElement(4, list1, list2); + assertEquals(9, result); + } + } + + @Nested + class K_is_bigger_than_the_size_of_at_least_one_of_the_lists { + + @Test + public void k_is_smaller_than_list1_and_bigger_than_list2() { + int[] list1 = new int[]{1, 2, 3, 4, 7, 9}; + int[] list2 = new int[]{1, 2, 3}; + int result = findKthSmallestElement(5, list1, list2); + assertEquals(3, result); + } + + @Test + public void k_is_bigger_than_list1_and_smaller_than_list2() { + int[] list1 = new int[]{1, 2, 3}; + int[] list2 = new int[]{1, 2, 3, 4, 7, 9}; + int result = findKthSmallestElement(5, list1, list2); + assertEquals(3, result); + } + + @Test + public void when_k_is_bigger_than_the_size_of_both_lists_and_elements_in_second_list_are_all_smaller_than_first_list() { + int[] list1 = new int[]{9, 11, 13, 55}; + int[] list2 = new int[]{1, 2, 3, 7}; + int result = findKthSmallestElement(6, list1, list2); + assertEquals(11, result); + } + + @Test + public void when_k_is_bigger_than_the_size_of_both_lists_and_elements_in_second_list_are_all_bigger_than_first_list() { + int[] list1 = new int[]{1, 2, 3, 7}; + int[] list2 = new int[]{9, 11, 13, 55}; + int result = findKthSmallestElement(6, list1, list2); + assertEquals(11, result); + } + + @Test + public void when_k_is_bigger_than_the_size_of_both_lists() { + int[] list1 = new int[]{3, 7, 9, 11, 55}; + int[] list2 = new int[]{1, 2, 3, 7, 13}; + int result = findKthSmallestElement(7, list1, list2); + assertEquals(9, result); + } + + @Test + public void when_k_is_bigger_than_the_size_of_both_lists_and_list1_has_more_elements_than_list2() { + int[] list1 = new int[]{3, 7, 9, 11, 55, 77, 100, 200}; + int[] list2 = new int[]{1, 2, 3, 7, 13}; + int result = findKthSmallestElement(11, list1, list2); + assertEquals(77, result); + } + + @Test + public void max_test() { + int[] list1 = new int[]{100, 200}; + int[] list2 = new int[]{1, 2, 3}; + int result = findKthSmallestElement(4, list1, list2); + assertEquals(100, result); + } + + @Test + public void max_test2() { + int[] list1 = new int[]{100, 200}; + int[] list2 = new int[]{1, 2, 3}; + int result = findKthSmallestElement(5, list1, list2); + assertEquals(200, result); + } + + @Test + public void when_k_is_smaller_than_the_size_of_both_lists_and_kth_element_in_list2() { + int[] list1 = new int[]{1, 2, 5}; + int[] list2 = new int[]{1, 3, 4, 7}; + int result = findKthSmallestElement(4, list1, list2); + assertEquals(3, result); + } + + @Test + public void when_k_is_smaller_than_the_size_of_both_lists_and_kth_element_is_smallest_in_list2() { + int[] list1 = new int[]{1, 2, 5}; + int[] list2 = new int[]{3, 4, 7}; + int result = findKthSmallestElement(3, list1, list2); + assertEquals(3, result); + } + + @Test + public void when_k_is_smaller_than_the_size_of_both_lists_and_kth_element_is_smallest_in_list23() { + int[] list1 = new int[]{3, 11, 27, 53, 90}; + int[] list2 = new int[]{4, 20, 21, 100}; + int result = findKthSmallestElement(5, list1, list2); + assertEquals(21, result); + } + } + +// @Test +// public void randomTests() { +// IntStream.range(1, 100000).forEach(i -> random()); +// } + + private void random() { + + Random random = new Random(); + int length1 = (Math.abs(random.nextInt())) % 1000 + 1; + int length2 = (Math.abs(random.nextInt())) % 1000 + 1; + + int[] list1 = sortedRandomIntArrayOfLength(length1); + int[] list2 = sortedRandomIntArrayOfLength(length2); + + int k = (Math.abs(random.nextInt()) % (length1 + length2)) + 1 ; + + int result = findKthSmallestElement(k, list1, list2); + + int result2 = getKthElementSorted(list1, list2, k); + + int result3 = getKthElementMerge(list1, list2, k); + + assertEquals(result2, result); + assertEquals(result2, result3); + } + + private int[] sortedRandomIntArrayOfLength(int length) { + int[] intArray = new Random().ints(length).toArray(); + Arrays.sort(intArray); + return intArray; + } +} \ No newline at end of file From 8d97b0cb37a0e76767c3241bf6cfb9c5e0ca60a5 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 14 Aug 2020 22:07:40 +0530 Subject: [PATCH 282/309] JAVA-1639: Upgrade spring-5-security-cognito to use latest Spring Boot version --- spring-5-security-cognito/pom.xml | 9 +---- .../cognito/CognitoWebConfiguration.java | 2 -- .../cognito/SecurityConfiguration.java | 23 ++++++++++++ .../cognito/SpringCognitoApplication.java | 2 -- .../src/main/resources/application.yml | 15 ++++++++ .../resources/cognito/application-cognito.yml | 15 -------- .../src/main/resources/cognito/home.html | 32 ----------------- .../src/main/resources/cognito/style.css | 9 ----- .../src/main/resources/templates/home.html | 35 +++++++++++++++++++ 9 files changed, 74 insertions(+), 68 deletions(-) create mode 100644 spring-5-security-cognito/src/main/java/com/baeldung/cognito/SecurityConfiguration.java create mode 100644 spring-5-security-cognito/src/main/resources/application.yml delete mode 100644 spring-5-security-cognito/src/main/resources/cognito/application-cognito.yml delete mode 100644 spring-5-security-cognito/src/main/resources/cognito/home.html delete mode 100644 spring-5-security-cognito/src/main/resources/cognito/style.css create mode 100644 spring-5-security-cognito/src/main/resources/templates/home.html diff --git a/spring-5-security-cognito/pom.xml b/spring-5-security-cognito/pom.xml index 8d03b91ce0..5f8f328086 100644 --- a/spring-5-security-cognito/pom.xml +++ b/spring-5-security-cognito/pom.xml @@ -34,11 +34,6 @@ - - org.springframework.security.oauth.boot - spring-security-oauth2-autoconfigure - ${oauth-auto.version} - org.springframework.security spring-security-oauth2-client @@ -62,10 +57,8 @@ test - + - 2.1.0.RELEASE - 2.1.0.RELEASE com.baeldung.cognito.SpringCognitoApplication diff --git a/spring-5-security-cognito/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java b/spring-5-security-cognito/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java index 6841fa7a65..df35a46ef3 100644 --- a/spring-5-security-cognito/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java +++ b/spring-5-security-cognito/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java @@ -1,12 +1,10 @@ package com.baeldung.cognito; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -@PropertySource("cognito/application-cognito.yml") public class CognitoWebConfiguration implements WebMvcConfigurer { @Override diff --git a/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SecurityConfiguration.java b/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SecurityConfiguration.java new file mode 100644 index 0000000000..ba0436d20d --- /dev/null +++ b/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SecurityConfiguration.java @@ -0,0 +1,23 @@ +package com.baeldung.cognito; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Configuration +public class SecurityConfiguration extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf() + .and() + .authorizeRequests(authz -> authz.mvcMatchers("/") + .permitAll() + .anyRequest() + .authenticated()) + .oauth2Login() + .and() + .logout() + .logoutSuccessUrl("/"); + } +} \ No newline at end of file diff --git a/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java b/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java index eebe6d8f45..fc55de590c 100644 --- a/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java +++ b/spring-5-security-cognito/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java @@ -2,10 +2,8 @@ package com.baeldung.cognito; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.PropertySource; @SpringBootApplication -@PropertySource("cognito/application-cognito.yml") public class SpringCognitoApplication { public static void main(String[] args) { diff --git a/spring-5-security-cognito/src/main/resources/application.yml b/spring-5-security-cognito/src/main/resources/application.yml new file mode 100644 index 0000000000..e53a2642e0 --- /dev/null +++ b/spring-5-security-cognito/src/main/resources/application.yml @@ -0,0 +1,15 @@ +spring: + security: + oauth2: + client: + registration: + cognito: + client-id: your_clientId + client-secret: your_clientSecret + scope: openid + redirect-uri: http://localhost:8080/login/oauth2/code/cognito + clientName: your_clientName + provider: + cognito: + issuerUri: https://cognito-idp.{region}.amazonaws.com/{poolId} + user-name-attribute: cognito:username diff --git a/spring-5-security-cognito/src/main/resources/cognito/application-cognito.yml b/spring-5-security-cognito/src/main/resources/cognito/application-cognito.yml deleted file mode 100644 index 0a28dbccb4..0000000000 --- a/spring-5-security-cognito/src/main/resources/cognito/application-cognito.yml +++ /dev/null @@ -1,15 +0,0 @@ -spring: - security: - oauth2: - client: - registration: - cognito: - client-id: clientId - client-secret: clientSecret - scope: openid - redirectUriTemplate: "http://localhost:8080/login/oauth2/code/cognito" - clientName: cognito-client-name - provider: - cognito: - issuerUri: https://cognito-idp.{region}.amazonaws.com/{poolId} - usernameAttribute: cognito:username diff --git a/spring-5-security-cognito/src/main/resources/cognito/home.html b/spring-5-security-cognito/src/main/resources/cognito/home.html deleted file mode 100644 index f0bd9e52a8..0000000000 --- a/spring-5-security-cognito/src/main/resources/cognito/home.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - OAuth2 Cognito Demo - - - - - -
-
-
-

OAuth2 Spring Security Cognito Demo

- -
-
- Hello, ! -
-
- - -
-
-
- - diff --git a/spring-5-security-cognito/src/main/resources/cognito/style.css b/spring-5-security-cognito/src/main/resources/cognito/style.css deleted file mode 100644 index 45190d6d70..0000000000 --- a/spring-5-security-cognito/src/main/resources/cognito/style.css +++ /dev/null @@ -1,9 +0,0 @@ -.login { - background-color: #7289da; - color: #fff; -} - -.login:hover { - background-color: #697ec4; - color: #fff; -} diff --git a/spring-5-security-cognito/src/main/resources/templates/home.html b/spring-5-security-cognito/src/main/resources/templates/home.html new file mode 100644 index 0000000000..df3c86fe2a --- /dev/null +++ b/spring-5-security-cognito/src/main/resources/templates/home.html @@ -0,0 +1,35 @@ + + + + + +OAuth2 Cognito Demo + + + + +
+
+
+

OAuth2 Spring Security Cognito Demo

+ +
+
+ Hello, ! +
+
+ + +
+
+
+ + From 9c846f0e842799543be23dc71b0c54bbb697b474 Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sat, 15 Aug 2020 03:21:29 +0530 Subject: [PATCH 283/309] keeping Configuration in Separate class --- .../cosmosdb/AzureCosmosDbApplication.java | 34 +---------------- .../config/AzureCosmosDbConfiguration.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/config/AzureCosmosDbConfiguration.java diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java index 7a91cd7d33..5a1764adc6 100644 --- a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/AzureCosmosDbApplication.java @@ -1,44 +1,12 @@ package com.baeldung.spring.data.cosmosdb; -import com.azure.data.cosmos.CosmosKeyCredential; -import com.baeldung.spring.data.cosmosdb.repository.ProductRepository; -import com.microsoft.azure.spring.data.cosmosdb.config.AbstractCosmosConfiguration; -import com.microsoft.azure.spring.data.cosmosdb.config.CosmosDBConfig; -import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableCosmosRepositories; - -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; @SpringBootApplication -@EnableCosmosRepositories(basePackageClasses = ProductRepository.class) -public class AzureCosmosDbApplication extends AbstractCosmosConfiguration { +public class AzureCosmosDbApplication { public static void main(String[] args) { SpringApplication.run(AzureCosmosDbApplication.class, args); } - - @Value("${azure.cosmosdb.uri}") - private String uri; - - @Value("${azure.cosmosdb.key}") - private String key; - - @Value("${azure.cosmosdb.secondaryKey}") - private String secondaryKey; - - @Value("${azure.cosmosdb.database}") - private String dbName; - - private CosmosKeyCredential cosmosKeyCredential; - - @Bean - public CosmosDBConfig getConfig() { - this.cosmosKeyCredential = new CosmosKeyCredential(key); - CosmosDBConfig cosmosdbConfig = CosmosDBConfig.builder(uri, this.cosmosKeyCredential, dbName) - .build(); - return cosmosdbConfig; - } - } diff --git a/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/config/AzureCosmosDbConfiguration.java b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/config/AzureCosmosDbConfiguration.java new file mode 100644 index 0000000000..7d3322faf6 --- /dev/null +++ b/persistence-modules/spring-data-cosmosdb/src/main/java/com/baeldung/spring/data/cosmosdb/config/AzureCosmosDbConfiguration.java @@ -0,0 +1,37 @@ +package com.baeldung.spring.data.cosmosdb.config; + +import com.azure.data.cosmos.CosmosKeyCredential; +import com.microsoft.azure.spring.data.cosmosdb.config.AbstractCosmosConfiguration; +import com.microsoft.azure.spring.data.cosmosdb.config.CosmosDBConfig; +import com.microsoft.azure.spring.data.cosmosdb.repository.config.EnableCosmosRepositories; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableCosmosRepositories(basePackages = "com.baeldung.spring.data.cosmosdb.repository") +public class AzureCosmosDbConfiguration extends AbstractCosmosConfiguration { + + @Value("${azure.cosmosdb.uri}") + private String uri; + + @Value("${azure.cosmosdb.key}") + private String key; + + @Value("${azure.cosmosdb.secondaryKey}") + private String secondaryKey; + + @Value("${azure.cosmosdb.database}") + private String dbName; + + private CosmosKeyCredential cosmosKeyCredential; + + @Bean + public CosmosDBConfig getConfig() { + this.cosmosKeyCredential = new CosmosKeyCredential(key); + CosmosDBConfig cosmosdbConfig = CosmosDBConfig.builder(uri, this.cosmosKeyCredential, dbName) + .build(); + return cosmosdbConfig; + } +} From 223944628593984ee2c663e9dfb317de09b45ec8 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 15 Aug 2020 15:01:37 +0100 Subject: [PATCH 284/309] BAEL-4321 use properties module and delete ReadMe --- spring-boot-modules/spring-boot-data-2/README.md | 9 --------- .../pom.xml | 6 +++--- .../com/baeldung/boot/properties}/DemoApplication.java | 0 .../boot/properties}/config/TshirtSizeConfig.java | 0 .../properties}/controller/TshirtSizeController.java | 0 .../boot/properties}/service/SizeConverterImpl.java | 0 .../boot/properties}/service/SizeConverterService.java | 0 .../src/main/resources/application.yml | 0 .../properties}/controller/TshirtSizeControllerTest.java | 0 9 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-data-2/README.md rename spring-boot-modules/{spring-boot-data-2 => spring-boot-properties-3}/pom.xml (90%) rename spring-boot-modules/{spring-boot-data-2/src/main/java/com/baeldung/boot/data => spring-boot-properties-3/src/main/java/com/baeldung/boot/properties}/DemoApplication.java (100%) rename spring-boot-modules/{spring-boot-data-2/src/main/java/com/baeldung/boot/data => spring-boot-properties-3/src/main/java/com/baeldung/boot/properties}/config/TshirtSizeConfig.java (100%) rename spring-boot-modules/{spring-boot-data-2/src/main/java/com/baeldung/boot/data => spring-boot-properties-3/src/main/java/com/baeldung/boot/properties}/controller/TshirtSizeController.java (100%) rename spring-boot-modules/{spring-boot-data-2/src/main/java/com/baeldung/boot/data => spring-boot-properties-3/src/main/java/com/baeldung/boot/properties}/service/SizeConverterImpl.java (100%) rename spring-boot-modules/{spring-boot-data-2/src/main/java/com/baeldung/boot/data => spring-boot-properties-3/src/main/java/com/baeldung/boot/properties}/service/SizeConverterService.java (100%) rename spring-boot-modules/{spring-boot-data-2 => spring-boot-properties-3}/src/main/resources/application.yml (100%) rename spring-boot-modules/{spring-boot-data-2/src/test/java/com/baeldung/boot/data => spring-boot-properties-3/src/test/java/com/baeldung/boot/properties}/controller/TshirtSizeControllerTest.java (100%) diff --git a/spring-boot-modules/spring-boot-data-2/README.md b/spring-boot-modules/spring-boot-data-2/README.md deleted file mode 100644 index 9dba74a7e5..0000000000 --- a/spring-boot-modules/spring-boot-data-2/README.md +++ /dev/null @@ -1,9 +0,0 @@ -This is a demo application for using YAML configuration for defining values in a POJO class. - -The application has an endpoint to provide T-shirt size conversion for label and countrycode. - -If you run this service locally you can call this endpoint on: - -`localhost:8080/convertSize?label=M&countryCode=fr` - -It should return the size as int. \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-data-2/pom.xml b/spring-boot-modules/spring-boot-properties-3/pom.xml similarity index 90% rename from spring-boot-modules/spring-boot-data-2/pom.xml rename to spring-boot-modules/spring-boot-properties-3/pom.xml index 0baaf292e8..1e3d627b19 100644 --- a/spring-boot-modules/spring-boot-data-2/pom.xml +++ b/spring-boot-modules/spring-boot-properties-3/pom.xml @@ -9,10 +9,10 @@ ../ - spring-boot-data-2 + spring-boot-properties-3 0.0.1-SNAPSHOT - spring-boot-data-2 - Spring Boot Data Module + spring-boot-properties-3 + Spring Boot Properties Module 1.8 diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/DemoApplication.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/DemoApplication.java rename to spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/config/TshirtSizeConfig.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/config/TshirtSizeConfig.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/config/TshirtSizeConfig.java rename to spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/config/TshirtSizeConfig.java diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/controller/TshirtSizeController.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/controller/TshirtSizeController.java rename to spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterImpl.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterImpl.java rename to spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java diff --git a/spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterService.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterService.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/java/com/baeldung/boot/data/service/SizeConverterService.java rename to spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterService.java diff --git a/spring-boot-modules/spring-boot-data-2/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/main/resources/application.yml rename to spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml diff --git a/spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/data/controller/TshirtSizeControllerTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java similarity index 100% rename from spring-boot-modules/spring-boot-data-2/src/test/java/com/baeldung/boot/data/controller/TshirtSizeControllerTest.java rename to spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java From 3c44e7af209b2f93838d2503f673ff6d4330c5e7 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 15 Aug 2020 15:04:10 +0100 Subject: [PATCH 285/309] BAEL-4321 fix indentation --- .../boot/properties/controller/TshirtSizeController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java index 6446a17317..82263eaeed 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java +++ b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java @@ -14,8 +14,7 @@ public class TshirtSizeController { } @RequestMapping(value ="convertSize", method = RequestMethod.GET) - public int convertSize(@RequestParam(value = "label") final String label, - @RequestParam(value = "countryCode", required = false) final String countryCode) { + public int convertSize(@RequestParam(value = "label") final String label, @RequestParam(value = "countryCode", required = false) final String countryCode) { return service.convertSize(label, countryCode); } From e399a6a8bc9c79d96a27a62eb960e7e6c209620e Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 15 Aug 2020 15:34:56 +0100 Subject: [PATCH 286/309] BAEL-4321 fix package name in imports and convert tabs to spaces --- .../baeldung/boot/properties/DemoApplication.java | 8 ++++---- .../boot/properties/config/TshirtSizeConfig.java | 2 +- .../controller/TshirtSizeController.java | 2 +- .../boot/properties/service/SizeConverterImpl.java | 2 +- .../properties/service/SizeConverterService.java | 2 +- .../src/main/resources/application.yml | 14 +++++++------- .../controller/TshirtSizeControllerTest.java | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java index 125cba6283..634cb211b2 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java +++ b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java @@ -1,4 +1,4 @@ -package com.baeldung.boot.data; +package com.baeldung.boot.properties; import com.baeldung.boot.data.config.TshirtSizeConfig; import org.springframework.boot.SpringApplication; @@ -9,8 +9,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties @EnableConfigurationProperties(TshirtSizeConfig.class) public class DemoApplication { - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } } diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/config/TshirtSizeConfig.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/config/TshirtSizeConfig.java index 000f5b6826..690763ab7b 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/config/TshirtSizeConfig.java +++ b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/config/TshirtSizeConfig.java @@ -1,4 +1,4 @@ -package com.baeldung.boot.data.config; +package com.baeldung.boot.properties.config; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java index 82263eaeed..2f5c523c2e 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java +++ b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java @@ -1,4 +1,4 @@ -package com.baeldung.boot.data.controller; +package com.baeldung.boot.properties.controller; import org.springframework.web.bind.annotation.*; import com.baeldung.boot.data.service.SizeConverterService; diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java index ccb5a06da4..8554783493 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java +++ b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.boot.data.service; +package com.baeldung.boot.properties.service; import org.springframework.stereotype.Service; import com.baeldung.boot.data.config.TshirtSizeConfig; diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterService.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterService.java index 91cf2bf0b4..412199b176 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterService.java +++ b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterService.java @@ -1,4 +1,4 @@ -package com.baeldung.boot.data.service; +package com.baeldung.boot.properties.service; public interface SizeConverterService { diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml index edd200389e..8779cb6b0c 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml @@ -1,10 +1,10 @@ -t-shirt-size: - simple-mapping: - XS: 6 - S: 8 - M: 10 - L: 12 - XL: 14 + t-shirt-size: + simple-mapping: + XS: 6 + S: 8 + M: 10 + L: 12 + XL: 14 complex-mapping: diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java index 1d60eb41c0..96584d6077 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java @@ -1,4 +1,4 @@ -package com.baeldung.boot.data.controller; +package com.baeldung.boot.properties.controller; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; From 130133d73bf1a2ba4ca4c25394bb92755602240d Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sat, 15 Aug 2020 15:39:01 +0100 Subject: [PATCH 287/309] BAEL-4321 fix leftover data package names --- .../main/java/com/baeldung/boot/properties/DemoApplication.java | 2 +- .../boot/properties/controller/TshirtSizeController.java | 2 +- .../com/baeldung/boot/properties/service/SizeConverterImpl.java | 2 +- .../boot/properties/controller/TshirtSizeControllerTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java index 634cb211b2..cf2fb7f981 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java +++ b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java @@ -1,6 +1,6 @@ package com.baeldung.boot.properties; -import com.baeldung.boot.data.config.TshirtSizeConfig; +import com.baeldung.boot.properties.config.TshirtSizeConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java index 2f5c523c2e..6b713c5be8 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java +++ b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java @@ -1,7 +1,7 @@ package com.baeldung.boot.properties.controller; import org.springframework.web.bind.annotation.*; -import com.baeldung.boot.data.service.SizeConverterService; +import com.baeldung.boot.properties.service.SizeConverterService; @RestController @RequestMapping(value = "/") diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java index 8554783493..34f7fe2ded 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java +++ b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java @@ -1,7 +1,7 @@ package com.baeldung.boot.properties.service; import org.springframework.stereotype.Service; -import com.baeldung.boot.data.config.TshirtSizeConfig; +import com.baeldung.boot.properties.config.TshirtSizeConfig; @Service diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java index 96584d6077..0b70ed8622 100644 --- a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java +++ b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import com.baeldung.boot.data.service.SizeConverterService; +import com.baeldung.boot.properties.service.SizeConverterService; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; From ab056706ac911db736de01b41aa257d2220f6881 Mon Sep 17 00:00:00 2001 From: mikr Date: Sat, 15 Aug 2020 20:02:21 +0200 Subject: [PATCH 288/309] Java-70 Remove unnecessary files from spring-jpa-2 + include in main persistence pom file --- persistence-modules/pom.xml | 1 + persistence-modules/spring-jpa-2/README.md | 18 +--- persistence-modules/spring-jpa-2/pom.xml | 94 +------------------ .../baeldung/config/PersistenceJPAConfig.java | 85 ----------------- .../config/PersistenceJPAConfigXml.java | 17 ---- .../com/baeldung/config/SpringWebConfig.java | 24 ----- .../com/baeldung/config/StudentJpaConfig.java | 67 ------------- .../com/baeldung/config/WebInitializer.java | 20 ---- .../src/main/resources/context.xml | 1 - .../src/main/resources/logback.xml | 19 ---- .../main/resources/persistence-h2.properties | 10 -- .../resources/persistence-student.properties | 11 --- .../src/main/resources/persistence.xml | 42 --------- .../src/main/resources/server.xml | 6 -- .../src/main/resources/sqlfiles.properties | 1 - .../src/test/java/META-INF/persistence.xml | 20 ---- .../java/com/baeldung/SpringContextTest.java | 21 ----- .../resources/persistence-student.properties | 9 -- persistence-modules/spring-jpa/README.md | 5 +- 19 files changed, 6 insertions(+), 465 deletions(-) delete mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfig.java delete mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfigXml.java delete mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/SpringWebConfig.java delete mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/StudentJpaConfig.java delete mode 100644 persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/WebInitializer.java delete mode 100644 persistence-modules/spring-jpa-2/src/main/resources/context.xml delete mode 100644 persistence-modules/spring-jpa-2/src/main/resources/logback.xml delete mode 100644 persistence-modules/spring-jpa-2/src/main/resources/persistence-h2.properties delete mode 100644 persistence-modules/spring-jpa-2/src/main/resources/persistence-student.properties delete mode 100644 persistence-modules/spring-jpa-2/src/main/resources/persistence.xml delete mode 100644 persistence-modules/spring-jpa-2/src/main/resources/server.xml delete mode 100644 persistence-modules/spring-jpa-2/src/main/resources/sqlfiles.properties delete mode 100644 persistence-modules/spring-jpa-2/src/test/java/META-INF/persistence.xml delete mode 100644 persistence-modules/spring-jpa-2/src/test/java/com/baeldung/SpringContextTest.java delete mode 100644 persistence-modules/spring-jpa-2/src/test/resources/persistence-student.properties diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 78f1afd39a..6186900a6e 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -78,6 +78,7 @@ spring-hibernate-5 spring-hibernate4 spring-jpa + spring-jpa-2 spring-persistence-simple spring-persistence-simple-2 diff --git a/persistence-modules/spring-jpa-2/README.md b/persistence-modules/spring-jpa-2/README.md index 71b368b44a..b1786f49bd 100644 --- a/persistence-modules/spring-jpa-2/README.md +++ b/persistence-modules/spring-jpa-2/README.md @@ -1,19 +1,5 @@ -========= - -## Spring JPA Example Project - +## Spring JPA (2) ### Relevant Articles: - [Many-To-Many Relationship in JPA](https://www.baeldung.com/jpa-many-to-many) -- More articles: [[<-- prev]](/spring-jpa) - - -### Eclipse Config -After importing the project into Eclipse, you may see the following error: -"No persistence xml file found in project" - -This can be ignored: -- Project -> Properties -> Java Persistance -> JPA -> Error/Warnings -> Select Ignore on "No persistence xml file found in project" -Or: -- Eclipse -> Preferences - Validation - disable the "Build" execution of the JPA Validator - +- More articles: [[<-- prev]](/spring-jpa) \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/pom.xml b/persistence-modules/spring-jpa-2/pom.xml index 410ed592b0..08a1f0c6a3 100644 --- a/persistence-modules/spring-jpa-2/pom.xml +++ b/persistence-modules/spring-jpa-2/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - spring-jpa + spring-jpa-2 0.1-SNAPSHOT - spring-jpa + spring-jpa-2 war @@ -31,94 +31,20 @@ spring-context ${org.springframework.version}
- - org.springframework - spring-webmvc - ${org.springframework.version} - - org.hibernate hibernate-entitymanager ${hibernate.version} - - xml-apis - xml-apis - ${xml-apis.version} - - - org.javassist - javassist - ${javassist.version} - - - mysql - mysql-connector-java - ${mysql-connector-java.version} - runtime - - - org.springframework.data - spring-data-jpa - ${spring-data-jpa.version} - com.h2database h2 ${h2.version} - - - - org.hibernate - hibernate-validator - ${hibernate-validator.version} - - - javax.el - javax.el-api - ${javax.el-api.version} - - - - - javax.servlet - jstl - ${jstl.version} - - - javax.servlet - servlet-api - provided - ${javax.servlet.servlet-api.version} - - - - - - com.google.guava - guava - ${guava.version} - - - org.assertj - assertj-core - ${assertj.version} - - - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - test - - org.springframework spring-test @@ -131,22 +57,6 @@ 5.1.5.RELEASE - 3.21.0-GA - - 6.0.6 - 2.1.5.RELEASE - - - 2.5 - - - 6.0.15.Final - 1.4.01 - 2.2.5 - - - 21.0 - 3.8.0 \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfig.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfig.java deleted file mode 100644 index c489321122..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfig.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.baeldung.config; - -import com.google.common.base.Preconditions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.persistence.EntityManagerFactory; -import javax.sql.DataSource; -import java.util.Properties; - -@Configuration -@EnableTransactionManagement -@PropertySource({ "classpath:persistence-h2.properties" }) -@ComponentScan({ "com.baeldung.persistence" }) -@EnableJpaRepositories(basePackages = "com.baeldung.persistence.dao") -public class PersistenceJPAConfig { - - @Autowired - private Environment env; - - public PersistenceJPAConfig() { - super(); - } - - // beans - - @Bean - public LocalContainerEntityManagerFactoryBean entityManagerFactory() { - final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); - em.setDataSource(dataSource()); - em.setPackagesToScan(new String[] { "com.baeldung.persistence.model" }); - - final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); - em.setJpaVendorAdapter(vendorAdapter); - em.setJpaProperties(additionalProperties()); - - return em; - } - - @Bean - public DataSource dataSource() { - final DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); - dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); - dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); - dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); - - return dataSource; - } - - @Bean - public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) { - final JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(emf); - return transactionManager; - } - - @Bean - public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { - return new PersistenceExceptionTranslationPostProcessor(); - } - - final Properties additionalProperties() { - final Properties hibernateProperties = new Properties(); - hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); - hibernateProperties.setProperty("hibernate.cache.use_second_level_cache", "false"); - - - return hibernateProperties; - } - -} \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfigXml.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfigXml.java deleted file mode 100644 index 95224a4662..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/PersistenceJPAConfigXml.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.config; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.ImportResource; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -// @Configuration -@EnableTransactionManagement -@ComponentScan({ "com.baeldung.persistence" }) -@ImportResource({ "classpath:jpaConfig.xml" }) -public class PersistenceJPAConfigXml { - - public PersistenceJPAConfigXml() { - super(); - } - -} \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/SpringWebConfig.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/SpringWebConfig.java deleted file mode 100644 index 475970d1f0..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/SpringWebConfig.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; -import org.springframework.web.servlet.view.InternalResourceViewResolver; -import org.springframework.web.servlet.view.JstlView; - -@EnableWebMvc -@Configuration -@ComponentScan({ "com.baeldung.web" }) -public class SpringWebConfig extends WebMvcConfigurerAdapter { - - @Bean - public InternalResourceViewResolver viewResolver() { - InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setViewClass(JstlView.class); - viewResolver.setPrefix("/WEB-INF/views/jsp/"); - viewResolver.setSuffix(".jsp"); - return viewResolver; - } -} diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/StudentJpaConfig.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/StudentJpaConfig.java deleted file mode 100644 index 54ced72dd1..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/StudentJpaConfig.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung.config; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.jdbc.datasource.DriverManagerDataSource; -import org.springframework.orm.jpa.JpaTransactionManager; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.persistence.EntityManagerFactory; -import javax.sql.DataSource; -import java.util.Properties; - -@Configuration -@EnableJpaRepositories(basePackages = "com.baeldung.inmemory.persistence.dao") -@PropertySource("persistence-student.properties") -@EnableTransactionManagement -public class StudentJpaConfig { - - @Autowired - private Environment env; - - @Bean - public DataSource dataSource() { - final DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName")); - dataSource.setUrl(env.getProperty("jdbc.url")); - dataSource.setUsername(env.getProperty("jdbc.user")); - dataSource.setPassword(env.getProperty("jdbc.pass")); - - return dataSource; - } - - @Bean - public LocalContainerEntityManagerFactoryBean entityManagerFactory() { - final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); - em.setDataSource(dataSource()); - em.setPackagesToScan(new String[] { "com.baeldung.inmemory.persistence.model" }); - em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); - em.setJpaProperties(additionalProperties()); - return em; - } - - @Bean - JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { - JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(entityManagerFactory); - return transactionManager; - } - - final Properties additionalProperties() { - final Properties hibernateProperties = new Properties(); - - hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); - hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); - hibernateProperties.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql")); - hibernateProperties.setProperty("hibernate.cache.use_second_level_cache", env.getProperty("hibernate.cache.use_second_level_cache")); - hibernateProperties.setProperty("hibernate.cache.use_query_cache", env.getProperty("hibernate.cache.use_query_cache")); - - return hibernateProperties; - } -} diff --git a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/WebInitializer.java b/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/WebInitializer.java deleted file mode 100644 index be81cca76b..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/java/com/baeldung/config/WebInitializer.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.config; - -import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; - -public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - @Override - protected Class[] getRootConfigClasses() { - return new Class[] { PersistenceJPAConfig.class }; - } - - @Override - protected Class[] getServletConfigClasses() { - return new Class[] { SpringWebConfig.class }; - } - - @Override - protected String[] getServletMappings() { - return new String[] { "/" }; - } -} diff --git a/persistence-modules/spring-jpa-2/src/main/resources/context.xml b/persistence-modules/spring-jpa-2/src/main/resources/context.xml deleted file mode 100644 index a64dfe9a61..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/resources/context.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/logback.xml b/persistence-modules/spring-jpa-2/src/main/resources/logback.xml deleted file mode 100644 index ec0dc2469a..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/resources/logback.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - - - - - - - - - - - - \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/persistence-h2.properties b/persistence-modules/spring-jpa-2/src/main/resources/persistence-h2.properties deleted file mode 100644 index a3060cc796..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/resources/persistence-h2.properties +++ /dev/null @@ -1,10 +0,0 @@ -# jdbc.X -jdbc.driverClassName=org.h2.Driver -jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 -jdbc.user=sa -jdbc.pass= - -# hibernate.X -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/persistence-student.properties b/persistence-modules/spring-jpa-2/src/main/resources/persistence-student.properties deleted file mode 100644 index d4c82420de..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/resources/persistence-student.properties +++ /dev/null @@ -1,11 +0,0 @@ -jdbc.driverClassName=com.mysql.cj.jdbc.Driver -jdbc.url=jdbc:mysql://localhost:3306/myDb -jdbc.user=tutorialuser -jdbc.pass=tutorialpass - -hibernate.dialect=org.hibernate.dialect.MySQL5Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop - -hibernate.cache.use_second_level_cache=false -hibernate.cache.use_query_cache=false \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/persistence.xml b/persistence-modules/spring-jpa-2/src/main/resources/persistence.xml deleted file mode 100644 index 57687c306d..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/resources/persistence.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - ${hibernate.hbm2ddl.auto} - ${hibernate.dialect} - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/server.xml b/persistence-modules/spring-jpa-2/src/main/resources/server.xml deleted file mode 100644 index 5c61659018..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/resources/server.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/main/resources/sqlfiles.properties b/persistence-modules/spring-jpa-2/src/main/resources/sqlfiles.properties deleted file mode 100644 index 0bea6adad1..0000000000 --- a/persistence-modules/spring-jpa-2/src/main/resources/sqlfiles.properties +++ /dev/null @@ -1 +0,0 @@ -spring.jpa.hibernate.ddl-auto=none \ No newline at end of file diff --git a/persistence-modules/spring-jpa-2/src/test/java/META-INF/persistence.xml b/persistence-modules/spring-jpa-2/src/test/java/META-INF/persistence.xml deleted file mode 100644 index 495f076fef..0000000000 --- a/persistence-modules/spring-jpa-2/src/test/java/META-INF/persistence.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - com.baeldung.persistence.model.Foo - com.baeldung.persistence.model.Bar - - - - - - - - - - - - - diff --git a/persistence-modules/spring-jpa-2/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/spring-jpa-2/src/test/java/com/baeldung/SpringContextTest.java deleted file mode 100644 index abc73e250d..0000000000 --- a/persistence-modules/spring-jpa-2/src/test/java/com/baeldung/SpringContextTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung; - -import com.baeldung.config.PersistenceJPAConfig; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; -import org.springframework.test.context.web.WebAppConfiguration; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { PersistenceJPAConfig.class }, loader = AnnotationConfigContextLoader.class) -@WebAppConfiguration -@DirtiesContext -public class SpringContextTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/persistence-modules/spring-jpa-2/src/test/resources/persistence-student.properties b/persistence-modules/spring-jpa-2/src/test/resources/persistence-student.properties deleted file mode 100644 index 3b6b580630..0000000000 --- a/persistence-modules/spring-jpa-2/src/test/resources/persistence-student.properties +++ /dev/null @@ -1,9 +0,0 @@ -jdbc.driverClassName=org.h2.Driver -jdbc.url=jdbc:h2:mem:myDb;DB_CLOSE_DELAY=-1 - -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create - -hibernate.cache.use_second_level_cache=false -hibernate.cache.use_query_cache=false \ No newline at end of file diff --git a/persistence-modules/spring-jpa/README.md b/persistence-modules/spring-jpa/README.md index 3eb8ae8d55..d260913635 100644 --- a/persistence-modules/spring-jpa/README.md +++ b/persistence-modules/spring-jpa/README.md @@ -1,7 +1,4 @@ -========= - -## Spring JPA Example Project - +## Spring JPA (1) ### Relevant Articles: - [The DAO with JPA and Spring](https://www.baeldung.com/spring-dao-jpa) From 1d0488b5761a1591602a374c5594298f02429b17 Mon Sep 17 00:00:00 2001 From: mikr Date: Sat, 15 Aug 2020 20:25:37 +0200 Subject: [PATCH 289/309] Java-70 Rename modules in Spring Security modules --- spring-security-modules/pom.xml | 3 +- .../README.md | 0 .../pom.xml | 4 +- .../spring-security-sso-auth-server/pom.xml | 0 .../com/baeldung/config/AuthServerConfig.java | 0 .../AuthorizationServerApplication.java | 0 .../com/baeldung/config/SecurityConfig.java | 0 .../com/baeldung/config/UserController.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/logback.xml | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../baeldung/UserInfoEndpointLiveTest.java | 0 .../spring-security-sso-kerberos/.gitignore | 0 .../spring-security-sso-kerberos/README.md | 0 .../spring-security-sso-kerberos/pom.xml | 0 .../java/com/baeldung/intro/Application.java | 0 .../intro/config/WebSecurityConfig.java | 0 .../security/DummyUserDetailsService.java | 0 .../kerberos/client/KerberosClientApp.java | 0 .../java/kerberos/client/SampleClient.java | 0 .../kerberos/client/config/AppConfig.java | 0 .../client/config/KerberosConfig.java | 0 .../java/kerberos/kdc/KerberosMiniKdc.java | 0 .../kerberos/kdc/MiniKdcConfigBuilder.java | 0 .../kerberos/server/KerberizedServerApp.java | 0 .../kerberos/server/config/MvcConfig.java | 0 .../server/config/WebSecurityConfig.java | 0 .../server/controller/SampleController.java | 0 .../service/DummyUserDetailsService.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/minikdc-krb5.conf | 0 .../src/main/resources/minikdc.ldiff | 0 .../src/main/resources/templates/hello.html | 0 .../src/main/resources/templates/home.html | 0 .../src/main/resources/templates/login.html | 0 .../client/SampleClientManualTest.java | 0 .../spring-security-sso-ui-2/pom.xml | 0 .../com/baeldung/config/UiApplication.java | 0 .../com/baeldung/config/UiSecurityConfig.java | 0 .../java/com/baeldung/config/UiWebConfig.java | 0 .../src/main/resources/application.yml | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/templates/index.html | 0 .../main/resources/templates/securedPage.html | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../spring-security-sso-ui/pom.xml | 0 .../com/baeldung/config/UiApplication.java | 0 .../com/baeldung/config/UiSecurityConfig.java | 0 .../java/com/baeldung/config/UiWebConfig.java | 0 .../src/main/resources/application.yml | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/templates/index.html | 0 .../main/resources/templates/securedPage.html | 0 .../java/com/baeldung/SpringContextTest.java | 0 .../spring-security-stormpath/README.md | 7 -- .../spring-security-stormpath/pom.xml | 68 ------------------- .../main/java/com/baeldung/Application.java | 25 ------- .../security/SecurityConfiguration.java | 24 ------- .../src/main/resources/application.properties | 6 -- .../src/main/resources/logback.xml | 13 ---- 60 files changed, 3 insertions(+), 147 deletions(-) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/README.md (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/pom.xml (92%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-auth-server/pom.xml (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthServerConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthorizationServerApplication.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-auth-server/src/main/java/com/baeldung/config/SecurityConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-auth-server/src/main/java/com/baeldung/config/UserController.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-auth-server/src/main/resources/application.properties (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-auth-server/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-auth-server/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-auth-server/src/test/java/com/baeldung/UserInfoEndpointLiveTest.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/.gitignore (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/README.md (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/pom.xml (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/Application.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/config/WebSecurityConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/security/DummyUserDetailsService.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/client/KerberosClientApp.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleClient.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/client/config/AppConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/client/config/KerberosConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/kdc/KerberosMiniKdc.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/kdc/MiniKdcConfigBuilder.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/server/KerberizedServerApp.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/server/config/MvcConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/server/config/WebSecurityConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/server/controller/SampleController.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/java/kerberos/server/service/DummyUserDetailsService.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/resources/application.properties (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/resources/minikdc-krb5.conf (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/resources/minikdc.ldiff (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/resources/templates/hello.html (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/resources/templates/home.html (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/main/resources/templates/login.html (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleClientManualTest.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui-2/pom.xml (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiApplication.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiSecurityConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiWebConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui-2/src/main/resources/application.yml (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui-2/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui-2/src/main/resources/templates/index.html (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui-2/src/main/resources/templates/securedPage.html (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui-2/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui/pom.xml (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui/src/main/java/com/baeldung/config/UiApplication.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui/src/main/java/com/baeldung/config/UiSecurityConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui/src/main/java/com/baeldung/config/UiWebConfig.java (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui/src/main/resources/application.yml (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui/src/main/resources/templates/index.html (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui/src/main/resources/templates/securedPage.html (100%) rename spring-security-modules/{spring-security-sso => spring-security-oauth2-sso}/spring-security-sso-ui/src/test/java/com/baeldung/SpringContextTest.java (100%) delete mode 100644 spring-security-modules/spring-security-stormpath/README.md delete mode 100644 spring-security-modules/spring-security-stormpath/pom.xml delete mode 100644 spring-security-modules/spring-security-stormpath/src/main/java/com/baeldung/Application.java delete mode 100644 spring-security-modules/spring-security-stormpath/src/main/java/com/baeldung/security/SecurityConfiguration.java delete mode 100644 spring-security-modules/spring-security-stormpath/src/main/resources/application.properties delete mode 100644 spring-security-modules/spring-security-stormpath/src/main/resources/logback.xml diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index d7b5844e6f..f050b48ac5 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -35,8 +35,7 @@ spring-security-rest spring-security-rest-basic-auth spring-security-rest-custom - spring-security-sso - spring-security-stormpath + spring-security-oauth2-sso spring-security-thymeleaf spring-security-x509 spring-security-kotlin-dsl diff --git a/spring-security-modules/spring-security-sso/README.md b/spring-security-modules/spring-security-oauth2-sso/README.md similarity index 100% rename from spring-security-modules/spring-security-sso/README.md rename to spring-security-modules/spring-security-oauth2-sso/README.md diff --git a/spring-security-modules/spring-security-sso/pom.xml b/spring-security-modules/spring-security-oauth2-sso/pom.xml similarity index 92% rename from spring-security-modules/spring-security-sso/pom.xml rename to spring-security-modules/spring-security-oauth2-sso/pom.xml index 4e5bb49aa3..ed4b1d64ba 100644 --- a/spring-security-modules/spring-security-sso/pom.xml +++ b/spring-security-modules/spring-security-oauth2-sso/pom.xml @@ -3,9 +3,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung - spring-security-sso + spring-security-oauth2-sso 1.0.0-SNAPSHOT - spring-security-sso + spring-security-oauth2-sso pom diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/pom.xml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/pom.xml similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/pom.xml rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/pom.xml diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthServerConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthServerConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthServerConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthServerConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthorizationServerApplication.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthorizationServerApplication.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthorizationServerApplication.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthorizationServerApplication.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/SecurityConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/SecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/SecurityConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/SecurityConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/UserController.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/UserController.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/UserController.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/UserController.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/resources/application.properties b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/resources/application.properties similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/resources/application.properties rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/resources/application.properties diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/resources/logback.xml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/resources/logback.xml rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/UserInfoEndpointLiveTest.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/UserInfoEndpointLiveTest.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/UserInfoEndpointLiveTest.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/UserInfoEndpointLiveTest.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/.gitignore b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/.gitignore similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/.gitignore rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/.gitignore diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/README.md similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/README.md diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/pom.xml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/pom.xml similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/pom.xml rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/pom.xml diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/Application.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/Application.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/Application.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/Application.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/config/WebSecurityConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/config/WebSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/config/WebSecurityConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/config/WebSecurityConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/security/DummyUserDetailsService.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/security/DummyUserDetailsService.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/security/DummyUserDetailsService.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/security/DummyUserDetailsService.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/KerberosClientApp.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/KerberosClientApp.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/KerberosClientApp.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/KerberosClientApp.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleClient.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleClient.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleClient.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/SampleClient.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/config/AppConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/config/AppConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/config/AppConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/config/AppConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/config/KerberosConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/config/KerberosConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/config/KerberosConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/client/config/KerberosConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/kdc/KerberosMiniKdc.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/kdc/KerberosMiniKdc.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/kdc/KerberosMiniKdc.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/kdc/KerberosMiniKdc.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/kdc/MiniKdcConfigBuilder.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/kdc/MiniKdcConfigBuilder.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/kdc/MiniKdcConfigBuilder.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/kdc/MiniKdcConfigBuilder.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/KerberizedServerApp.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/KerberizedServerApp.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/KerberizedServerApp.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/KerberizedServerApp.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/config/MvcConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/config/MvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/config/MvcConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/config/MvcConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/config/WebSecurityConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/config/WebSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/config/WebSecurityConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/config/WebSecurityConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/controller/SampleController.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/controller/SampleController.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/controller/SampleController.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/controller/SampleController.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/service/DummyUserDetailsService.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/service/DummyUserDetailsService.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/service/DummyUserDetailsService.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/java/kerberos/server/service/DummyUserDetailsService.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/application.properties b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/application.properties similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/application.properties rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/application.properties diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/minikdc-krb5.conf b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/minikdc-krb5.conf similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/minikdc-krb5.conf rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/minikdc-krb5.conf diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/minikdc.ldiff b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/minikdc.ldiff similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/minikdc.ldiff rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/minikdc.ldiff diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/templates/hello.html b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/templates/hello.html similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/templates/hello.html rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/templates/hello.html diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/templates/home.html b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/templates/home.html similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/templates/home.html rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/templates/home.html diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/templates/login.html b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/templates/login.html similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/resources/templates/login.html rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/main/resources/templates/login.html diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleClientManualTest.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleClientManualTest.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleClientManualTest.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-kerberos/src/test/java/kerberos/client/SampleClientManualTest.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/pom.xml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/pom.xml similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/pom.xml rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/pom.xml diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiApplication.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiApplication.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiApplication.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiApplication.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiSecurityConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiSecurityConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiSecurityConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiWebConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiWebConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiWebConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiWebConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/resources/application.yml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/application.yml similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/resources/application.yml rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/application.yml diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/resources/logback.xml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/resources/logback.xml rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/resources/templates/index.html b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/templates/index.html similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/resources/templates/index.html rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/templates/index.html diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/resources/templates/securedPage.html b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/templates/securedPage.html similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/resources/templates/securedPage.html rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/main/resources/templates/securedPage.html diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui-2/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/pom.xml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/pom.xml similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/pom.xml rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/pom.xml diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiApplication.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiApplication.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiApplication.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiApplication.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiSecurityConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiSecurityConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiSecurityConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiWebConfig.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiWebConfig.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiWebConfig.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiWebConfig.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/resources/application.yml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/application.yml similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/resources/application.yml rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/application.yml diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/resources/logback.xml b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/resources/logback.xml rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/resources/templates/index.html b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/templates/index.html similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/resources/templates/index.html rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/templates/index.html diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/resources/templates/securedPage.html b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/templates/securedPage.html similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/resources/templates/securedPage.html rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/main/resources/templates/securedPage.html diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-oauth2-sso/spring-security-sso-ui/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/spring-security-stormpath/README.md b/spring-security-modules/spring-security-stormpath/README.md deleted file mode 100644 index 971d4cc858..0000000000 --- a/spring-security-modules/spring-security-stormpath/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Spring Security Stormpath - -This module contains articles about Spring Security with Stormpath - -### Relevant articles - -- [Spring Security with Stormpath](https://www.baeldung.com/spring-security-stormpath) diff --git a/spring-security-modules/spring-security-stormpath/pom.xml b/spring-security-modules/spring-security-stormpath/pom.xml deleted file mode 100644 index 81a7c40aef..0000000000 --- a/spring-security-modules/spring-security-stormpath/pom.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - 4.0.0 - spring-security-stormpath - 1.0-SNAPSHOT - spring-security-stormpath - war - http://maven.apache.org - - - - abhinabkanrar@gmail.com - Abhinab Kanrar - https://github.com/AbhinabKanrar - abhinabkanrar - - - - - com.baeldung - parent-boot-1 - 0.0.1-SNAPSHOT - ../../parent-boot-1 - - - - - org.springframework.boot - spring-boot-starter-web - - - com.stormpath.spring - stormpath-default-spring-boot-starter - ${stormpath-spring.version} - - - - - spring-security-stormpath - - - src/main/resources - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - - - repackage - - - - - - - - - 1.5.4 - - - diff --git a/spring-security-modules/spring-security-stormpath/src/main/java/com/baeldung/Application.java b/spring-security-modules/spring-security-stormpath/src/main/java/com/baeldung/Application.java deleted file mode 100644 index 3d1409eaeb..0000000000 --- a/spring-security-modules/spring-security-stormpath/src/main/java/com/baeldung/Application.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - */ -package com.baeldung; - -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * @author abhinab - * - */ -@SpringBootApplication -public class Application implements CommandLineRunner { - - @Override - public void run(String... args) throws Exception { - } - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/spring-security-modules/spring-security-stormpath/src/main/java/com/baeldung/security/SecurityConfiguration.java b/spring-security-modules/spring-security-stormpath/src/main/java/com/baeldung/security/SecurityConfiguration.java deleted file mode 100644 index 5d75ecea8a..0000000000 --- a/spring-security-modules/spring-security-stormpath/src/main/java/com/baeldung/security/SecurityConfiguration.java +++ /dev/null @@ -1,24 +0,0 @@ -/** - * - */ -package com.baeldung.security; - -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; - -import static com.stormpath.spring.config.StormpathWebSecurityConfigurer.stormpath; - -/** - * @author abhinab - * - */ -@Configuration -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.apply(stormpath()); - } - -} diff --git a/spring-security-modules/spring-security-stormpath/src/main/resources/application.properties b/spring-security-modules/spring-security-stormpath/src/main/resources/application.properties deleted file mode 100644 index 64a9ca456c..0000000000 --- a/spring-security-modules/spring-security-stormpath/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -security.basic.enabled = false - -stormpath.web.stormpathFilter.order = 0 - -stormpath.client.apiKey.id = 668HU0EOZQ7F4MT53ND2HSGBA -stormpath.client.apiKey.secret = RPTaYX07csTJR0AMKjM462KRdiP6q037kBWoDrBC3DI diff --git a/spring-security-modules/spring-security-stormpath/src/main/resources/logback.xml b/spring-security-modules/spring-security-stormpath/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/spring-security-modules/spring-security-stormpath/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file From 3e2ce28afbdeb558d8007a308ea3e6960430800c Mon Sep 17 00:00:00 2001 From: CHANDRAKANT Kumar Date: Sun, 16 Aug 2020 01:15:24 +0530 Subject: [PATCH 290/309] Incorporated the review comments on the pull request. --- spring-webflux-threads/.gitignore | 25 ------------ spring-webflux-threads/README.md | 2 +- .../com/baeldung/webflux/Application.java | 3 ++ .../java/com/baeldung/webflux/Controller.java | 40 +++++++++---------- 4 files changed, 24 insertions(+), 46 deletions(-) delete mode 100644 spring-webflux-threads/.gitignore diff --git a/spring-webflux-threads/.gitignore b/spring-webflux-threads/.gitignore deleted file mode 100644 index 82eca336e3..0000000000 --- a/spring-webflux-threads/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/build/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ \ No newline at end of file diff --git a/spring-webflux-threads/README.md b/spring-webflux-threads/README.md index 26013d73e1..279b831a6d 100644 --- a/spring-webflux-threads/README.md +++ b/spring-webflux-threads/README.md @@ -1,7 +1,7 @@ ## Spring WebFlux Concurrency This module contains articles about concurrency model in Spring WebFlux. -Please note that this assumes Mongo and Kafka to be running on the local machine on default configurations. + ### Relevant Articles: diff --git a/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java index 1dfa00eae0..6cba90c0f4 100644 --- a/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java +++ b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java @@ -3,6 +3,9 @@ package com.baeldung.webflux; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +/** +* Please note that this assumes Mongo and Kafka to be running on the local machine on default configurations. +*/ @SpringBootApplication public class Application { diff --git a/spring-webflux-threads/src/main/java/com/baeldung/webflux/Controller.java b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Controller.java index ec6d7a596b..3c7e4e41ca 100644 --- a/spring-webflux-threads/src/main/java/com/baeldung/webflux/Controller.java +++ b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Controller.java @@ -53,31 +53,31 @@ public class Controller { @GetMapping("/threads/webclient") public Flux getThreadsWebClient() { WebClient.create("http://localhost:8080/index") - .get() - .retrieve() - .bodyToMono(String.class) - .subscribeOn(scheduler) - .publishOn(scheduler) - .doOnNext(s -> logger.info("Response: {}", s)) - .subscribe(); + .get() + .retrieve() + .bodyToMono(String.class) + .subscribeOn(scheduler) + .publishOn(scheduler) + .doOnNext(s -> logger.info("Response: {}", s)) + .subscribe(); return Flux.fromIterable(getThreads()); } @GetMapping("/threads/rxjava") public Observable getIndexRxJava() { Observable.fromIterable(Arrays.asList("Hello", "World")) - .map(s -> s.toUpperCase()) - .observeOn(io.reactivex.schedulers.Schedulers.trampoline()) - .doOnNext(s -> logger.info("String: {}", s)) - .subscribe(); + .map(s -> s.toUpperCase()) + .observeOn(io.reactivex.schedulers.Schedulers.trampoline()) + .doOnNext(s -> logger.info("String: {}", s)) + .subscribe(); return Observable.fromIterable(getThreads()); } @GetMapping("/threads/mongodb") public Flux getIndexMongo() { personRepository.findAll() - .doOnNext(p -> logger.info("Person: {}", p)) - .subscribe(); + .doOnNext(p -> logger.info("Person: {}", p)) + .subscribe(); return Flux.fromIterable(getThreads()); } @@ -90,9 +90,9 @@ public class Controller { SenderOptions senderOptions = SenderOptions.create(producerProps); KafkaSender sender = KafkaSender.create(senderOptions); Flux> outboundFlux = Flux.range(1, 10) - .map(i -> SenderRecord.create(new ProducerRecord<>("reactive-test", i, "Message_" + i), i)); + .map(i -> SenderRecord.create(new ProducerRecord<>("reactive-test", i, "Message_" + i), i)); sender.send(outboundFlux) - .subscribe(); + .subscribe(); Map consumerProps = new HashMap<>(); consumerProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); @@ -108,7 +108,7 @@ public class Controller { inboundFlux.subscribe(r -> { logger.info("Received message: {}", r.value()); r.receiverOffset() - .acknowledge(); + .acknowledge(); }); return Flux.fromIterable(getThreads()); } @@ -120,9 +120,9 @@ public class Controller { private List getThreads() { return Thread.getAllStackTraces() - .keySet() - .stream() - .map(t -> String.format("%-20s \t %s \t %d \t %s\n", t.getName(), t.getState(), t.getPriority(), t.isDaemon() ? "Daemon" : "Normal")) - .collect(Collectors.toList()); + .keySet() + .stream() + .map(t -> String.format("%-20s \t %s \t %d \t %s\n", t.getName(), t.getState(), t.getPriority(), t.isDaemon() ? "Daemon" : "Normal")) + .collect(Collectors.toList()); } } From 1ba940679a4a324aa976d2070848f2e8ed8eaaf9 Mon Sep 17 00:00:00 2001 From: mikr Date: Sat, 15 Aug 2020 22:18:01 +0200 Subject: [PATCH 291/309] Java-1460 Reduce logging created by the maven-help plugin --- maven-modules/maven-profiles/pom.xml | 40 +++++++++++++++------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/maven-modules/maven-profiles/pom.xml b/maven-modules/maven-profiles/pom.xml index 4937bc7c5d..f3aeb9d549 100644 --- a/maven-modules/maven-profiles/pom.xml +++ b/maven-modules/maven-profiles/pom.xml @@ -66,27 +66,29 @@ + + show-active-profiles + + + + org.apache.maven.plugins + maven-help-plugin + ${help.plugin.version} + + + show-profiles + compile + + active-profiles + + + + + + + - - - - org.apache.maven.plugins - maven-help-plugin - ${help.plugin.version} - - - show-profiles - compile - - active-profiles - - - - - - - 3.2.0 From bb34174aeb777da69ef019aefeb9b102d374f35f Mon Sep 17 00:00:00 2001 From: Carlos Grappa Date: Sat, 15 Aug 2020 17:59:34 -0300 Subject: [PATCH 292/309] BAEL 2881 (#9639) * BAEL-4154 IOException Too many open files * Add comment to explain GC dependency * Add HPPC, remove Colt & Trove * Add inplace iterators for fastutil and extra maps for HPPC Co-authored-by: Carlos Grappa --- .../core-java-collections-maps-2/pom.xml | 14 +--- .../map/primitives/PrimitiveMaps.java | 81 +++++++++++++------ 2 files changed, 61 insertions(+), 34 deletions(-) diff --git a/core-java-modules/core-java-collections-maps-2/pom.xml b/core-java-modules/core-java-collections-maps-2/pom.xml index a64a11c6ea..7c4ab19945 100644 --- a/core-java-modules/core-java-collections-maps-2/pom.xml +++ b/core-java-modules/core-java-collections-maps-2/pom.xml @@ -21,20 +21,15 @@ ${eclipse-collections.version} - net.sf.trove4j - trove4j - ${trove4j.version} + com.carrotsearch + hppc + ${hppc.version} it.unimi.dsi fastutil ${fastutil.version} - - colt - colt - ${colt.version} - org.apache.commons commons-lang3 @@ -69,9 +64,8 @@ 4.1 1.7.0 8.2.0 - 3.0.2 + 0.7.2 8.1.0 - 1.2.0 3.11.1 diff --git a/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/primitives/PrimitiveMaps.java b/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/primitives/PrimitiveMaps.java index 30bec12ccc..e53290f93a 100644 --- a/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/primitives/PrimitiveMaps.java +++ b/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/primitives/PrimitiveMaps.java @@ -1,29 +1,68 @@ package com.baeldung.map.primitives; -import cern.colt.map.AbstractIntDoubleMap; -import cern.colt.map.OpenIntDoubleHashMap; -import gnu.trove.map.TDoubleIntMap; -import gnu.trove.map.hash.TDoubleIntHashMap; +import com.carrotsearch.hppc.IntLongHashMap; +import com.carrotsearch.hppc.IntLongScatterMap; +import com.carrotsearch.hppc.IntObjectHashMap; +import com.carrotsearch.hppc.IntObjectMap; +import com.carrotsearch.hppc.IntObjectScatterMap; + import it.unimi.dsi.fastutil.ints.Int2BooleanMap; +import it.unimi.dsi.fastutil.ints.Int2BooleanMaps; import it.unimi.dsi.fastutil.ints.Int2BooleanOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2BooleanSortedMap; import it.unimi.dsi.fastutil.ints.Int2BooleanSortedMaps; +import it.unimi.dsi.fastutil.objects.ObjectIterator; + import org.eclipse.collections.api.map.primitive.ImmutableIntIntMap; import org.eclipse.collections.api.map.primitive.MutableIntIntMap; import org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap; import org.eclipse.collections.impl.factory.primitive.IntIntMaps; import org.eclipse.collections.impl.factory.primitive.ObjectDoubleMaps; +import static java.lang.String.format; + +import java.math.BigDecimal; + public class PrimitiveMaps { public static void main(String[] args) { + hppcMap(); eclipseCollectionsMap(); - troveMap(); - coltMap(); fastutilMap(); } + private static void hppcMap() { + //Regular maps + IntLongHashMap intLongHashMap = new IntLongHashMap(); + intLongHashMap.put(25,1L); + intLongHashMap.put(150,Long.MAX_VALUE); + intLongHashMap.put(1,0L); + + intLongHashMap.get(150); + + IntObjectMap intObjectMap = new IntObjectHashMap(); + intObjectMap.put(1, BigDecimal.valueOf(1)); + intObjectMap.put(2, BigDecimal.valueOf(2500)); + + BigDecimal value = intObjectMap.get(2); + + //Scatter maps + IntLongScatterMap intLongScatterMap = new IntLongScatterMap(); + intLongScatterMap.put(1, 1L); + intLongScatterMap.put(2, -2L); + intLongScatterMap.put(1000,0L); + + intLongScatterMap.get(1000); + + IntObjectScatterMap intObjectScatterMap = new IntObjectScatterMap(); + intObjectScatterMap.put(1, BigDecimal.valueOf(1)); + intObjectScatterMap.put(2, BigDecimal.valueOf(2500)); + + value = intObjectScatterMap.get(2); + } + + private static void fastutilMap() { Int2BooleanMap int2BooleanMap = new Int2BooleanOpenHashMap(); int2BooleanMap.put(1, true); @@ -32,13 +71,19 @@ public class PrimitiveMaps { boolean value = int2BooleanMap.get(1); - Int2BooleanSortedMap int2BooleanSorted = Int2BooleanSortedMaps.EMPTY_MAP; - } + //Lambda style iteration + Int2BooleanMaps.fastForEach(int2BooleanMap, entry -> { + System.out.println(String.format("Key: %d, Value: %b",entry.getIntKey(),entry.getBooleanValue())); + }); + + //Iterator based loop + ObjectIterator iterator = Int2BooleanMaps.fastIterator(int2BooleanMap); + while(iterator.hasNext()) { + Int2BooleanMap.Entry entry = iterator.next(); + System.out.println(String.format("Key: %d, Value: %b",entry.getIntKey(),entry.getBooleanValue())); + + } - private static void coltMap() { - AbstractIntDoubleMap map = new OpenIntDoubleHashMap(); - map.put(1, 4.5); - double value = map.get(1); } private static void eclipseCollectionsMap() { @@ -53,17 +98,5 @@ public class PrimitiveMaps { dObject.addToValue("stability", 0.8); } - private static void troveMap() { - double[] doubles = new double[] {1.2, 4.5, 0.3}; - int[] ints = new int[] {1, 4, 0}; - TDoubleIntMap doubleIntMap = new TDoubleIntHashMap(doubles, ints); - - doubleIntMap.put(1.2, 22); - doubleIntMap.put(4.5, 16); - - doubleIntMap.adjustValue(1.2, 1); - doubleIntMap.adjustValue(4.5, 4); - doubleIntMap.adjustValue(0.3, 7); - } } From 44afb00d224caffb9259e1b714dde051a49ae06b Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sun, 16 Aug 2020 08:46:46 +0530 Subject: [PATCH 293/309] Update README.md --- core-java-modules/core-java/README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core-java-modules/core-java/README.md b/core-java-modules/core-java/README.md index 7781382ae5..b0e740e3b5 100644 --- a/core-java-modules/core-java/README.md +++ b/core-java-modules/core-java/README.md @@ -1,13 +1,13 @@ ## Core Java Cookbooks and Examples ### Relevant Articles: -[Getting Started with Java Properties](http://www.baeldung.com/java-properties) -[Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency) -[Introduction to Java Serialization](http://www.baeldung.com/java-serialization) -[Guide to UUID in Java](http://www.baeldung.com/java-uuid) -[Compiling Java *.class Files with javac](http://www.baeldung.com/javac) -[Introduction to Javadoc](http://www.baeldung.com/javadoc) -[Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable) -[What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid) -[A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle) -[Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties) +- [Getting Started with Java Properties](http://www.baeldung.com/java-properties) +- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency) +- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization) +- [Guide to UUID in Java](http://www.baeldung.com/java-uuid) +- [Compiling Java *.class Files with javac](http://www.baeldung.com/javac) +- [Introduction to Javadoc](http://www.baeldung.com/javadoc) +- [Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable) +- [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid) +- [A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle) +- [Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties) From 1e96de4b6417fb73b1413807bcb2a99584ab19cd Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sun, 16 Aug 2020 13:35:04 +0530 Subject: [PATCH 294/309] Update pom.xml Adding spring-data-cosmosdb module in the persistence module --- persistence-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index f1154f203b..8544a5cef4 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -53,6 +53,7 @@ spring-boot-persistence-mongodb spring-data-cassandra spring-data-cassandra-reactive + spring-data-cosmosdb spring-data-couchbase-2 spring-data-dynamodb spring-data-eclipselink From 5eefa6b148b318378552ab24d4134cd97b84591c Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Sun, 16 Aug 2020 13:36:23 +0530 Subject: [PATCH 295/309] Update pom.xml removing extra spaces --- persistence-modules/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 8544a5cef4..a9d3c89604 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -53,7 +53,7 @@ spring-boot-persistence-mongodb spring-data-cassandra spring-data-cassandra-reactive - spring-data-cosmosdb + spring-data-cosmosdb spring-data-couchbase-2 spring-data-dynamodb spring-data-eclipselink From ecaa8db1421fc0af794b983c309b35fe16adf6b4 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 16 Aug 2020 16:30:53 +0530 Subject: [PATCH 296/309] JAVA-68: Renamed spring-security-mvc-jsonview to spring-security-web-jsonview --- .../.gitignore | 0 .../README.md | 0 .../pom.xml | 4 ++-- .../src/main/java/com/baeldung/AppInitializer.java | 0 .../main/java/com/baeldung/controller/ItemsController.java | 0 .../src/main/java/com/baeldung/controller/View.java | 0 .../src/main/java/com/baeldung/model/Item.java | 0 .../src/main/java/com/baeldung/spring/AppConfig.java | 0 .../com/baeldung/spring/SecurityJsonViewControllerAdvice.java | 0 .../src/main/resources/logback.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../security/SpringSecurityJsonViewIntegrationTest.java | 0 12 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/.gitignore (100%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/README.md (100%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/pom.xml (98%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/src/main/java/com/baeldung/AppInitializer.java (100%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/src/main/java/com/baeldung/controller/ItemsController.java (100%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/src/main/java/com/baeldung/controller/View.java (100%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/src/main/java/com/baeldung/model/Item.java (100%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/src/main/java/com/baeldung/spring/AppConfig.java (100%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java (100%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-mvc-jsonview => spring-security-web-jsonview}/src/test/java/com/baeldung/security/SpringSecurityJsonViewIntegrationTest.java (100%) diff --git a/spring-security-modules/spring-security-mvc-jsonview/.gitignore b/spring-security-modules/spring-security-web-jsonview/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/.gitignore rename to spring-security-modules/spring-security-web-jsonview/.gitignore diff --git a/spring-security-modules/spring-security-mvc-jsonview/README.md b/spring-security-modules/spring-security-web-jsonview/README.md similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/README.md rename to spring-security-modules/spring-security-web-jsonview/README.md diff --git a/spring-security-modules/spring-security-mvc-jsonview/pom.xml b/spring-security-modules/spring-security-web-jsonview/pom.xml similarity index 98% rename from spring-security-modules/spring-security-mvc-jsonview/pom.xml rename to spring-security-modules/spring-security-web-jsonview/pom.xml index f6ba997c62..0d1b0b09db 100644 --- a/spring-security-modules/spring-security-mvc-jsonview/pom.xml +++ b/spring-security-modules/spring-security-web-jsonview/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - spring-security-mvc-jsonview + spring-security-web-jsonview 0.1-SNAPSHOT - spring-security-mvc-jsonview + spring-security-web-jsonview war diff --git a/spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/AppInitializer.java b/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/AppInitializer.java similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/AppInitializer.java rename to spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/AppInitializer.java diff --git a/spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/controller/ItemsController.java b/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/controller/ItemsController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/controller/ItemsController.java rename to spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/controller/ItemsController.java diff --git a/spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/controller/View.java b/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/controller/View.java similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/controller/View.java rename to spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/controller/View.java diff --git a/spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/model/Item.java b/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/model/Item.java similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/model/Item.java rename to spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/model/Item.java diff --git a/spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/spring/AppConfig.java b/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/spring/AppConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/spring/AppConfig.java rename to spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/spring/AppConfig.java diff --git a/spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java b/spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java rename to spring-security-modules/spring-security-web-jsonview/src/main/java/com/baeldung/spring/SecurityJsonViewControllerAdvice.java diff --git a/spring-security-modules/spring-security-mvc-jsonview/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-jsonview/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-jsonview/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-mvc-jsonview/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/spring-security-mvc-jsonview/src/test/java/com/baeldung/security/SpringSecurityJsonViewIntegrationTest.java b/spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/security/SpringSecurityJsonViewIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-jsonview/src/test/java/com/baeldung/security/SpringSecurityJsonViewIntegrationTest.java rename to spring-security-modules/spring-security-web-jsonview/src/test/java/com/baeldung/security/SpringSecurityJsonViewIntegrationTest.java From 3e193877e67b849c8c7c587e86e1916d925b1fb9 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 16 Aug 2020 16:31:42 +0530 Subject: [PATCH 297/309] JAVA-68: Renamed spring-security-mvc-login to spring-security-web-login --- .../.gitignore | 0 .../README.md | 0 .../pom.xml | 4 ++-- .../src/main/java/com/baeldung/AppInitializer.java | 0 .../com/baeldung/controller/SecuredResourceController.java | 0 .../java/com/baeldung/security/CustomAccessDeniedHandler.java | 0 .../baeldung/security/CustomAuthenticationFailureHandler.java | 0 .../com/baeldung/security/CustomLogoutSuccessHandler.java | 0 .../security/RefererAuthenticationSuccessHandler.java | 0 .../java/com/baeldung/security/config/SecSecurityConfig.java | 0 .../java/com/baeldung/spring/ChannelSecSecurityConfig.java | 0 .../src/main/java/com/baeldung/spring/MvcConfig.java | 0 .../java/com/baeldung/spring/RedirectionSecurityConfig.java | 0 .../src/main/resources/RedirectionWebSecurityConfig.xml | 0 .../src/main/resources/channelWebSecurityConfig.xml | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/webSecurityConfig.xml | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/accessDenied.jsp | 0 .../src/main/webapp/WEB-INF/view/admin/adminpage.jsp | 0 .../src/main/webapp/WEB-INF/view/anonymous.jsp | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/view/login.jsp | 0 .../src/main/webapp/WEB-INF/web-old.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../test/java/com/baeldung/security/FormLoginUnitTest.java | 0 .../baeldung/security/RedirectionSecurityIntegrationTest.java | 0 .../src/test/resources/.gitignore | 0 28 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/.gitignore (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/README.md (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/pom.xml (98%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/java/com/baeldung/AppInitializer.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/java/com/baeldung/controller/SecuredResourceController.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/java/com/baeldung/security/CustomAccessDeniedHandler.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/java/com/baeldung/security/CustomAuthenticationFailureHandler.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/java/com/baeldung/security/CustomLogoutSuccessHandler.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/java/com/baeldung/security/RefererAuthenticationSuccessHandler.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/java/com/baeldung/security/config/SecSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/java/com/baeldung/spring/ChannelSecSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/java/com/baeldung/spring/MvcConfig.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/java/com/baeldung/spring/RedirectionSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/resources/RedirectionWebSecurityConfig.xml (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/resources/channelWebSecurityConfig.xml (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/resources/webSecurityConfig.xml (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/webapp/WEB-INF/view/accessDenied.jsp (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/webapp/WEB-INF/view/admin/adminpage.jsp (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/webapp/WEB-INF/view/anonymous.jsp (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/webapp/WEB-INF/view/login.jsp (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/main/webapp/WEB-INF/web-old.xml (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/test/java/com/baeldung/security/FormLoginUnitTest.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/test/java/com/baeldung/security/RedirectionSecurityIntegrationTest.java (100%) rename spring-security-modules/{spring-security-mvc-login => spring-security-web-login}/src/test/resources/.gitignore (100%) diff --git a/spring-security-modules/spring-security-mvc-login/.gitignore b/spring-security-modules/spring-security-web-login/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc-login/.gitignore rename to spring-security-modules/spring-security-web-login/.gitignore diff --git a/spring-security-modules/spring-security-mvc-login/README.md b/spring-security-modules/spring-security-web-login/README.md similarity index 100% rename from spring-security-modules/spring-security-mvc-login/README.md rename to spring-security-modules/spring-security-web-login/README.md diff --git a/spring-security-modules/spring-security-mvc-login/pom.xml b/spring-security-modules/spring-security-web-login/pom.xml similarity index 98% rename from spring-security-modules/spring-security-mvc-login/pom.xml rename to spring-security-modules/spring-security-web-login/pom.xml index 4e0fe00176..2b64d157d3 100644 --- a/spring-security-modules/spring-security-mvc-login/pom.xml +++ b/spring-security-modules/spring-security-web-login/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - spring-security-mvc-login + spring-security-web-login 0.1-SNAPSHOT - spring-security-mvc-login + spring-security-web-login war diff --git a/spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/AppInitializer.java b/spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/AppInitializer.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/AppInitializer.java rename to spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/AppInitializer.java diff --git a/spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/controller/SecuredResourceController.java b/spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/controller/SecuredResourceController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/controller/SecuredResourceController.java rename to spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/controller/SecuredResourceController.java diff --git a/spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomAccessDeniedHandler.java b/spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/security/CustomAccessDeniedHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomAccessDeniedHandler.java rename to spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/security/CustomAccessDeniedHandler.java diff --git a/spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomAuthenticationFailureHandler.java b/spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/security/CustomAuthenticationFailureHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomAuthenticationFailureHandler.java rename to spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/security/CustomAuthenticationFailureHandler.java diff --git a/spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomLogoutSuccessHandler.java b/spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/security/CustomLogoutSuccessHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomLogoutSuccessHandler.java rename to spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/security/CustomLogoutSuccessHandler.java diff --git a/spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/security/RefererAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/security/RefererAuthenticationSuccessHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/security/RefererAuthenticationSuccessHandler.java rename to spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/security/RefererAuthenticationSuccessHandler.java diff --git a/spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/security/config/SecSecurityConfig.java b/spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/security/config/SecSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/security/config/SecSecurityConfig.java rename to spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/security/config/SecSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/spring/ChannelSecSecurityConfig.java b/spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/spring/ChannelSecSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/spring/ChannelSecSecurityConfig.java rename to spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/spring/ChannelSecSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/spring/MvcConfig.java b/spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/spring/MvcConfig.java rename to spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/spring/MvcConfig.java diff --git a/spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/spring/RedirectionSecurityConfig.java b/spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/spring/RedirectionSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/java/com/baeldung/spring/RedirectionSecurityConfig.java rename to spring-security-modules/spring-security-web-login/src/main/java/com/baeldung/spring/RedirectionSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-login/src/main/resources/RedirectionWebSecurityConfig.xml b/spring-security-modules/spring-security-web-login/src/main/resources/RedirectionWebSecurityConfig.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/resources/RedirectionWebSecurityConfig.xml rename to spring-security-modules/spring-security-web-login/src/main/resources/RedirectionWebSecurityConfig.xml diff --git a/spring-security-modules/spring-security-mvc-login/src/main/resources/channelWebSecurityConfig.xml b/spring-security-modules/spring-security-web-login/src/main/resources/channelWebSecurityConfig.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/resources/channelWebSecurityConfig.xml rename to spring-security-modules/spring-security-web-login/src/main/resources/channelWebSecurityConfig.xml diff --git a/spring-security-modules/spring-security-mvc-login/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-login/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-login/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-mvc-login/src/main/resources/webSecurityConfig.xml b/spring-security-modules/spring-security-web-login/src/main/resources/webSecurityConfig.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/resources/webSecurityConfig.xml rename to spring-security-modules/spring-security-web-login/src/main/resources/webSecurityConfig.xml diff --git a/spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/view/accessDenied.jsp b/spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/view/accessDenied.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/view/accessDenied.jsp rename to spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/view/accessDenied.jsp diff --git a/spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/view/admin/adminpage.jsp b/spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/view/admin/adminpage.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/view/admin/adminpage.jsp rename to spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/view/admin/adminpage.jsp diff --git a/spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/view/anonymous.jsp b/spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/view/anonymous.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/view/anonymous.jsp rename to spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/view/anonymous.jsp diff --git a/spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/view/login.jsp b/spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/view/login.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/view/login.jsp rename to spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/view/login.jsp diff --git a/spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/web-old.xml b/spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/web-old.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/main/webapp/WEB-INF/web-old.xml rename to spring-security-modules/spring-security-web-login/src/main/webapp/WEB-INF/web-old.xml diff --git a/spring-security-modules/spring-security-mvc-login/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-web-login/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-web-login/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/spring-security-mvc-login/src/test/java/com/baeldung/security/FormLoginUnitTest.java b/spring-security-modules/spring-security-web-login/src/test/java/com/baeldung/security/FormLoginUnitTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/test/java/com/baeldung/security/FormLoginUnitTest.java rename to spring-security-modules/spring-security-web-login/src/test/java/com/baeldung/security/FormLoginUnitTest.java diff --git a/spring-security-modules/spring-security-mvc-login/src/test/java/com/baeldung/security/RedirectionSecurityIntegrationTest.java b/spring-security-modules/spring-security-web-login/src/test/java/com/baeldung/security/RedirectionSecurityIntegrationTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/test/java/com/baeldung/security/RedirectionSecurityIntegrationTest.java rename to spring-security-modules/spring-security-web-login/src/test/java/com/baeldung/security/RedirectionSecurityIntegrationTest.java diff --git a/spring-security-modules/spring-security-mvc-login/src/test/resources/.gitignore b/spring-security-modules/spring-security-web-login/src/test/resources/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc-login/src/test/resources/.gitignore rename to spring-security-modules/spring-security-web-login/src/test/resources/.gitignore From f645cac5d6b05d52a8feb61b3a487abe689819fa Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 16 Aug 2020 16:32:25 +0530 Subject: [PATCH 298/309] JAVA-68: Renamed spring-security-mvc-persisted-remember-me to spring-security-web-persisted-remember-me --- .../.gitignore | 0 .../README.md | 0 .../pom.xml | 4 ++-- .../src/main/java/com/baeldung/controller/MyController.java | 0 .../security/MySimpleUrlAuthenticationSuccessHandler.java | 0 .../src/main/java/com/baeldung/security/SecurityRole.java | 0 .../baeldung/security/SecurityWebApplicationInitializer.java | 0 .../main/java/com/baeldung/service/MyUserDetailsService.java | 0 .../src/main/java/com/baeldung/spring/MvcConfig.java | 0 .../src/main/java/com/baeldung/spring/PersistenceConfig.java | 0 .../src/main/java/com/baeldung/spring/SecurityConfig.java | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/persisted_logins_create_table.sql | 0 .../src/main/resources/persistence-h2.properties | 0 .../src/main/resources/persistence-postgres.properties | 0 .../src/main/resources/webSecurityConfig.xml | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/anonymous.jsp | 0 .../src/main/webapp/WEB-INF/view/console.jsp | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/view/login.jsp | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 .../src/test/resources/.gitignore | 0 24 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/.gitignore (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/README.md (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/pom.xml (98%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/java/com/baeldung/controller/MyController.java (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/java/com/baeldung/security/SecurityRole.java (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/java/com/baeldung/service/MyUserDetailsService.java (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/java/com/baeldung/spring/MvcConfig.java (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/java/com/baeldung/spring/PersistenceConfig.java (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/java/com/baeldung/spring/SecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/resources/persisted_logins_create_table.sql (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/resources/persistence-h2.properties (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/resources/persistence-postgres.properties (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/resources/webSecurityConfig.xml (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/webapp/WEB-INF/view/anonymous.jsp (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/webapp/WEB-INF/view/console.jsp (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/webapp/WEB-INF/view/login.jsp (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/main/webapp/WEB-INF/web.xml (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/test/java/com/baeldung/SpringContextTest.java (100%) rename spring-security-modules/{spring-security-mvc-persisted-remember-me => spring-security-web-persisted-remember-me}/src/test/resources/.gitignore (100%) diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/.gitignore b/spring-security-modules/spring-security-web-persisted-remember-me/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/.gitignore rename to spring-security-modules/spring-security-web-persisted-remember-me/.gitignore diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/README.md b/spring-security-modules/spring-security-web-persisted-remember-me/README.md similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/README.md rename to spring-security-modules/spring-security-web-persisted-remember-me/README.md diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/pom.xml b/spring-security-modules/spring-security-web-persisted-remember-me/pom.xml similarity index 98% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/pom.xml rename to spring-security-modules/spring-security-web-persisted-remember-me/pom.xml index 9410793222..25c5ddd9d0 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/pom.xml +++ b/spring-security-modules/spring-security-web-persisted-remember-me/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - spring-security-mvc-persisted-remember-me + spring-security-web-persisted-remember-me 0.1-SNAPSHOT - spring-security-mvc-persisted-remember-me + spring-security-web-persisted-remember-me war diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/controller/MyController.java b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/controller/MyController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/controller/MyController.java rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/controller/MyController.java diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/SecurityRole.java b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/security/SecurityRole.java similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/SecurityRole.java rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/security/SecurityRole.java diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/service/MyUserDetailsService.java b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/service/MyUserDetailsService.java similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/service/MyUserDetailsService.java rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/service/MyUserDetailsService.java diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/MvcConfig.java b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/MvcConfig.java rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/spring/MvcConfig.java diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/PersistenceConfig.java b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/spring/PersistenceConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/PersistenceConfig.java rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/spring/PersistenceConfig.java diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/SecurityConfig.java b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/spring/SecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/SecurityConfig.java rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/java/com/baeldung/spring/SecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/resources/persisted_logins_create_table.sql b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/resources/persisted_logins_create_table.sql similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/resources/persisted_logins_create_table.sql rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/resources/persisted_logins_create_table.sql diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/resources/persistence-h2.properties b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/resources/persistence-h2.properties rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/resources/persistence-h2.properties diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/resources/persistence-postgres.properties b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/resources/persistence-postgres.properties similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/resources/persistence-postgres.properties rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/resources/persistence-postgres.properties diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/resources/webSecurityConfig.xml b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/resources/webSecurityConfig.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/resources/webSecurityConfig.xml rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/resources/webSecurityConfig.xml diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/view/anonymous.jsp b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/view/anonymous.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/view/anonymous.jsp rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/view/anonymous.jsp diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/view/console.jsp b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/view/console.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/view/console.jsp rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/view/console.jsp diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/view/login.jsp b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/view/login.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/view/login.jsp rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/view/login.jsp diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/web.xml rename to spring-security-modules/spring-security-web-persisted-remember-me/src/main/webapp/WEB-INF/web.xml diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-web-persisted-remember-me/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-web-persisted-remember-me/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/resources/.gitignore b/spring-security-modules/spring-security-web-persisted-remember-me/src/test/resources/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/resources/.gitignore rename to spring-security-modules/spring-security-web-persisted-remember-me/src/test/resources/.gitignore From d35dfb6ba9fa6b97a7440a2f2ec82aa77d2581ac Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 16 Aug 2020 16:32:56 +0530 Subject: [PATCH 299/309] JAVA-68: Renamed spring-security-mvc-socket to spring-security-web-sockets --- .../.gitignore | 0 .../README.md | 0 .../pom.xml | 4 ++-- .../java/com/baeldung/springsecuredsockets/Constants.java | 0 .../com/baeldung/springsecuredsockets/config/AppConfig.java | 0 .../baeldung/springsecuredsockets/config/DataStoreConfig.java | 0 .../baeldung/springsecuredsockets/config/SecurityConfig.java | 0 .../springsecuredsockets/config/SocketBrokerConfig.java | 0 .../springsecuredsockets/config/SocketSecurityConfig.java | 0 .../springsecuredsockets/config/WebAppInitializer.java | 0 .../springsecuredsockets/controllers/CsrfTokenController.java | 0 .../springsecuredsockets/controllers/SocketController.java | 0 .../java/com/baeldung/springsecuredsockets/domain/Role.java | 0 .../java/com/baeldung/springsecuredsockets/domain/User.java | 0 .../springsecuredsockets/repositories/UserRepository.java | 0 .../security/CustomAccessDeniedHandler.java | 0 .../security/CustomDaoAuthenticationProvider.java | 0 .../security/CustomLoginSuccessHandler.java | 0 .../security/CustomLogoutSuccessHandler.java | 0 .../security/CustomUserDetailsService.java | 0 .../security/SecurityWebApplicationInitializer.java | 0 .../springsecuredsockets/transfer/socket/Message.java | 0 .../springsecuredsockets/transfer/socket/OutputMessage.java | 0 .../springsecuredsockets/transfer/user/CustomUserDetails.java | 0 .../springsockets/config/WebSocketMessageBrokerConfig.java | 0 .../baeldung/springsockets/controllers/RestAPIController.java | 0 .../springsockets/controllers/WebSocketController.java | 0 .../main/java/com/baeldung/springsockets/models/Greeting.java | 0 .../main/java/com/baeldung/springsockets/models/Message.java | 0 .../src/main/resources/data.sql | 0 .../src/main/resources/logback.xml | 0 .../src/main/resources/schema.sql | 0 .../src/main/resources/static/rest.html | 0 .../src/main/resources/static/rest.js | 0 .../src/main/resources/static/ws.html | 0 .../src/main/resources/static/ws.js | 0 .../src/main/webapp/WEB-INF/jsp/denied.jsp | 0 .../src/main/webapp/WEB-INF/jsp/index.jsp | 0 .../src/main/webapp/WEB-INF/jsp/login.jsp | 0 .../src/main/webapp/WEB-INF/jsp/socket.jsp | 0 .../src/main/webapp/WEB-INF/jsp/success.jsp | 0 .../src/main/webapp/resources/scripts/app.js | 0 .../webapp/resources/scripts/controllers/indexController.js | 0 .../webapp/resources/scripts/controllers/socketController.js | 0 .../webapp/resources/scripts/controllers/successController.js | 0 .../src/main/webapp/resources/scripts/routes/router.js | 0 .../main/webapp/resources/scripts/services/SocketService.js | 0 .../src/main/webapp/resources/styles/app.css | 0 .../src/main/webapp/resources/styles/denied.css | 0 .../src/main/webapp/resources/styles/index.css | 0 .../src/main/webapp/resources/styles/login.css | 0 .../src/main/webapp/resources/styles/socket.css | 0 .../src/main/webapp/resources/styles/success.css | 0 .../main/webapp/resources/vendor/angular/angular-route.min.js | 0 .../webapp/resources/vendor/angular/angular-route.min.js.map | 0 .../src/main/webapp/resources/vendor/angular/angular.min.js | 0 .../main/webapp/resources/vendor/angular/angular.min.js.map | 0 .../src/main/webapp/resources/vendor/jquery/jquery.min.js | 0 .../src/main/webapp/resources/vendor/sockjs/sockjs.min.js | 0 .../src/main/webapp/resources/vendor/sockjs/sockjs.min.js.map | 0 .../src/main/webapp/resources/vendor/stomp/stomp.min.js | 0 .../src/test/java/com/baeldung/SpringContextTest.java | 0 62 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/.gitignore (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/README.md (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/pom.xml (98%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/Constants.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/config/AppConfig.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/config/DataStoreConfig.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/config/SecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/config/SocketBrokerConfig.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/config/SocketSecurityConfig.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/config/WebAppInitializer.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/controllers/CsrfTokenController.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/controllers/SocketController.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/domain/Role.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/domain/User.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/repositories/UserRepository.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/security/CustomAccessDeniedHandler.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/security/CustomDaoAuthenticationProvider.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/security/CustomLoginSuccessHandler.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/security/CustomLogoutSuccessHandler.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/security/CustomUserDetailsService.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/security/SecurityWebApplicationInitializer.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/transfer/socket/Message.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/transfer/socket/OutputMessage.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsecuredsockets/transfer/user/CustomUserDetails.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsockets/config/WebSocketMessageBrokerConfig.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsockets/controllers/RestAPIController.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsockets/controllers/WebSocketController.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsockets/models/Greeting.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/java/com/baeldung/springsockets/models/Message.java (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/resources/data.sql (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/resources/schema.sql (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/resources/static/rest.html (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/resources/static/rest.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/resources/static/ws.html (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/resources/static/ws.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/WEB-INF/jsp/denied.jsp (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/WEB-INF/jsp/index.jsp (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/WEB-INF/jsp/login.jsp (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/WEB-INF/jsp/socket.jsp (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/WEB-INF/jsp/success.jsp (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/scripts/app.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/scripts/controllers/indexController.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/scripts/controllers/socketController.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/scripts/controllers/successController.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/scripts/routes/router.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/scripts/services/SocketService.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/styles/app.css (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/styles/denied.css (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/styles/index.css (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/styles/login.css (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/styles/socket.css (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/styles/success.css (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/vendor/angular/angular-route.min.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/vendor/angular/angular-route.min.js.map (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/vendor/angular/angular.min.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/vendor/angular/angular.min.js.map (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/vendor/jquery/jquery.min.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/vendor/sockjs/sockjs.min.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/vendor/sockjs/sockjs.min.js.map (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/main/webapp/resources/vendor/stomp/stomp.min.js (100%) rename spring-security-modules/{spring-security-mvc-socket => spring-security-web-sockets}/src/test/java/com/baeldung/SpringContextTest.java (100%) diff --git a/spring-security-modules/spring-security-mvc-socket/.gitignore b/spring-security-modules/spring-security-web-sockets/.gitignore similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/.gitignore rename to spring-security-modules/spring-security-web-sockets/.gitignore diff --git a/spring-security-modules/spring-security-mvc-socket/README.md b/spring-security-modules/spring-security-web-sockets/README.md similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/README.md rename to spring-security-modules/spring-security-web-sockets/README.md diff --git a/spring-security-modules/spring-security-mvc-socket/pom.xml b/spring-security-modules/spring-security-web-sockets/pom.xml similarity index 98% rename from spring-security-modules/spring-security-mvc-socket/pom.xml rename to spring-security-modules/spring-security-web-sockets/pom.xml index 6515121f9f..3a3ec47af5 100644 --- a/spring-security-modules/spring-security-mvc-socket/pom.xml +++ b/spring-security-modules/spring-security-web-sockets/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 com.baeldung.springsecuredsockets - spring-security-mvc-socket + spring-security-web-sockets 1.0.0 - spring-security-mvc-socket + spring-security-web-sockets war diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/Constants.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/Constants.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/Constants.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/Constants.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/AppConfig.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/AppConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/AppConfig.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/AppConfig.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/DataStoreConfig.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/DataStoreConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/DataStoreConfig.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/DataStoreConfig.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/SecurityConfig.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/SecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/SecurityConfig.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/SecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/SocketBrokerConfig.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/SocketBrokerConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/SocketBrokerConfig.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/SocketBrokerConfig.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/SocketSecurityConfig.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/SocketSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/SocketSecurityConfig.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/SocketSecurityConfig.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/WebAppInitializer.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/WebAppInitializer.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/config/WebAppInitializer.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/config/WebAppInitializer.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/controllers/CsrfTokenController.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/controllers/CsrfTokenController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/controllers/CsrfTokenController.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/controllers/CsrfTokenController.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/controllers/SocketController.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/controllers/SocketController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/controllers/SocketController.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/controllers/SocketController.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/domain/Role.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/domain/Role.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/domain/Role.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/domain/Role.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/domain/User.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/domain/User.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/domain/User.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/domain/User.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/repositories/UserRepository.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/repositories/UserRepository.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/repositories/UserRepository.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/repositories/UserRepository.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/CustomAccessDeniedHandler.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/CustomAccessDeniedHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/CustomAccessDeniedHandler.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/CustomAccessDeniedHandler.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/CustomDaoAuthenticationProvider.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/CustomDaoAuthenticationProvider.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/CustomDaoAuthenticationProvider.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/CustomDaoAuthenticationProvider.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/CustomLoginSuccessHandler.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/CustomLoginSuccessHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/CustomLoginSuccessHandler.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/CustomLoginSuccessHandler.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/CustomLogoutSuccessHandler.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/CustomLogoutSuccessHandler.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/CustomLogoutSuccessHandler.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/CustomLogoutSuccessHandler.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/CustomUserDetailsService.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/CustomUserDetailsService.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/CustomUserDetailsService.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/CustomUserDetailsService.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/SecurityWebApplicationInitializer.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/SecurityWebApplicationInitializer.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/security/SecurityWebApplicationInitializer.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/security/SecurityWebApplicationInitializer.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/transfer/socket/Message.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/transfer/socket/Message.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/transfer/socket/Message.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/transfer/socket/Message.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/transfer/socket/OutputMessage.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/transfer/socket/OutputMessage.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/transfer/socket/OutputMessage.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/transfer/socket/OutputMessage.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/transfer/user/CustomUserDetails.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/transfer/user/CustomUserDetails.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsecuredsockets/transfer/user/CustomUserDetails.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsecuredsockets/transfer/user/CustomUserDetails.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsockets/config/WebSocketMessageBrokerConfig.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsockets/config/WebSocketMessageBrokerConfig.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsockets/config/WebSocketMessageBrokerConfig.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsockets/config/WebSocketMessageBrokerConfig.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsockets/controllers/RestAPIController.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsockets/controllers/RestAPIController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsockets/controllers/RestAPIController.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsockets/controllers/RestAPIController.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsockets/controllers/WebSocketController.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsockets/controllers/WebSocketController.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsockets/controllers/WebSocketController.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsockets/controllers/WebSocketController.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsockets/models/Greeting.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsockets/models/Greeting.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsockets/models/Greeting.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsockets/models/Greeting.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsockets/models/Message.java b/spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsockets/models/Message.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/java/com/baeldung/springsockets/models/Message.java rename to spring-security-modules/spring-security-web-sockets/src/main/java/com/baeldung/springsockets/models/Message.java diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/resources/data.sql b/spring-security-modules/spring-security-web-sockets/src/main/resources/data.sql similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/resources/data.sql rename to spring-security-modules/spring-security-web-sockets/src/main/resources/data.sql diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-sockets/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-sockets/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/resources/schema.sql b/spring-security-modules/spring-security-web-sockets/src/main/resources/schema.sql similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/resources/schema.sql rename to spring-security-modules/spring-security-web-sockets/src/main/resources/schema.sql diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/resources/static/rest.html b/spring-security-modules/spring-security-web-sockets/src/main/resources/static/rest.html similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/resources/static/rest.html rename to spring-security-modules/spring-security-web-sockets/src/main/resources/static/rest.html diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/resources/static/rest.js b/spring-security-modules/spring-security-web-sockets/src/main/resources/static/rest.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/resources/static/rest.js rename to spring-security-modules/spring-security-web-sockets/src/main/resources/static/rest.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/resources/static/ws.html b/spring-security-modules/spring-security-web-sockets/src/main/resources/static/ws.html similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/resources/static/ws.html rename to spring-security-modules/spring-security-web-sockets/src/main/resources/static/ws.html diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/resources/static/ws.js b/spring-security-modules/spring-security-web-sockets/src/main/resources/static/ws.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/resources/static/ws.js rename to spring-security-modules/spring-security-web-sockets/src/main/resources/static/ws.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/WEB-INF/jsp/denied.jsp b/spring-security-modules/spring-security-web-sockets/src/main/webapp/WEB-INF/jsp/denied.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/WEB-INF/jsp/denied.jsp rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/WEB-INF/jsp/denied.jsp diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/WEB-INF/jsp/index.jsp b/spring-security-modules/spring-security-web-sockets/src/main/webapp/WEB-INF/jsp/index.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/WEB-INF/jsp/index.jsp rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/WEB-INF/jsp/index.jsp diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/WEB-INF/jsp/login.jsp b/spring-security-modules/spring-security-web-sockets/src/main/webapp/WEB-INF/jsp/login.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/WEB-INF/jsp/login.jsp rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/WEB-INF/jsp/login.jsp diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/WEB-INF/jsp/socket.jsp b/spring-security-modules/spring-security-web-sockets/src/main/webapp/WEB-INF/jsp/socket.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/WEB-INF/jsp/socket.jsp rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/WEB-INF/jsp/socket.jsp diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/WEB-INF/jsp/success.jsp b/spring-security-modules/spring-security-web-sockets/src/main/webapp/WEB-INF/jsp/success.jsp similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/WEB-INF/jsp/success.jsp rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/WEB-INF/jsp/success.jsp diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/app.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/app.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/app.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/app.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/controllers/indexController.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/controllers/indexController.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/controllers/indexController.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/controllers/indexController.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/controllers/socketController.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/controllers/socketController.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/controllers/socketController.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/controllers/socketController.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/controllers/successController.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/controllers/successController.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/controllers/successController.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/controllers/successController.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/routes/router.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/routes/router.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/routes/router.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/routes/router.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/services/SocketService.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/services/SocketService.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/scripts/services/SocketService.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/scripts/services/SocketService.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/app.css b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/app.css similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/app.css rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/app.css diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/denied.css b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/denied.css similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/denied.css rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/denied.css diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/index.css b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/index.css similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/index.css rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/index.css diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/login.css b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/login.css similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/login.css rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/login.css diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/socket.css b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/socket.css similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/socket.css rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/socket.css diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/success.css b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/success.css similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/styles/success.css rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/styles/success.css diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/angular/angular-route.min.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/angular/angular-route.min.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/angular/angular-route.min.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/angular/angular-route.min.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/angular/angular-route.min.js.map b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/angular/angular-route.min.js.map similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/angular/angular-route.min.js.map rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/angular/angular-route.min.js.map diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/angular/angular.min.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/angular/angular.min.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/angular/angular.min.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/angular/angular.min.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/angular/angular.min.js.map b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/angular/angular.min.js.map similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/angular/angular.min.js.map rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/angular/angular.min.js.map diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/jquery/jquery.min.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/jquery/jquery.min.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/jquery/jquery.min.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/jquery/jquery.min.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/sockjs/sockjs.min.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/sockjs/sockjs.min.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/sockjs/sockjs.min.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/sockjs/sockjs.min.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/sockjs/sockjs.min.js.map b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/sockjs/sockjs.min.js.map similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/sockjs/sockjs.min.js.map rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/sockjs/sockjs.min.js.map diff --git a/spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/stomp/stomp.min.js b/spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/stomp/stomp.min.js similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/main/webapp/resources/vendor/stomp/stomp.min.js rename to spring-security-modules/spring-security-web-sockets/src/main/webapp/resources/vendor/stomp/stomp.min.js diff --git a/spring-security-modules/spring-security-mvc-socket/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-web-sockets/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-mvc-socket/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-web-sockets/src/test/java/com/baeldung/SpringContextTest.java From 10e9f147ee2a0e28c8a89741a97a41ad4f23194f Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 16 Aug 2020 16:33:28 +0530 Subject: [PATCH 300/309] JAVA-68: Renamed spring-security-react to spring-security-web-react --- .../.gitignore | 0 .../README.md | 0 .../pom.xml | 4 ++-- .../main/java/com/baeldung/spring/MvcConfig.java | 0 .../java/com/baeldung/spring/SecSecurityConfig.java | 0 .../src/main/resources/logback.xml | 0 .../src/main/webapp/WEB-INF/mvc-servlet.xml | 0 .../src/main/webapp/WEB-INF/view/accessDenied.jsp | 0 .../main/webapp/WEB-INF/view/admin/adminpage.jsp | 0 .../src/main/webapp/WEB-INF/view/anonymous.jsp | 0 .../src/main/webapp/WEB-INF/view/homepage.jsp | 0 .../src/main/webapp/WEB-INF/view/react/.babelrc | 0 .../main/webapp/WEB-INF/view/react/.eslintignore | 0 .../src/main/webapp/WEB-INF/view/react/.eslintrc | 0 .../src/main/webapp/WEB-INF/view/react/.gitignore | 0 .../webapp/WEB-INF/view/react/package-lock.json | 0 .../src/main/webapp/WEB-INF/view/react/package.json | 0 .../webapp/WEB-INF/view/react/public/favicon.ico | Bin .../webapp/WEB-INF/view/react/public/index.html | 0 .../webapp/WEB-INF/view/react/public/manifest.json | 0 .../src/main/webapp/WEB-INF/view/react/src/Form.js | 0 .../src/main/webapp/WEB-INF/view/react/src/Input.js | 0 .../main/webapp/WEB-INF/view/react/src/index.css | 0 .../src/main/webapp/WEB-INF/view/react/src/index.js | 0 .../WEB-INF/view/react/src/registerServiceWorker.js | 0 .../src/main/webapp/WEB-INF/web.xml | 0 .../test/java/com/baeldung/SpringContextTest.java | 0 27 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/{spring-security-react => spring-security-web-react}/.gitignore (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/README.md (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/pom.xml (98%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/java/com/baeldung/spring/MvcConfig.java (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/java/com/baeldung/spring/SecSecurityConfig.java (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/resources/logback.xml (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/mvc-servlet.xml (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/accessDenied.jsp (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/admin/adminpage.jsp (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/anonymous.jsp (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/homepage.jsp (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/.babelrc (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/.eslintignore (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/.eslintrc (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/.gitignore (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/package-lock.json (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/package.json (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/public/favicon.ico (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/public/index.html (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/public/manifest.json (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/src/Form.js (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/src/Input.js (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/src/index.css (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/src/index.js (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/view/react/src/registerServiceWorker.js (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/main/webapp/WEB-INF/web.xml (100%) rename spring-security-modules/{spring-security-react => spring-security-web-react}/src/test/java/com/baeldung/SpringContextTest.java (100%) diff --git a/spring-security-modules/spring-security-react/.gitignore b/spring-security-modules/spring-security-web-react/.gitignore similarity index 100% rename from spring-security-modules/spring-security-react/.gitignore rename to spring-security-modules/spring-security-web-react/.gitignore diff --git a/spring-security-modules/spring-security-react/README.md b/spring-security-modules/spring-security-web-react/README.md similarity index 100% rename from spring-security-modules/spring-security-react/README.md rename to spring-security-modules/spring-security-web-react/README.md diff --git a/spring-security-modules/spring-security-react/pom.xml b/spring-security-modules/spring-security-web-react/pom.xml similarity index 98% rename from spring-security-modules/spring-security-react/pom.xml rename to spring-security-modules/spring-security-web-react/pom.xml index 19240fe88c..d0ca6f8c8d 100644 --- a/spring-security-modules/spring-security-react/pom.xml +++ b/spring-security-modules/spring-security-web-react/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - spring-security-react + spring-security-web-react 0.1-SNAPSHOT - spring-security-react + spring-security-web-react war diff --git a/spring-security-modules/spring-security-react/src/main/java/com/baeldung/spring/MvcConfig.java b/spring-security-modules/spring-security-web-react/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 100% rename from spring-security-modules/spring-security-react/src/main/java/com/baeldung/spring/MvcConfig.java rename to spring-security-modules/spring-security-web-react/src/main/java/com/baeldung/spring/MvcConfig.java diff --git a/spring-security-modules/spring-security-react/src/main/java/com/baeldung/spring/SecSecurityConfig.java b/spring-security-modules/spring-security-web-react/src/main/java/com/baeldung/spring/SecSecurityConfig.java similarity index 100% rename from spring-security-modules/spring-security-react/src/main/java/com/baeldung/spring/SecSecurityConfig.java rename to spring-security-modules/spring-security-web-react/src/main/java/com/baeldung/spring/SecSecurityConfig.java diff --git a/spring-security-modules/spring-security-react/src/main/resources/logback.xml b/spring-security-modules/spring-security-web-react/src/main/resources/logback.xml similarity index 100% rename from spring-security-modules/spring-security-react/src/main/resources/logback.xml rename to spring-security-modules/spring-security-web-react/src/main/resources/logback.xml diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/mvc-servlet.xml similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/mvc-servlet.xml rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/accessDenied.jsp b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/accessDenied.jsp similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/accessDenied.jsp rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/accessDenied.jsp diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/admin/adminpage.jsp b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/admin/adminpage.jsp similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/admin/adminpage.jsp rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/admin/adminpage.jsp diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/anonymous.jsp b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/anonymous.jsp similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/anonymous.jsp rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/anonymous.jsp diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/homepage.jsp similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/homepage.jsp rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/homepage.jsp diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/.babelrc b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/.babelrc similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/.babelrc rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/.babelrc diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/.eslintignore b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/.eslintignore similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/.eslintignore rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/.eslintignore diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/.eslintrc b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/.eslintrc similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/.eslintrc rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/.eslintrc diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/.gitignore b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/.gitignore similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/.gitignore rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/.gitignore diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/package-lock.json b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package-lock.json similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/package-lock.json rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package-lock.json diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/package.json b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/package.json rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/package.json diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/public/favicon.ico b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/public/favicon.ico similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/public/favicon.ico rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/public/favicon.ico diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/public/index.html b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/public/index.html similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/public/index.html rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/public/index.html diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/public/manifest.json b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/public/manifest.json similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/public/manifest.json rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/public/manifest.json diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/src/Form.js b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/src/Form.js similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/src/Form.js rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/src/Form.js diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/src/Input.js b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/src/Input.js similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/src/Input.js rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/src/Input.js diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/src/index.css b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/src/index.css similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/src/index.css rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/src/index.css diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/src/index.js b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/src/index.js similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/src/index.js rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/src/index.js diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/src/registerServiceWorker.js b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/src/registerServiceWorker.js similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/view/react/src/registerServiceWorker.js rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/view/react/src/registerServiceWorker.js diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/web.xml rename to spring-security-modules/spring-security-web-react/src/main/webapp/WEB-INF/web.xml diff --git a/spring-security-modules/spring-security-react/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-web-react/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-security-modules/spring-security-react/src/test/java/com/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-web-react/src/test/java/com/baeldung/SpringContextTest.java From 12d16d9c850ebecc7cbc0c1a7fc4340730695234 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 16 Aug 2020 16:34:03 +0530 Subject: [PATCH 301/309] JAVA-68: parent module pom changes as per child module renaming --- spring-security-modules/pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index f050b48ac5..815b84d448 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -24,14 +24,14 @@ spring-security-web-boot-2 spring-security-web-mvc-custom spring-security-web-digest-auth - spring-security-mvc-jsonview + spring-security-web-jsonview spring-security-ldap - spring-security-mvc-login - spring-security-mvc-persisted-remember-me - spring-security-mvc-socket + spring-security-web-login + spring-security-web-persisted-remember-me + spring-security-web-sockets spring-security-oidc spring-security-okta - spring-security-react + spring-security-web-react spring-security-rest spring-security-rest-basic-auth spring-security-rest-custom From 00d8cdc2524cac8c1a3dd3cff243b81ca24e8a53 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 16 Aug 2020 16:37:06 +0530 Subject: [PATCH 302/309] JAVA-68: README changes --- spring-security-modules/spring-security-web-jsonview/README.md | 2 +- spring-security-modules/spring-security-web-sockets/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-security-modules/spring-security-web-jsonview/README.md b/spring-security-modules/spring-security-web-jsonview/README.md index 0e28d4c292..83f8106df9 100644 --- a/spring-security-modules/spring-security-web-jsonview/README.md +++ b/spring-security-modules/spring-security-web-jsonview/README.md @@ -1,4 +1,4 @@ -## Spring Security MVC Json View +## Spring Security Web Json View This module contains articles about Spring Security with JSON diff --git a/spring-security-modules/spring-security-web-sockets/README.md b/spring-security-modules/spring-security-web-sockets/README.md index d134d19c84..14ef0c8b99 100644 --- a/spring-security-modules/spring-security-web-sockets/README.md +++ b/spring-security-modules/spring-security-web-sockets/README.md @@ -1,4 +1,4 @@ -## Spring Security MVC Socket +## Spring Security Web Sockets This module contains articles about WebSockets with Spring Security From a32ecbeb8a75329707d4f9c899fe39a8737f7e7d Mon Sep 17 00:00:00 2001 From: bfontana Date: Sun, 16 Aug 2020 18:32:19 -0300 Subject: [PATCH 303/309] Delete README.md File will be added after the article is published. --- spring-webflux-threads/README.md | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 spring-webflux-threads/README.md diff --git a/spring-webflux-threads/README.md b/spring-webflux-threads/README.md deleted file mode 100644 index b69ba958c1..0000000000 --- a/spring-webflux-threads/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Spring WebFlux Concurrency - -This module contains articles about concurrency model in Spring WebFlux. - -### Relevant Articles: - -- [Concurrency in Spring WebFlux]() From 1c432896ca36bded5196933a5c804d1cc986f5f4 Mon Sep 17 00:00:00 2001 From: bfontana Date: Sun, 16 Aug 2020 19:21:54 -0300 Subject: [PATCH 304/309] Update Application.java Minor Javadoc fixings. --- .../src/main/java/com/baeldung/webflux/Application.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java index a0cd7d6a27..06a148a77f 100644 --- a/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java +++ b/spring-webflux-threads/src/main/java/com/baeldung/webflux/Application.java @@ -4,8 +4,8 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** -* Please note that this assumes Mongo and Kafka to be running on the local machine on default configurations. -* If you want to experiment with Tomcat/Jetty instead of Netty, just uncomment the lines in pom.xml and rebuild. +* Please note we assume Mongo and Kafka are running in the local machine and on default configuration. +* Additionally, if you want to experiment with Tomcat/Jetty instead of Netty, just uncomment the lines in pom.xml and rebuild. */ @SpringBootApplication public class Application { From 62432a25320d7caec51e6ad6573968fbed6d83e5 Mon Sep 17 00:00:00 2001 From: Amit Pandey Date: Mon, 17 Aug 2020 10:30:19 +0530 Subject: [PATCH 305/309] Java 2387 (#9882) * fix junit test cases * added module in parent build --- .../com/baeldung/datetime/UseDateTimeFormatterUnitTest.java | 2 +- .../java/com/baeldung/datetime/UseToInstantUnitTest.java | 6 ++++-- .../com/baeldung/datetime/UseZonedDateTimeUnitTest.java | 2 +- core-java-modules/pom.xml | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseDateTimeFormatterUnitTest.java b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseDateTimeFormatterUnitTest.java index 797e0b954a..8ca0066a0d 100644 --- a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseDateTimeFormatterUnitTest.java +++ b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseDateTimeFormatterUnitTest.java @@ -31,6 +31,6 @@ public class UseDateTimeFormatterUnitTest { public void givenALocalDate_whenFormattingWithStyleAndLocale_thenPass() { String result = subject.formatWithStyleAndLocale(localDateTime, FormatStyle.MEDIUM, Locale.UK); - assertThat(result).isEqualTo("25 Jan 2015, 06:30:00"); + assertThat(result).isEqualTo("25-Jan-2015 06:30:00"); } } \ No newline at end of file diff --git a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseToInstantUnitTest.java b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseToInstantUnitTest.java index 78d9a647fe..cb6e804284 100644 --- a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseToInstantUnitTest.java +++ b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseToInstantUnitTest.java @@ -3,6 +3,7 @@ package com.baeldung.datetime; import static org.assertj.core.api.Assertions.assertThat; import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; @@ -24,10 +25,11 @@ public class UseToInstantUnitTest { @Test public void givenADate_whenConvertingToLocalDate_thenAsExpected() { - Date givenDate = new Date(1465817690000L); + LocalDateTime currentDateTime = LocalDateTime.now(); + Date givenDate = Date.from(currentDateTime.atZone(ZoneId.systemDefault()).toInstant()); LocalDateTime localDateTime = subject.convertDateToLocalDate(givenDate); - assertThat(localDateTime).isEqualTo("2016-06-13T13:34:50"); + assertThat(localDateTime).isEqualTo(currentDateTime); } } \ No newline at end of file diff --git a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseZonedDateTimeUnitTest.java b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseZonedDateTimeUnitTest.java index 4a39f6056e..0ee0f72d78 100644 --- a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseZonedDateTimeUnitTest.java +++ b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseZonedDateTimeUnitTest.java @@ -54,7 +54,7 @@ public class UseZonedDateTimeUnitTest { @Test public void givenAStringWithTimeZone_whenParsing_thenEqualsExpected() { ZonedDateTime resultFromString = zonedDateTime.getZonedDateTimeUsingParseMethod("2015-05-03T10:15:30+01:00[Europe/Paris]"); - ZonedDateTime resultFromLocalDateTime = ZonedDateTime.of(2015, 5, 3, 11, 15, 30, 0, ZoneId.of("Europe/Paris")); + ZonedDateTime resultFromLocalDateTime = ZonedDateTime.of(2015, 5, 3, 10, 15, 30, 0, ZoneId.of("Europe/Paris")); assertThat(resultFromString.getZone()).isEqualTo(ZoneId.of("Europe/Paris")); assertThat(resultFromLocalDateTime.getZone()).isEqualTo(ZoneId.of("Europe/Paris")); diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 589097cf48..e6fd449c87 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -64,6 +64,7 @@ core-java-date-operations-2 + core-java-8-datetime core-java-exceptions core-java-exceptions-2 From 2bad67ff3831f2fd4b907983d3e726fa00c8b3d7 Mon Sep 17 00:00:00 2001 From: Amit Pandey Date: Mon, 17 Aug 2020 10:33:20 +0530 Subject: [PATCH 306/309] added modules in parent (#9842) * added modules in parent * commented failed modules in pom --- core-java-modules/pom.xml | 5 +++++ patterns/pom.xml | 1 + persistence-modules/pom.xml | 2 ++ spring-boot-modules/spring-boot-custom-starter/pom.xml | 1 + spring-cloud/pom.xml | 2 ++ spring-cloud/spring-cloud-stream/pom.xml | 2 ++ 6 files changed, 13 insertions(+) diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index e6fd449c87..0b832223f4 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -22,6 +22,7 @@ + core-java-8 core-java-8-2 @@ -59,7 +60,11 @@ core-java-concurrency-basic core-java-concurrency-basic-2 core-java-concurrency-collections + core-java-concurrency-collections-2 + core-java-console + + core-java-8-datetime-2 core-java-date-operations-2 diff --git a/patterns/pom.xml b/patterns/pom.xml index e1753aba56..a179d75ffe 100644 --- a/patterns/pom.xml +++ b/patterns/pom.xml @@ -21,6 +21,7 @@ dip cqrs-es front-controller + hexagonal-architecture intercepting-filter solid diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 6186900a6e..3e1a90b737 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -19,12 +19,14 @@ core-java-persistence deltaspike elasticsearch + flyway flyway-repair hbase hibernate5 hibernate-mapping hibernate-ogm hibernate-annotations + hibernate-exceptions hibernate-libraries hibernate-jpa hibernate-queries diff --git a/spring-boot-modules/spring-boot-custom-starter/pom.xml b/spring-boot-modules/spring-boot-custom-starter/pom.xml index 17f9fdc2cc..338bf22f46 100644 --- a/spring-boot-modules/spring-boot-custom-starter/pom.xml +++ b/spring-boot-modules/spring-boot-custom-starter/pom.xml @@ -18,6 +18,7 @@ greeter-library + greeter greeter-spring-boot-autoconfigure greeter-spring-boot-starter greeter-spring-boot-sample-app diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index 0e2cac1ff9..99fde0daf4 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -41,6 +41,8 @@ spring-cloud-zuul spring-cloud-zuul-fallback spring-cloud-ribbon-retry + spring-cloud-circuit-breaker + spring-cloud-eureka-self-preservation diff --git a/spring-cloud/spring-cloud-stream/pom.xml b/spring-cloud/spring-cloud-stream/pom.xml index ebaaab0801..17c788c000 100644 --- a/spring-cloud/spring-cloud-stream/pom.xml +++ b/spring-cloud/spring-cloud-stream/pom.xml @@ -14,7 +14,9 @@ + spring-cloud-stream-kafka spring-cloud-stream-rabbit + spring-cloud-stream-kinesis From 3233bd6adc5e5485d9af8573c200291bd95c3beb Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Mon, 17 Aug 2020 12:41:09 +0100 Subject: [PATCH 307/309] BAEL-4321 add new module to pom --- spring-boot-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 84f1f0e86c..f4e3e534c8 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -56,6 +56,7 @@ spring-boot-performance spring-boot-properties spring-boot-properties-2 + spring-boot-properties-3 spring-boot-property-exp spring-boot-runtime spring-boot-security From 5c46488ac82f826873f7214efd6dc0cb848dc0ea Mon Sep 17 00:00:00 2001 From: Amit Pandey Date: Mon, 17 Aug 2020 18:21:42 +0530 Subject: [PATCH 308/309] used standard parent pom (#9885) --- .../spring-boot-basic-customization/pom.xml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/spring-boot-modules/spring-boot-basic-customization/pom.xml b/spring-boot-modules/spring-boot-basic-customization/pom.xml index 2a4b321c5f..fc34994a85 100644 --- a/spring-boot-modules/spring-boot-basic-customization/pom.xml +++ b/spring-boot-modules/spring-boot-basic-customization/pom.xml @@ -4,13 +4,11 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.3.2.RELEASE - + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT + ../ spring-boot-basic-customization From 0d2ae486e100cb5e94c8598670579e8393b690ce Mon Sep 17 00:00:00 2001 From: davidmartinezbarua Date: Mon, 17 Aug 2020 11:52:28 -0300 Subject: [PATCH 309/309] Revert "BAEL-4321 demo app for yaml to pojo" --- spring-boot-modules/pom.xml | 1 - .../spring-boot-properties-3/pom.xml | 54 ------------------- .../boot/properties/DemoApplication.java | 16 ------ .../properties/config/TshirtSizeConfig.java | 27 ---------- .../controller/TshirtSizeController.java | 21 -------- .../properties/service/SizeConverterImpl.java | 22 -------- .../service/SizeConverterService.java | 8 --- .../src/main/resources/application.yml | 30 ----------- .../controller/TshirtSizeControllerTest.java | 38 ------------- 9 files changed, 217 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-properties-3/pom.xml delete mode 100644 spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java delete mode 100644 spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/config/TshirtSizeConfig.java delete mode 100644 spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java delete mode 100644 spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java delete mode 100644 spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterService.java delete mode 100644 spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml delete mode 100644 spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index b4cabaaedf..3a2f14f5df 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -56,7 +56,6 @@ spring-boot-performance spring-boot-properties spring-boot-properties-2 - spring-boot-properties-3 spring-boot-property-exp spring-boot-runtime spring-boot-security diff --git a/spring-boot-modules/spring-boot-properties-3/pom.xml b/spring-boot-modules/spring-boot-properties-3/pom.xml deleted file mode 100644 index 1e3d627b19..0000000000 --- a/spring-boot-modules/spring-boot-properties-3/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - 4.0.0 - - com.baeldung.spring-boot-modules - spring-boot-modules - 1.0.0-SNAPSHOT - ../ - - - spring-boot-properties-3 - 0.0.1-SNAPSHOT - spring-boot-properties-3 - Spring Boot Properties Module - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - org.springframework.boot - spring-boot-starter-web - RELEASE - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java deleted file mode 100644 index cf2fb7f981..0000000000 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/DemoApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.boot.properties; - -import com.baeldung.boot.properties.config.TshirtSizeConfig; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; - -@SpringBootApplication -@EnableConfigurationProperties(TshirtSizeConfig.class) -public class DemoApplication { - - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } - -} diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/config/TshirtSizeConfig.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/config/TshirtSizeConfig.java deleted file mode 100644 index 690763ab7b..0000000000 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/config/TshirtSizeConfig.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.boot.properties.config; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.util.Map; - -@ConfigurationProperties(prefix = "t-shirt-size") -public class TshirtSizeConfig { - - private final Map simpleMapping; - - private final Map> complexMapping; - - - public TshirtSizeConfig(Map simpleMapping, Map> complexMapping) { - this.simpleMapping = simpleMapping; - this.complexMapping = complexMapping; - } - - public Map getSimpleMapping() { - return simpleMapping; - } - - public Map> getComplexMapping() { - return complexMapping; - } -} diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java deleted file mode 100644 index 6b713c5be8..0000000000 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/controller/TshirtSizeController.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.boot.properties.controller; - -import org.springframework.web.bind.annotation.*; -import com.baeldung.boot.properties.service.SizeConverterService; - -@RestController -@RequestMapping(value = "/") -public class TshirtSizeController { - - private final SizeConverterService service; - - public TshirtSizeController(SizeConverterService service) { - this.service = service; - } - - @RequestMapping(value ="convertSize", method = RequestMethod.GET) - public int convertSize(@RequestParam(value = "label") final String label, @RequestParam(value = "countryCode", required = false) final String countryCode) { - return service.convertSize(label, countryCode); - } - -} diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java deleted file mode 100644 index 34f7fe2ded..0000000000 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.boot.properties.service; - -import org.springframework.stereotype.Service; -import com.baeldung.boot.properties.config.TshirtSizeConfig; - - -@Service -public class SizeConverterImpl implements SizeConverterService { - - private final TshirtSizeConfig tshirtSizeConfig; - - public SizeConverterImpl(TshirtSizeConfig tshirtSizeConfig) { - this.tshirtSizeConfig = tshirtSizeConfig; - } - - public int convertSize(String label, String countryCode) { - if(countryCode == null) { - return tshirtSizeConfig.getSimpleMapping().get(label); - } - return tshirtSizeConfig.getComplexMapping().get(label).get(countryCode.toLowerCase()); - } -} diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterService.java b/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterService.java deleted file mode 100644 index 412199b176..0000000000 --- a/spring-boot-modules/spring-boot-properties-3/src/main/java/com/baeldung/boot/properties/service/SizeConverterService.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.boot.properties.service; - - -public interface SizeConverterService { - - int convertSize(String label, String countryCode); - -} diff --git a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml deleted file mode 100644 index 8779cb6b0c..0000000000 --- a/spring-boot-modules/spring-boot-properties-3/src/main/resources/application.yml +++ /dev/null @@ -1,30 +0,0 @@ - t-shirt-size: - simple-mapping: - XS: 6 - S: 8 - M: 10 - L: 12 - XL: 14 - - - complex-mapping: - XS: - uk: 6 - fr: 34 - us: 2 - S: - uk: 8 - fr: 36 - us: 4 - M: - uk: 10 - fr: 38 - us: 6 - L: - uk: 12 - fr: 40 - us: 8 - XL: - uk: 14 - fr: 42 - us: 10 diff --git a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java b/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java deleted file mode 100644 index 0b70ed8622..0000000000 --- a/spring-boot-modules/spring-boot-properties-3/src/test/java/com/baeldung/boot/properties/controller/TshirtSizeControllerTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.boot.properties.controller; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import com.baeldung.boot.properties.service.SizeConverterService; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class TshirtSizeControllerUnitTest { - - @Mock - private SizeConverterService service; - - @InjectMocks - private TshirtSizeController tested; - - @Test - void whenConvertSize_thenOK() { - - // Given - String label = "S"; - String countryCode = "fr"; - int result = 36; - - // When - when(service.convertSize(label, countryCode)).thenReturn(result); - int actual = tested.convertSize(label, countryCode); - - // Then - assertEquals(actual, result); - - } -} \ No newline at end of file