From b8b5a8ce9d1280b12e6102e3b69af8787a8a1758 Mon Sep 17 00:00:00 2001 From: Bulimac Vlad Date: Tue, 28 Oct 2014 17:51:13 +0200 Subject: [PATCH 01/12] Java - Workshop 1 & 2 --- exercises/teamnet/.idea/.name | 1 + exercises/teamnet/.idea/compiler.xml | 23 + .../.idea/copyright/profiles_settings.xml | 3 + exercises/teamnet/.idea/encodings.xml | 5 + exercises/teamnet/.idea/misc.xml | 11 + exercises/teamnet/.idea/modules.xml | 9 + .../teamnet/.idea/scopes/scope_settings.xml | 5 + exercises/teamnet/.idea/uiDesigner.xml | 125 ++ exercises/teamnet/.idea/vcs.xml | 7 + exercises/teamnet/.idea/workspace.xml | 1272 +++++++++++++++++ exercises/teamnet/USPresident.data | Bin 0 -> 136 bytes .../ro/teamnet/zerotohero/canvas/Canvas.class | Bin 0 -> 534 bytes .../ro/teamnet/zerotohero/gc/DemoObject.class | Bin 0 -> 1138 bytes .../ro/teamnet/zerotohero/gc/GCExample.class | Bin 0 -> 773 bytes .../oop/graphicshape/AbstractShape.class | Bin 0 -> 466 bytes .../zerotohero/oop/graphicshape/Circle.class | Bin 0 -> 1840 bytes .../zerotohero/oop/graphicshape/Circles.class | Bin 0 -> 755 bytes .../oop/graphicshape/ImmutableClass.class | Bin 0 -> 794 bytes .../zerotohero/oop/graphicshape/Point.class | Bin 0 -> 669 bytes .../zerotohero/oop/graphicshape/Point3D.class | Bin 0 -> 445 bytes .../zerotohero/oop/graphicshape/Shape.class | Bin 0 -> 925 bytes .../oop/graphicshape/ShapeBehaviour.class | Bin 0 -> 169 bytes .../zerotohero/oop/graphicshape/Square.class | Bin 0 -> 488 bytes .../zerotohero/oop/runapp/RunApp.class | Bin 0 -> 2608 bytes .../zerotohero/reflection/api/Column.class | Bin 0 -> 445 bytes .../zerotohero/reflection/api/DBManager.class | Bin 0 -> 2318 bytes .../zerotohero/reflection/api/Table.class | Bin 0 -> 441 bytes .../reflection/model/Employee.class | Bin 0 -> 595 bytes .../serializare/TransientSerialization.class | Bin 0 -> 2728 bytes .../zerotohero/serializare/USPresident.class | Bin 0 -> 950 bytes .../zerotohero/threads/counter/Counter.class | Bin 0 -> 1023 bytes .../threads/counter/SyncronizeCounter$1.class | Bin 0 -> 680 bytes .../threads/counter/SyncronizeCounter$2.class | Bin 0 -> 680 bytes .../threads/counter/SyncronizeCounter.class | Bin 0 -> 778 bytes .../thread_creation/ClassRunnable.class | Bin 0 -> 620 bytes .../threads/thread_creation/ClassThread.class | Bin 0 -> 583 bytes .../thread_creation/ThreadTester.class | Bin 0 -> 1306 bytes .../ro/teamnet/zerotohero/canvas/Canvas.java | 14 + .../ro/teamnet/zerotohero/gc/DemoObject.java | 38 + .../ro/teamnet/zerotohero/gc/GCExample.java | 20 + .../oop/graphicshape/AbstractShape.java | 14 + .../zerotohero/oop/graphicshape/Circle.java | 54 + .../zerotohero/oop/graphicshape/Circles.java | 23 + .../oop/graphicshape/ImmutableClass.java | 27 + .../zerotohero/oop/graphicshape/Point.java | 29 + .../zerotohero/oop/graphicshape/Point3D.java | 14 + .../zerotohero/oop/graphicshape/Shape.java | 24 + .../oop/graphicshape/ShapeBehaviour.java | 10 + .../zerotohero/oop/graphicshape/Square.java | 17 + .../teamnet/zerotohero/oop/runapp/RunApp.java | 42 + .../zerotohero/reflection/api/Column.java | 16 + .../zerotohero/reflection/api/DBManager.java | 43 + .../zerotohero/reflection/api/Table.java | 16 + .../zerotohero/reflection/model/Employee.java | 19 + .../serializare/TransientSerialization.java | 42 + .../zerotohero/serializare/USPresident.java | 25 + .../zerotohero/threads/counter/Counter.java | 27 + .../threads/counter/SyncronizeCounter.java | 35 + .../thread_creation/ClassRunnable.java | 14 + .../threads/thread_creation/ClassThread.java | 15 + .../threads/thread_creation/ThreadTester.java | 26 + exercises/teamnet/teamnet.iml | 12 + 62 files changed, 2077 insertions(+) create mode 100644 exercises/teamnet/.idea/.name create mode 100644 exercises/teamnet/.idea/compiler.xml create mode 100644 exercises/teamnet/.idea/copyright/profiles_settings.xml create mode 100644 exercises/teamnet/.idea/encodings.xml create mode 100644 exercises/teamnet/.idea/misc.xml create mode 100644 exercises/teamnet/.idea/modules.xml create mode 100644 exercises/teamnet/.idea/scopes/scope_settings.xml create mode 100644 exercises/teamnet/.idea/uiDesigner.xml create mode 100644 exercises/teamnet/.idea/vcs.xml create mode 100644 exercises/teamnet/.idea/workspace.xml create mode 100644 exercises/teamnet/USPresident.data create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/canvas/Canvas.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/gc/DemoObject.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/gc/GCExample.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/AbstractShape.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Circle.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Circles.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/ImmutableClass.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Point.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Point3D.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Shape.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/ShapeBehaviour.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Square.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/runapp/RunApp.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/reflection/api/Column.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/reflection/api/DBManager.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/reflection/api/Table.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/reflection/model/Employee.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/TransientSerialization.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/USPresident.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/Counter.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter$1.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter$2.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/thread_creation/ClassRunnable.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/thread_creation/ClassThread.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/thread_creation/ThreadTester.class create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/canvas/Canvas.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/gc/DemoObject.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/gc/GCExample.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/AbstractShape.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Circle.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Circles.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/ImmutableClass.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Point.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Point3D.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Shape.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/ShapeBehaviour.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Square.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/runapp/RunApp.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/Column.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/DBManager.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/Table.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/model/Employee.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/TransientSerialization.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/USPresident.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/Counter.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ClassRunnable.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ClassThread.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ThreadTester.java create mode 100644 exercises/teamnet/teamnet.iml diff --git a/ exercises/teamnet/.idea/.name b/ exercises/teamnet/.idea/.name new file mode 100644 index 0000000..d54a42c --- /dev/null +++ b/ exercises/teamnet/.idea/.name @@ -0,0 +1 @@ +teamnet \ No newline at end of file diff --git a/ exercises/teamnet/.idea/compiler.xml b/ exercises/teamnet/.idea/compiler.xml new file mode 100644 index 0000000..217af47 --- /dev/null +++ b/ exercises/teamnet/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/ exercises/teamnet/.idea/copyright/profiles_settings.xml b/ exercises/teamnet/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/ exercises/teamnet/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ exercises/teamnet/.idea/encodings.xml b/ exercises/teamnet/.idea/encodings.xml new file mode 100644 index 0000000..e206d70 --- /dev/null +++ b/ exercises/teamnet/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/ exercises/teamnet/.idea/misc.xml b/ exercises/teamnet/.idea/misc.xml new file mode 100644 index 0000000..d53afa3 --- /dev/null +++ b/ exercises/teamnet/.idea/misc.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/ exercises/teamnet/.idea/modules.xml b/ exercises/teamnet/.idea/modules.xml new file mode 100644 index 0000000..58a0721 --- /dev/null +++ b/ exercises/teamnet/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/ exercises/teamnet/.idea/scopes/scope_settings.xml b/ exercises/teamnet/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000..922003b --- /dev/null +++ b/ exercises/teamnet/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/ exercises/teamnet/.idea/uiDesigner.xml b/ exercises/teamnet/.idea/uiDesigner.xml new file mode 100644 index 0000000..3b00020 --- /dev/null +++ b/ exercises/teamnet/.idea/uiDesigner.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ exercises/teamnet/.idea/vcs.xml b/ exercises/teamnet/.idea/vcs.xml new file mode 100644 index 0000000..def6a6a --- /dev/null +++ b/ exercises/teamnet/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ exercises/teamnet/.idea/workspace.xml b/ exercises/teamnet/.idea/workspace.xml new file mode 100644 index 0000000..3972693 --- /dev/null +++ b/ exercises/teamnet/.idea/workspace.xml @@ -0,0 +1,1272 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + + + 1414413942194 + 1414413942194 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.7 + + + + + + + + teamnet + + + + + + + + + + + + + + + + diff --git a/ exercises/teamnet/USPresident.data b/ exercises/teamnet/USPresident.data new file mode 100644 index 0000000000000000000000000000000000000000..98cc1d1983b8c55b777b1e85102a3afc2c13e2b7 GIT binary patch literal 136 zcmZ4UmVvdnh(Wg~U#}!JF*h%@M6W8fD8D2>14!x>rxs-<=44hS7NzQi1_uV!Z literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/canvas/Canvas.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/canvas/Canvas.class new file mode 100644 index 0000000000000000000000000000000000000000..c367561452e34bbf78cc40840bae19f5412425c2 GIT binary patch literal 534 zcmZ{h%Sr<=6o&syFEdVCTea59PDJp6X5ms1r0QzWg;H>tj-eB2CnZe_`cmS?f`Sj= zLy0Fd-3aY0{*!Yi|95hdpWn}K0H@dvQAX3pdI%3qCoLZvJ~kQ3=PFh9f}yZ~&|xUH z^^;_%M=F)K<3U%N2hr_QWi`^V=y!xsE}s>PHc=yny~t>8r5L2r@>glJ)d?w&MLH29 z-p;}qgWr?((nygtyJ83iFKuOFhvy3rS`T^8h+(4QQ6h$t=LUj>_j+t%d83@YlJ_`y z786m0kAUHL{+Sj4tJp%FVRydi-yjSP*M|2++T(ZKXBk_%H$ih@2PL{__j#ak5s)rX z#wjw2rNb%Md-gjdEoa356de;!^C;H7;5|-Jh>ku`e4~N~2XU_n ZLIh-WpjN(l1`6mz4XhA~o-p&Q{Q-P@b>08~ literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/gc/DemoObject.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/gc/DemoObject.class new file mode 100644 index 0000000000000000000000000000000000000000..f701068f789fe60dceb430056147bc26d45f654f GIT binary patch literal 1138 zcma)4TTc^F5dKbEy6w8P7s^%e0-|jZR`7~kR6rAwqQ(-8Z*I3+SX_3SW$T4!!k8`-E+#RCag{GGtF*2txT@fqfLd+V>y}@!H!T6NAds5#+>O9+gJr{M z(iaP?^@c#MykQ`oZMs=XmFRQ5eRu#9!r3iM6O_X2N~ zQeQFkd28LfA9f}N!Q7rB;AWe)Q?q==Q6_MFTLMlWv>laPXy`(>h6&uz(1E-_*S`$ygU~REDGlw&Yv@E) z!L)`M+*EK&!)?rJm_xU~;D3xOkU8klVnCq%z_qmMd(T_+CIYYZO#=Bs@d!U8CT=tu zmRl3(E6g2DI3Vy)%gW0QZUev8Yx1W%T2*aNf53eR*p9!&!Yx35y9JbnOmbX)aA84i zMr6gr8E$5p`y4|rGRT5!!CM4z9`Y61>%5ows7Z2Sj$^v~66n_Ic?dVGY literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/gc/GCExample.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/gc/GCExample.class new file mode 100644 index 0000000000000000000000000000000000000000..5b8fed6842d74322e8088b8e42f90159491f47bc GIT binary patch literal 773 zcmZ`%%Wl(95Ixs+-!mi$GGpIj1?ERJy>~O_26KoiaWUL zqUmCdp|mAaska&I*5)3Avy=4&Lp_wKcs)vbLhbTiOr6Cri+H@pmCWmL)6oa=h+!jC zS)c_^QlW!SLS;HTpco9I;N{Nqk31R1qD|ZhmnlP|^)5W*A9xV+bP#m3lIfsrw7D7( z+tPo=4As6!vNyd$5oy9K6bvIR;~Gc33Mxp;wXZ@xtnF8v?*V}a%7DORZpC^O1)4^F_onz2u@ zWSSMs)4N{)P(z)n3KnpMI{C++VG|wDJcYG?0y{i~LwT_y9f% zaUCiID;}=yx%WJ5e|)~Z1K7t_gb>~E{E!fxMFd!HVxx&ohF~U&sbpYR4B@FNl|5r< z?CcI0{7ZdLn|7i~c{3fS(%gx(ph+junJ5OrD2L}m-{z`fI7*D>R*G>cEq{M+Bg=F#Gfk<6^WP5%viG1z<;V)G1Z9J tAiYn@CCB>aVi|2hl!w*153hZJp!W>_k(M5joz$7Peu;x0ai?ajeE}}zkmM|z!tvDV;nj=2jNBv$!Mf-5j=YFGqy;^0<%p1?xc;JF?l8%?DZ3 zCGo=yKFVNEA@#$)*HuvBJ`3HnZ?^0n&(e2o*ADI}B&%zW8Q$?)mcnGicCAOfRM57GVKjWt2rTp1wF2Wu%l87WO>1~w$2juMPTOvF+h)fy zc5J`tSa(QM-4nL4>Rz~}xrR>4^er>2Wmh2^cn5)RyGIJs)wRYq=69yynC_7gof0Ph zwe2`Np5yg=f^|&aJQnP_V5>Ug2aGhWx-Bm#MC_Y_qhS$C8ZM)vVL{9lR1{{=eq^G{Ep@wT2e4^nIKGm>~N(P^4_#CSm z4zQ{)ci6V{W+;T-Wa++ccXikMUYDdp4PRhWp)5&VGwAtdV0-Q`j=lM~SNXU%P zOURgnD<_3(4oXIdR_AV?amBS1Le zm`|7^Hzx;}wFTBY1TGO0n5LZ}aG6EUhTwX1Z2&$QgA*#0NQ79#8!?STnh3B9!15e<1VZ4B1ky&qkae(MO@AMSfEJ@yJin?_=VZ zb2L{+Xp8~P`e1@?#WaQA*pd?z`?xghMLv9Gjg7oE0#g`)c`+(qQ3X+Csa82diC8bH zo?>;CsI)$&htSddY;rCQw(ZRjKANAUL5r8L5zo&$He*?aL@Q^Q86hf@Xr+%?YVZ=G UEfU=z(al#986;3FM7s3WKVqgqNdN!< literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Circles.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Circles.class new file mode 100644 index 0000000000000000000000000000000000000000..ff602520d5a8c4438172dd015cfae5ea6a594535 GIT binary patch literal 755 zcmb7>-)b5`6vn^NHM_NIqp>m8{>lGfB5_l4nNkp~P>{CJAOvzVZYDaiIJXFY;b+O*M7vG*ebLMxxJ?H89&p!ai*h?abf{FJ@#8A-kLCZ%ipNz`= z?VXO+O>CIhWLWwl`!e{-5HIdG8H}pB5Dd!=*%v=Xy_WD#dCQ~BN<+EaYjR)e?m z9XVt;YWT_t1n>1l;M@pb1*${pC^c}}J|A?XJM8d*aH`UGJuy6CNVY{#@df`iYK5(9 z45k~Ner9kMUWh^SN^1j-$NO#PXR9mRfacC=807a-dR|p|{_5CI`@rw4UpE#KI zPMQiA&L{#B2NSSI3SxLes&@=nFzDJcMY^1dkVb~yv`%Crz&EPYwW+^|olOvLl*TX~ zC@~MR36%;#xoL3(vIzMWtAt|6%{-k)$ow2KQA&)lR9Z2|u>RZ3(S495iwxOhDMPe1 V;%Up%PWf4io|hamc+=hBYOi9zo|kX zfsk5>AHa{QI=e{^MVyf3-S=kS%)ICI+4_L9=YVLIeyu<873Dnzhs*Xm3uF8MNZbBqzXOT=gGLKC@ z0X^N13xO}~JPWmwgH-A8QstS>`dq^-8-~4H4*PLb^yN^6t-)ZV4gWBaMX@h17v)N7 zb)+s@X`y8r(P`hb@?u5z)C}rz<%m-~rJLi?-Q7J7U;PL0kO;qk|2-S!k!r?f$oc;p ze19g-Weu;eRYL_+HB{jXe16feMy4h(Yb3)&roHf6_e@3F_R+xy-c^|w=^!vxi~{4v z-6KXS1g4oCGjqAu8}|^6JY>a7`#T+vVSQ}v@ zW8|ks|;A literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Point.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Point.class new file mode 100644 index 0000000000000000000000000000000000000000..c432f3cf2cf64fb363ffc329dc3d97459adcc834 GIT binary patch literal 669 zcmb7A&1w@-7(I7>5)-E;9Zg$JEiG=6$Y1E&8tzt)hc9L}=gU3CTky aakvxTCW~<&516CHt_P>`gm{J6!Rj@~z<#j+ literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Point3D.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Point3D.class new file mode 100644 index 0000000000000000000000000000000000000000..de80bd8f2cff1c368307851e23f1bbd5e752abbf GIT binary patch literal 445 zcmb7A%SyvQ6g@Xh8(Y&>>uaGd+}R?H(52!=5duXDN>*;Bbuc4srlhH8|H_33F8lyL zN<0bqfiCWy^WfeyGrxb|KL7?eXuw6MjtX`>?0VP}xT}#}2qYBLE=^*xD}vK747(A{ zYx|@H?V(BZ-Eub8>4O?isdR>RqNb5bP0mZv&0@n<=fl(nnO3tzXTeIRHnTB%VC_73 zPSrd%lSQoNIv81#WP_UvroXY?1&w>VOegx*Fi8U*zPnANggcgDbk-SgVAv?0!3A2-c{wYzY zf)D-xf0TGu20Yxg;hu** z521%HLoHUR(hTgB!Oyu_Xl|s+2pBN9Ph}>}AwxCnjv1U|^;$5j4P_=?EM^m-U-3yw zNPDPao{qVeHeZ2`No3B@A8HjD!DpE;(L14)Q3=IJsd+Tje4fZSPxxF!BO4E>3)g}d zEuWLUB~KUBfziF53v*n$b;46?s7c7^7tc;Ou&_T;3muDrwBGzexBrGOd4LwyJoEzG z$38VWqDCGb1n46Q;NwDo08NJd|8dOl_?+~kNp3WcO<{=P$vMjk`ZJO6rKGVK*6k=! z%Cl)SdYcwam=O(0DUi=*C}Q25)XjDShe9uq-Sk4Z+ic?if4t zr_{mFKn0H74*ge-T~Ki{yGwdqr!1nA(OK(#2Kzvl3NBJ~3(!TI?m1@(Z+$8dY0grIx$WvYzdrR%;vA{?OVzgZsNyhqSi-p=Fn4wXPTQ-1q^wX0@vT literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/ShapeBehaviour.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/ShapeBehaviour.class new file mode 100644 index 0000000000000000000000000000000000000000..b8787806b879f88529a927031c16f5b2c6c6ffcf GIT binary patch literal 169 zcmY+8F$%&!6h!C8n5dQDCA7&e#0!YnTI2-Z@X02`?6R&YJeq|E@KEAzX)_GNJb0h) z>kVL!Wr?!Hf{=?>ASc<@gSQ-1ZleZ%s<*+K sm~5@%){8S;b59um!-RFhd62Q?%eB`g6a+#RWdO>f0P@r@kC~zP0X(TJiU0rr literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Square.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/oop/graphicshape/Square.class new file mode 100644 index 0000000000000000000000000000000000000000..244227a4d3bec969dcc0cb8c74071da9402c0095 GIT binary patch literal 488 zcmb7=!A`9gU z;6oYzEj)l8c4q#WZ)P_0{qy++-~{_2d^BsQU?;$CfIR_!p>LId7zk9)^-Sj%%(Vxd zgznO~Qe&uR>bjVYmA#SU2{X;1N#!JwRy(~)`gx`o0`btAI9GByQ+fQPtjSGA8yho^ z@2s3>I$dOPuHw-{A+0*&8agRZX?Ly!!jUO#s`}dPsV|w{y?m4r0<{WO34`|EE2Ch)C- zLCi{+Q{cgD059St2}uP$%*wbd_Ll`GB~DkwGOyq&7G%64_G^NdmawQGBv4*e5XO>> z*A%>tWeL|6bP4)KD{cz<4F$(=OU9eR>RSR%m9gTz)IKqxAcL$7F7{Qy$;rqILKDQA zgtsLW82lGBU9&DSv_uD&7`)R)mNT@aG@Z{^iYwe)R96ag6HXZ!wXmd`nxN~KUMsJa z83t3P5wo~j)VUSA!%f37^0dYbqZBhMx>_p5u2uBOQYk?OimIkFbVYBZ*3@-1R#5d^ zENz*Zo=eycsAi5J+jn6z1d5x}nwcqZk{I2`XwFnic`Z}Ut0f+*YmjZ3)Kz_5CGCMd zv@soO>+YDV|r?HKSq@h^I6ra^FbR)s;1# zv24z`U{6p9b-qE@k6|WRELJR0$LWGvE)$rNCUY4+r-@RxI>j0hMuQl_X$pSt0=r_b z=UPHB2ptB)k%s3^k*6wJAY#w>+ZBqlj#ah^J8*&ZA;Xyi`n6zaI%Q@EA2EbVV-ZeBg>s}c z?j-OoJ{GzA#Lb)#ObMR`@fkiR7v?lx$VRm7b`W{|0{4XCm(+GPm++d|U*T)P{)XYy z-j2E+J$cY*0_sz0U)NQ7vuyDq4IraJj83Q5H6yk_Gr^*!p}9gG>Zd8f^(>`1+VmQ> z2gi=9dYg&Xu6N5qWyKzHGYq}anZbQDWXo`H89Jgn1qrj=4#@2z&5DxnxIojbb2lGp zy83L1hELSNG!dgoG58Kz_xd>UinqdWcJCs%9;P#iwg(G&5>47x{Z8Bb&t<1diNWh4 zSJ!u@ppo5!+ILSJ>bwlOZ*h7~Nxf{TdWIfEBAT4r@2|uakQfh(6+aJ{n2NNXAu2{Yqun>O1@@!O9;VfAUj{Hj z=b$4%qN79wFotouA!YUuUZTN9Yw#>@p(XVbyfygf=nqR($fv6aRH0PST1Aj};X_qC zL6>bcgh=S{l^Vj!A!Q5g^G%u^q&Zwg=OfJ;x@@T*B85y4;R!{6vg2rc)34l6!_InMH9H&r-F{;~$)()kCNc@f_l4A>7}Q qzy+$|eSDASagjc(9^gB?Kqo(0xrQ?7^caqmYmw8bB|e%4WopZcCOf3H~$>{s4cJ zaTXKdK;og(Y3F%oI@7Q3k52$s*o#n&uoGdIP>#LL64%xV6ZX%}TSGn3%4#=I-H;kL zxE7}Cvoz+0vBFetXM)R|BOG)x7fiy>W^DSFZ=CZ%2jktCaI%m~{{>Ws1B=Ex$y}Of zn@Q5zKj@>kCZ38Q>O8f3&HFmxXt|`P(*Xw|PnXB*mJ=!8n~pfI-)PobcZ7@7tH3&O z9Mn6fKKM7WD&<$pasF1NM@Id2PN>dj^w1v)KscUXEwnlxM~y%z$Xbyfpdz7&l6VEI a&TND=*$?HsE=-wG!3H*S_XWh*!uAhgEPx~c literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/reflection/api/DBManager.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/reflection/api/DBManager.class new file mode 100644 index 0000000000000000000000000000000000000000..29a68d623f651e895ec8e12178c999f3a9e9d649 GIT binary patch literal 2318 zcma)8YjYD-7=BKZ>?Y~bLQ4yU0_ENdWlKfW7J;@DTTBaDM3IYb)6;azW;bp&ND)P6 z{Nf+*2QcIGgMI;rATopf=8V5czgVBMo09D4NM|zVoPE!GecsE-AAkS)0>EqdCX0QT zQp>cCi&?yjTr(1w(J|W$4VQFW&LWMe4Bo^0I_9!y##9%eU2cjhGCU?6Sa6&iBkfT18g|<~`|qfw#of^yQ)> z^MUQTrd6`d^W!s?YZatFO0%|GmVO}6(VJVg?pUT{xdrpm{4)7Rl_P>S4>Vj&JB}<^ z&R9M#%jLN=D0vCxNa83pH=e3$}C?$dt5v|B%40>;K2& zNS8cfTA;~R2TvjOuYd$nK?LKm&3PK)OCR*eQDVGhF0k^qXRK0q#niECbPVYzuws~T z`dhSYSD>@E(c!tkx7|XBXmZRiP*MATTr>N!SQ0q#YVV4y567G=mK<+IO1hYx^D2H` zUa(b_w7ksmaRq{b9_%-;1Y4kgQ#DeHZrQ+XI0lMfL<5_WjFM}>Qz8fIDcC3+zfdVk zH+We(I!XpUgD&_!9dC%vS~#N17>`_FMyB;Q@~mla~y9jRyvfDx=3=sVvri0$b}| zMm-lpA=U{3>4FR<9ILE~r?;=6xUh3Z?@uA`z1?`nYO#Zb=z(7<+8OZK&pi%Mhb*))3e3-oD1Rj3t29 z5@Z!P(&*#HsBG}DMq)lf+u^{t;#+xwmsBMjA5Aq+sC?O*$9}#E`}i<{ZxD-^-)tg& zncM~URR2?mM?5s)AXhCUHscV_M#O-_IKr=tsz_2OEPkZ23~4|2SJBjtL>0+3B%UE9 z@H=`Uq81XhXV4X~`8m?po+9&GOd|If+2?5Hh0(U9ik5*;1rJrUR8?TiA|8a@^;$`W<#sVmD>>QmPxP*n^*V z_n1&9m~Ie?Riw~I4QX;8!~l*#r|b|0ah#AY;Ue)KqCE!}aDrBnoMsdJvoK6K!ibZ2 zo%=ZsqEmQ-9xh@AZ&IQOZ;^f)so{05nvM}2qdHFWCz!o;ilyU39dGM61EJ&WU(o)f z{tWewMTx^rYHXs$uIJc6)OY3v+Pa=#*Ff9uC+Hsd1$*k1&>6aRm?0e@I7bOcAA#r( ZL+*@}V4OjK9NTanlQbb1o~opG{sGz?NWlOA literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/reflection/api/Table.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/reflection/api/Table.class new file mode 100644 index 0000000000000000000000000000000000000000..6826bac917aefeb840ef368fb8ab00415b1491de GIT binary patch literal 441 zcmaiwJx>EM42Iv7mZQg4`B)G_AchJU$iT?NP$VQM)%8F^Olf6~RJo)|bCt?ZW8eqy zqY%ChT!%^waUA>c>)78vpI-p3uos~fVJE__Kr^U;p{~kFVE^p=ex#;K8f7!t4_@2s zS|IMb!Vl?I8)o9PXVshi$CbOer;m!!&P6qr0+p6?jSxqUht6GQd%rN>$q-pN2Jw-n?D zc^BL}Tj}Y|(6IcfRAVjYa|^Vp1w9T%oEJE*LJNad%V-M-)cCCM_C=lhqQPDbt8*J+ XjqgK#H<^hE>)60%>Ape`wy^yRj+=gL literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/reflection/model/Employee.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/reflection/model/Employee.class new file mode 100644 index 0000000000000000000000000000000000000000..45d6b97e7316c711b9f5949f2c21a0042ea11fe7 GIT binary patch literal 595 zcmaix%Sr<=6o&uUo2{*_^;%uIQ&EGsRD@dULV6J^-Dk$wrpzQ|CL`!uxe{FX06vs> zGTsn`F7hWQ=j6|qlehPmR{+P@Dj|c70vZKuGGw&~B}2V45%+=zLXY^sMoN!P7#i1! zwkniE6)P{0O|6X;Rv8^L9CRYXtrVe_mOskKSTiQ&k-Q6}?~1sXD&8_d5^C})`RS^c z-j?k(yKRQd#CW8a{d0!=snW`xQMj`^B&?RXC9G;kY1vCcPewO_5FDuSMKBbRa`D$@ z){Yf19nEG6$u{8aa2l8gDIM3qB#|#KlryhGO%1cK51` zGAaywW~csAG1PuPqwh_qo!G`4{TfKAH^`CZDO#YpKw~~ek*3mr30K1$2Qp+l7p0=G~jkKJub67$>%`d0A@^j@X<=0}Ye*ivXl0X0e literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/TransientSerialization.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/TransientSerialization.class new file mode 100644 index 0000000000000000000000000000000000000000..889bf20869fd3e85283d4dc03159c8b4e74f6c82 GIT binary patch literal 2728 zcma)8OK%fb6#lLsnTc_LIs{@MFr+*Zh-1ndLwT0al*FNRND1`8WIRbG*fVB4CXhl` ztyGrm+GVRsk=Vf^ks1lwO%`2rQK{-rV2Qfyg3|AfUlS1tBF(+$o^$Rw-#PcYH~#&< zU!DRuh_7PUfk6cysko$KNX2jrA!J)Ig3B>{j87Eg6pX645xvvv>Ihbd=S4I)grE{KZ*;6MZ zqR^cK0v!R{=(Ow1N)X%}b{yv4TD4kEdSqh8G`x|DSE_i7K}a&gq&>+Bwl};6tb&*x;bKVQ(x<<&}w=qljY`MS*@pw{6GM3{uiFHC>w| z5^dI!MNOO9ly%#*t2$dRnwl)?Rz2%VB9eEytqrC}G}Cn*S91)b;<{#Do1K;+ORi&> zfN!z|cjCBtT zIg|dv@$aUV(yVd=n`St!TPb;F{tnIT4&=IaSI^z;VW zR>RK!TN*$47lM%Yo#Rff(wqh7=-x$$$G&+N#};3yVmIY@)d73Z!&NJKv6mWd4u69v z*APdS5E@T}6Olx85iLVcpzK?Kx`fv8CB()PYZeh-MBA{)_EEpKZyA?T%joD^z`A*y z$wX4g$O7J($Kk4`KNCqtvdPG^Oq8x&P1i)GC6#RPT@~q?j6R!3=kOD>CpIjgV;*r| z-b8r`oy?u|b8lY67MXhiTV>>BY)(dgL+A%2l968#%0!7b871HVu&&pDQPTvb1c1?y z$f&8L+5py-R0wQm09X~I1Xc&Ro$_O>!(kl9N&YJ6K?>R0JjOQPKpsm$7B5EbwvI$u#8QE*zp83kt*oP*#H8{lw}-z)a5Wrexn5`M+Vp{fly or{Mf01s|v{aY(@hdS&^oh@;lyNGr3yArhkvs04bEt|5H*Kinar6951J literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/USPresident.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/USPresident.class new file mode 100644 index 0000000000000000000000000000000000000000..904ec276d122bf96f5070fcbabf5ac8579829c43 GIT binary patch literal 950 zcmb7CTWb?R6#gc+-NbF0Cb89eOVw(!O}bv{gH(O6B2UNiwukHoIXn@u83Y zA_dcef6f&2B7EdC|a=m``$;WQekr<(bd{wT1?tq@rGyCaXM+8?UOK@E2VD&0=) z7pK}AZsS9T#<%6*ES3fG&05kv%C2z2YSy@o6rSTyymfFMs{*b6QcqNW^Lo)gPy<8L zh*LWBI`QzSWpUHfb=H}a;ELaqsyg<=AIw#0(eT8^^j8r*&gpB(cSu*8Z;#=(7iJxb`K+6%%e2md9 z(wd7gmT-xDC&9yIT%kzNB-Uu)VVQe?KKgTAdSR?bV@&E~eJ=U3~npY`G;o48Hu+N?V literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/Counter.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/Counter.class new file mode 100644 index 0000000000000000000000000000000000000000..608355556383d464ed62e712f075e5f36ff20a00 GIT binary patch literal 1023 zcmd5*T~8B16g|_g-L0!&0SgFP#E%xF>&KfAA0**{G)Pj@#K-A&LWgX3>vq>fe}j+y z4;7P=XyOm>*Z2#JXXpkr+3->JC7qI*&4HFd$h+TowmJW6DTp(X>bOZ|9QBMg>wREWV z(m_|nuVgo%r_zdi8FXZ<%|3G$lD-}Zc&#|{5+w(rO1$?fj*_TP>m~hI$==Az0KM%A z@TP#HLqApn6($1qmLFs_l-p4n`)WrUL^n%s9?G}U#T2GpT*WmD4_wsI5U84f7s&9y zYbUV|4_>4?=ow;*9T`ND;I#}o4N_fGqeMM(v4(YH9=g~-(}L&X5grR{{1XR(=`-|~ z-9zP*$vId19l-`vHA)$nYn>$P$lGU~39F@8l%XVtLlyQ2UY}%~BeU7K;L7;%;8K0} zZ(%!$CW;8m)-NXVf|*MSVrvXdc|pjEFDs~n6*im8=Hm;Rx8N$zHJ^s|I(Hst!MV70 z4Dp4F94fS>6K4rCT)UG5%wmo^2RBX+|6;3}@%ae3viyqN5%S+rczujwr8I^`_ZapV z&KTwYDaG*Q4?^3dJm6=O?h1xt zLn`qw9CU0+}U1S(87UsiHa-D*Rt6tC=^Jh3;5RMi+;F5-`R3962 z*rqi!K+Oqo^grb3x)^ejHYf%{S)3qA^13HMAB|7Cc=Q+0Ng^SA_y+bmPG`xwG>}J* ztUoCruRtEd((Ll>*ar&lNX*_jNQL@Pk~+I9MFJ}k*zzyX!W1+~S;wqISrE@MR;bbu JAi?PbvOlzTqA&me literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter$2.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter$2.class new file mode 100644 index 0000000000000000000000000000000000000000..fa7fda0d9c52b7ded0ed1d83ca261a4a4f7518c5 GIT binary patch literal 680 zcmbVJ%TB^T6g>l#0x3Qa5%95cp(a|R3u7>Dh#HgX2II!nP$qOtnMtNo6ZtDw8W(6k2&{oK0e>x0UTko3Y~9=IF(A;Glu;3&K-l((S51}tjby?A2JcEKVLCBS5<#AJV6<-qA1Yz}kucio zh@@{LBX~dYL!BxsjNg4yq0vf?L}%jJI&4!bCRGgOu1-xTE@W1|{ws6;fj@HU^jw9p zPNW)K3mfUai>8Mb);!Fi;9}jw1_}%(|L%ujF{|XqTn+r&asLd*|AeCj54oh_>f86h zH*D7$8lasKu=h9Q>ADz7k~S!YLRlOjPxNMAj(!@Scya0GlO~cdxBCM2JPsF0W?`U) z5=n28fHEp%G0e{%Uyf~{@`~K-e1p`f4$z>=O?uKIur&f({{dQ=g66S6nK>+CiL`?% NmMIeyCBjJq#V^X=qH_QM literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter.class new file mode 100644 index 0000000000000000000000000000000000000000..ae83139f93c7ca72b977f71f8b6bb8a30839bfaa GIT binary patch literal 778 zcmbtST}vB56g{)~*mRqkRBilhjja#%0~hT>5lf*23c_k1B7*d3vJS~eG7GblLj701 zC{*wV^hb$jHiZ=Ilg_gD&YU~{*mPP4Ib%EsMaCbgN-=c+S7_9!@#+6c5Z ze9f7EujcuyFX8Kk%OtwnzZ@F`XyT8f_bktjY_tCnUsP@KmEr3k#HJQf!gCfZq}$0hY-C77%c} J{i<3zw>$Ik`SuRr2z3WVRBWtZbskj*Ygo6iVPVt47DMqwDrwFb<{Hf| zL;hU%1;bKXDsh>FJrUjVUO-5tt$iMJc_h>N2h5wHj2TYbk@k$>p%TV>6p=Q1NYOLH zNbr9Alka@0jMU0I4|p8kBub@HEwYXh#o%;w68YjnW_G_gha-N^UChI_ulbDIvQ;{-t Hb6EZYZj6%8 literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/thread_creation/ClassThread.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/thread_creation/ClassThread.class new file mode 100644 index 0000000000000000000000000000000000000000..5164f9be84b6ac95903c39f12abc6061df3e233f GIT binary patch literal 583 zcmbVJ%T5A85Uk;~4^a@r_XBU>!992|2IGaq6EP+bu4aGycn6b)*tkaWD{Jj}Lr8DjhxKexHXjsb^r$Ok~8+>V(=ef(J?%?@5H(=m|y7OhUm& z(JbE#sWMV4ukG_F>ZQ#V8HcfAaJxDVhvHHuX5}A@<6C~ui?Co@*eYThI}Ej{xIRn< z)y0DmY9vM$c8l1x1BA}&pY-o>8N|xHY4y7_(Ll*{g zQuPm*!MaOGJ{?5#TynZ42m}{qJW@iK_i4{d@w_MQiilMWI9#x%}3w# zQ}m%ElK27sj_<~GIv_=e38u;3XRm!Zd+mLuKYo4t4qy~Z2GZ!)aK%82(pdvh^cxt! zU>sMG(=cQ}N576?r7h(dQKxH4TsK(ahK`#GzNN%%9e0!-(=aX&n{-?!m=cI&2UZ25 zvtCgObmkpbF4Zb)(qFOH%0!ZRuV9x~ZQoJ$E*K5govOfO-uJ9P+7(v@)_duDfwxX+ z1?#@Fi`8BIx8w=~h{Y1%LG zmedh$0ll&nmJ^7(^6lO^*;FdTc#*N})%=2-cNC$n<}QZS#U^@?5g7k}G6G}AOP(#; z)oR#?h6xjs$Y{80VhZ;JGJj8FrskB3(&s4tFzws)9nW`yt#K3gF>PW7v+DG~#2n@| zJT&nL3tZ@ahHFmbrJ*FE~}%H)>*0MJM)ee!8|H3&8`tSag_lV$``^d#O%#Y=@tcsvQ10c+xH=8moyXGN-|)n2HnPc zWv9K_g@J#h=z$j&7U<3%4rI|(gX+O11vHM;4a%gKKB`H6C>ont;w0HtwYjY*8&Yn9 z%8m2s6t;Z!SG}*nX03^ zDehP`_K6I_V1sS^2Wm$G9q6VUK^O8!;W@1roJGKCd?F!5wl5@vb3B1rA33>R(oNt4 OF5qHgdY9;F!R6l*K|$yM literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/canvas/Canvas.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/canvas/Canvas.java new file mode 100644 index 0000000..46aa8a3 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/canvas/Canvas.java @@ -0,0 +1,14 @@ +package ro.teamnet.zerotohero.canvas; + +import ro.teamnet.zerotohero.oop.graphicshape.Circle; + +/** + * Created by Buli on 27.10.2014. + */ +public class Canvas { + + public double getArea(){ + Circle myCircle = new Circle(); + return myCircle.area(); + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/gc/DemoObject.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/gc/DemoObject.java new file mode 100644 index 0000000..ef959d4 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/gc/DemoObject.java @@ -0,0 +1,38 @@ +package ro.teamnet.zerotohero.gc; + +import java.lang.management.GarbageCollectorMXBean; + +/** + * Created by Buli on 27.10.2014. + */ +public class DemoObject { + + private static final int bufferSize = 100000; + private String temp; + private String objectRef; + private static int count = 0; + + public DemoObject() { + this.objectRef = this.toString(); + StringBuilder s = new StringBuilder(); + + for(int i=0; i5){ + System.gc(); + } + + } + + @Override + public void finalize()throws Throwable{ + count --; + System.out.println(count); + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/gc/GCExample.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/gc/GCExample.java new file mode 100644 index 0000000..da11761 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/gc/GCExample.java @@ -0,0 +1,20 @@ +package ro.teamnet.zerotohero.gc; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Buli on 27.10.2014. + */ +public class GCExample { + + public static void main(String[] args) { + List demoObjects = new ArrayList(); + while(true) { + new DemoObject(); + demoObjects.add(new DemoObject()); + } + } + + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/AbstractShape.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/AbstractShape.java new file mode 100644 index 0000000..1c43135 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/AbstractShape.java @@ -0,0 +1,14 @@ +package ro.teamnet.zerotohero.oop.graphicshape; + +/** + * Created by Buli on 27.10.2014. + */ +public abstract class AbstractShape { + + private double value = 21; + + public double area(){ + return value; + }; + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Circle.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Circle.java new file mode 100644 index 0000000..a784822 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Circle.java @@ -0,0 +1,54 @@ +package ro.teamnet.zerotohero.oop.graphicshape; + +/** + * Created by Buli on 27.10.2014. + */ +public class Circle extends Shape{ + + private int xPos,yPos, radius; + + public Circle() { + this.xPos = 41; + this.yPos = 30; + this.radius = 2; + } + + public Circle(int xPos) { + this.xPos = xPos; + } + + public Circle(int xPos, int yPos) { + this.xPos = xPos; + this.yPos = yPos; + } + + public Circle(int xPos, int yPos, int radius) { + this.xPos = xPos; + this.radius = radius; + this.yPos = yPos; + } + + @Override + public double area(){ + return Math.PI * radius*radius; + } + + @Override + public String toString(){ + return "center = ("+ xPos + "," + yPos + ") and radius =" + radius; + } + + public void fillColour(){ + System.out.println(super.color); + } + + public void fillColour(int param){ + super.setColor(param); + System.out.println("The circle color is now " + param); + } + + public void fillColour(float param){ + super.setSaturation(param); + System.out.println("The saturation is now " + param); + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Circles.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Circles.java new file mode 100644 index 0000000..e973ce3 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Circles.java @@ -0,0 +1,23 @@ +package ro.teamnet.zerotohero.oop.graphicshape; + +/** + * Created by Buli on 27.10.2014. + */ +public class Circles { + + public Circles() { + } + + public double getAreaPub(){ + Circle circle1 = new Circle(); + return circle1.area(); + } + + public void getAreaDef(){ + Circle myCircle = new Circle(); + myCircle.fillColour(); + myCircle.fillColour(2); + myCircle.fillColour((float) 21.2); + } + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/ImmutableClass.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/ImmutableClass.java new file mode 100644 index 0000000..a66cc1c --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/ImmutableClass.java @@ -0,0 +1,27 @@ +package ro.teamnet.zerotohero.oop.graphicshape; + +/** + * Created by Buli on 27.10.2014. + */ +public final class ImmutableClass { + + private final int field; + private final float field2; + + private ImmutableClass(int field, float field2) { + this.field = field; + this.field2 = field2; + } + + public static ImmutableClass createNewInstance(int fld, float fld2){ + return new ImmutableClass(fld,fld2); + } + + public int getField() { + return field; + } + + public float getField2() { + return field2; + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Point.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Point.java new file mode 100644 index 0000000..94e1b21 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Point.java @@ -0,0 +1,29 @@ +package ro.teamnet.zerotohero.oop.graphicshape; + +/** + * Created by Buli on 27.10.2014. + */ +public class Point { + + private int xPos, yPos; + + public Point(int xPos, int yPos) { + this.xPos = xPos; + this.yPos = yPos; + } + + @Override + public boolean equals(Object other){ + if(other == null){ + return false; + } + + if(other instanceof Point){ + Point anotherPoint = (Point) other; + if((xPos == anotherPoint.xPos) && (yPos == anotherPoint.yPos) ) + return true; + } + + return false; + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Point3D.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Point3D.java new file mode 100644 index 0000000..6b2f5af --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Point3D.java @@ -0,0 +1,14 @@ +package ro.teamnet.zerotohero.oop.graphicshape; + +/** + * Created by Buli on 27.10.2014. + */ +public class Point3D extends Point { + + private int zPos; + + public Point3D(int x, int y, int zPos){ + super(x,y); + this.zPos = zPos; + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Shape.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Shape.java new file mode 100644 index 0000000..fb6ffaa --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Shape.java @@ -0,0 +1,24 @@ +package ro.teamnet.zerotohero.oop.graphicshape; + +/** + * Created by Buli on 27.10.2014. + */ +public class Shape extends AbstractShape implements ShapeBehaviour { + protected int color; + protected float saturation; + + + public double area(){ + double value = 0; + System.out.println("Area"); + return value; + } + + public void setColor(int color) { + this.color = color; + } + + public void setSaturation(float saturation) { + this.saturation = saturation; + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/ShapeBehaviour.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/ShapeBehaviour.java new file mode 100644 index 0000000..4ef73a5 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/ShapeBehaviour.java @@ -0,0 +1,10 @@ +package ro.teamnet.zerotohero.oop.graphicshape; + +/** + * Created by Buli on 27.10.2014. + */ +public interface ShapeBehaviour { + + public double area(); + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Square.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Square.java new file mode 100644 index 0000000..d9aeb0b --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/Square.java @@ -0,0 +1,17 @@ +package ro.teamnet.zerotohero.oop.graphicshape; + +/** + * Created by Buli on 27.10.2014. + */ +public class Square extends Shape{ + + private int side; + + public Square(int side) { + this.side = side; + } + + public double area(){ + return side*side; + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/runapp/RunApp.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/runapp/RunApp.java new file mode 100644 index 0000000..731748a --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/runapp/RunApp.java @@ -0,0 +1,42 @@ +package ro.teamnet.zerotohero.oop.runapp; + +import ro.teamnet.zerotohero.oop.graphicshape.*; +import ro.teamnet.zerotohero.canvas.Canvas; + +/** + * Created by Buli on 27.10.2014. + */ +public class RunApp { + + public static void main(String[] args){ + Circles myCircles = new Circles(); + System.out.println("The default circle area is " + myCircles.getAreaPub()); + + System.out.print("getAreaDef result: "); + myCircles.getAreaDef(); + + Canvas myCanvas = new Canvas(); + //myCanvas.getArea(); + + Shape myShape = new Circle(10); + System.out.println("New circle area: " + myShape.area()); + + ShapeBehaviour myShapeB = new Square(10); + System.out.println("New square area: " + myShapeB.area()); + + Object p1 = new Point(10, 20); + Object p2 = new Point(50, 100); + Object p3 = new Point(10, 20); + + System.out.println("p1 equals p2 is " + p1.equals(p2)); + System.out.println("p1 equals p3 is " + p1.equals(p3)); + + //ImmutableClass newObject = new ImmutableClass(2,2.3); + ImmutableClass newObj = ImmutableClass.createNewInstance(2,(float) 2.3); + System.out.println("Field immutable: " + newObj.getField()); + System.out.println("Field2 immutable: " + newObj.getField2()); + + + } + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/Column.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/Column.java new file mode 100644 index 0000000..b208b99 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/Column.java @@ -0,0 +1,16 @@ +package ro.teamnet.zerotohero.reflection.api; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Created by Buli on 28.10.2014. + */ + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Column { + String columnName(); +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/DBManager.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/DBManager.java new file mode 100644 index 0000000..09bd6c5 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/DBManager.java @@ -0,0 +1,43 @@ +package ro.teamnet.zerotohero.reflection.api; + +import ro.teamnet.zerotohero.reflection.model.Employee; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; + +/** + * Created by Buli on 28.10.2014. + */ +public class DBManager { + + public static void insert(Object o){ + if(o.getClass().getAnnotation(Table.class).tableName() == null && o.getClass().getAnnotation(Column.class).columnName() == null) + throw new IllegalArgumentException(); + + Table table = o.getClass().getAnnotation(Table.class); + System.out.println("Table name: " + table.tableName()); + + Field[] columns = o.getClass().getFields(); + for(Field column:columns){ + + Column c = (Column) column.getAnnotation(Column.class); + System.out.println(c.columnName()); + + try { + System.out.println(column.get(o)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + + + } + + public static void main(String[] Args){ + Employee emp = new Employee(); + emp.name = "Ion"; + emp.job = "CEO"; + + insert(emp); + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/Table.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/Table.java new file mode 100644 index 0000000..c023add --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/api/Table.java @@ -0,0 +1,16 @@ +package ro.teamnet.zerotohero.reflection.api; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Created by Buli on 28.10.2014. + */ + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Table { + String tableName(); +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/model/Employee.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/model/Employee.java new file mode 100644 index 0000000..9fa66eb --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/reflection/model/Employee.java @@ -0,0 +1,19 @@ +package ro.teamnet.zerotohero.reflection.model; + +import ro.teamnet.zerotohero.reflection.api.Column; +import ro.teamnet.zerotohero.reflection.api.Table; + +/** + * Created by Buli on 28.10.2014. + */ + +@Table(tableName = "EMP") +public class Employee { + + @Column(columnName = "NAME") + public String name; + + @Column(columnName = "JOB") + public String job; + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/TransientSerialization.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/TransientSerialization.java new file mode 100644 index 0000000..e499b28 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/TransientSerialization.java @@ -0,0 +1,42 @@ +package ro.teamnet.zerotohero.serializare; + +import java.io.*; + +/** + * Created by Buli on 28.10.2014. + */ +public class TransientSerialization { + + public static void main(String []args) { + + USPresident usPresident = new USPresident("Barack Obama", "2009 to --", "56th term"); + System.out.println(usPresident); + //Serialize the object + + try (ObjectOutputStream oos = new ObjectOutputStream(new + FileOutputStream("USPresident.data"))){ + oos.writeObject(usPresident); + } + catch(FileNotFoundException fnfe) { + System.err.println("cannot create a file with the given file name "); + } catch(IOException ioe) { + System.err.println("an I/O error occurred while processing the file"); + } // the ObjectOutputStream will auto-close, so don't have to worry about it + //De-serialize the object + + try(ObjectInputStream ois = new ObjectInputStream(new + FileInputStream("USPresident.data"))){ + Object obj = ois.readObject(); + if(obj != null && obj instanceof USPresident){ + USPresident presidentOfUS = (USPresident)obj; + System.out.println(presidentOfUS); + } + }catch(FileNotFoundException fnfe) { + System.err.println("cannot create a file with the given file name "); + } catch(IOException ioe) { + System.err.println("an I/O error occurred while processing the file"); + } catch(ClassNotFoundException cnfe) { + System.err.println("cannot recognize the class of the object - is the file corrupted?"); + } + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/USPresident.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/USPresident.java new file mode 100644 index 0000000..69b36f1 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/USPresident.java @@ -0,0 +1,25 @@ +package ro.teamnet.zerotohero.serializare; + +import java.io.Serializable; + +/** + * Created by Buli on 28.10.2014. + */ +public class USPresident implements Serializable { + private static final long serialVersionUID = 1L; + + private String name; + private String period; + private transient String term; + + @Override + public String toString() { + return "US President [name=" + name + ", period=" + period + ", term=" + term + "]"; + } + public USPresident(String name, String period, String term) { + this.name = name; + this.period = period; + this.term = term; + } + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/Counter.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/Counter.java new file mode 100644 index 0000000..01fb31f --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/Counter.java @@ -0,0 +1,27 @@ +package ro.teamnet.zerotohero.threads.counter; + +/** + * Created by Buli on 28.10.2014. + */ +public class Counter { + + public static long counter = 0; + + public static void increment(){ + Counter.counter++; + System.out.println("Valoarea counterului este:" + Counter.counter); + + Counter.counter++; + System.out.println("Valoarea counterului este:" + Counter.counter); + + Counter.counter++; + System.out.println("Valoarea counterului este:" + Counter.counter); + + Counter.counter++; + System.out.println("Valoarea counterului este:" + Counter.counter); + + Counter.counter++; + System.out.println("Valoarea counterului este:" + Counter.counter); + } + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter.java new file mode 100644 index 0000000..897d201 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/SyncronizeCounter.java @@ -0,0 +1,35 @@ +package ro.teamnet.zerotohero.threads.counter; + +/** + * Created by Buli on 28.10.2014. + */ +public class SyncronizeCounter { + + public static void main(String[] Args){ + + Thread t = new Thread(){ + @Override + public void run(){ + Counter.increment(); + Counter.increment(); + Counter.increment(); + Counter.increment(); + } + }; + + Thread t2 = new Thread(){ + @Override + public void run(){ + + Counter.increment(); + Counter.increment(); + Counter.increment(); + Counter.increment(); + } + }; + + t.start(); + t2.start(); + } + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ClassRunnable.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ClassRunnable.java new file mode 100644 index 0000000..2ce78c0 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ClassRunnable.java @@ -0,0 +1,14 @@ +package ro.teamnet.zerotohero.threads.thread_creation; + +import ro.teamnet.zerotohero.threads.counter.Counter; + +/** + * Created by Buli on 28.10.2014. + */ +public class ClassRunnable implements Runnable{ + + public void run(){ + System.out.println("Runnable class implemented"); + } + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ClassThread.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ClassThread.java new file mode 100644 index 0000000..e69270e --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ClassThread.java @@ -0,0 +1,15 @@ +package ro.teamnet.zerotohero.threads.thread_creation; + +import ro.teamnet.zerotohero.threads.counter.Counter; + +/** + * Created by Buli on 28.10.2014. + */ +public class ClassThread extends Thread{ + + @Override + public void run(){ + System.out.println("Thread class extended"); + } + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ThreadTester.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ThreadTester.java new file mode 100644 index 0000000..7f00c53 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/thread_creation/ThreadTester.java @@ -0,0 +1,26 @@ +package ro.teamnet.zerotohero.threads.thread_creation; + +import com.sun.media.sound.EmergencySoundbank; + +/** + * Created by Buli on 28.10.2014. + */ +public class ThreadTester { + + public static void main (String[] Args){ + ThreadTester myThread = new ThreadTester(); + + Thread newThread = new ClassThread(); + newThread.run(); + + System.out.println("newThread priority:" + newThread.getPriority()); + System.out.println("newThread name:" + newThread.getName()); + + newThread.setPriority(10); + newThread.setName("Exercise 3"); + + System.out.println("newThread priority:" + newThread.getPriority()); + System.out.println("newThread name:" + newThread.getName()); + } + +} diff --git a/ exercises/teamnet/teamnet.iml b/ exercises/teamnet/teamnet.iml new file mode 100644 index 0000000..08ae11a --- /dev/null +++ b/ exercises/teamnet/teamnet.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + From c107644ff549d604d8d448c91a752ccdc1bf0327 Mon Sep 17 00:00:00 2001 From: Bulimac Vlad Date: Tue, 28 Oct 2014 22:19:26 +0200 Subject: [PATCH 02/12] Added WaitThread.java for ex 5 from Thread Ex Added TestStudent.java and Student,java for ex 6 from Thread Ex --- exercises/teamnet/.idea/workspace.xml | 487 +++++++----------- .../zerotohero/serializare/Student.class | Bin 0 -> 893 bytes .../zerotohero/serializare/TestStudent.class | Bin 0 -> 2684 bytes .../zerotohero/threads/counter/Counter.class | Bin 1023 -> 1023 bytes .../zerotohero/serializare/Student.java | 24 + .../zerotohero/serializare/TestStudent.java | 43 ++ .../zerotohero/threads/counter/Counter.java | 2 +- .../threads/counter/WaitThread.java | 56 ++ exercises/teamnet/student.data | Bin 0 -> 137 bytes 9 files changed, 319 insertions(+), 293 deletions(-) create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/Student.class create mode 100644 exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/TestStudent.class create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/Student.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/TestStudent.java create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/WaitThread.java create mode 100644 exercises/teamnet/student.data diff --git a/ exercises/teamnet/.idea/workspace.xml b/ exercises/teamnet/.idea/workspace.xml index 3972693..5ba703e 100644 --- a/ exercises/teamnet/.idea/workspace.xml +++ b/ exercises/teamnet/.idea/workspace.xml @@ -23,54 +23,99 @@ - - + + - - - - - + + + - - + + - - + + - + + + + - - + + - - + + - + + + + - - + + + + + + + + + + + + + + + + + + + + + + - - + + - + + + + + + + + + + + + + + + + + + + + + + @@ -101,15 +146,18 @@ @@ -132,7 +180,7 @@ - @@ -147,6 +195,7 @@ + @@ -190,48 +239,6 @@ - - - - - - - - - - - - - - - - - @@ -263,103 +270,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -380,20 +292,20 @@ - - + + - - - + - - - + - - - + - - - + - - - - - - - + + + + + - + - - + + @@ -738,15 +650,17 @@ - + + + - - + @@ -768,7 +682,7 @@ - + @@ -801,37 +715,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -857,7 +740,6 @@ - @@ -879,7 +761,6 @@ - @@ -887,7 +768,6 @@ - @@ -895,7 +775,6 @@ - @@ -924,7 +803,6 @@ - @@ -946,7 +824,6 @@ - @@ -954,7 +831,6 @@ - @@ -962,7 +838,6 @@ - @@ -1061,7 +936,6 @@ - @@ -1072,58 +946,108 @@ - + - - - + + - + - - - + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + - + - + - - - + + + + + + + + - - - + + + + + + + + - + @@ -1131,63 +1055,42 @@ - + - + - + - - + + - - - - - - - - - - - + - - - - - - - - - - - - - - - + + + - + - - + + - + + diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/Student.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/Student.class new file mode 100644 index 0000000000000000000000000000000000000000..c7072777ca60ad096f85c7f3241dc9a9786cf975 GIT binary patch literal 893 zcma)4%Wl&^6g^|Ru@l@-oU{d6z@-HoH>r6nK`cP36e%i;RF%4%BttuuV^@yDqF)6P zNhOf@06q$FXY2|I3yIBr%;TJM&&9Tgs{uxn$lffe`;o~Zm( zg=Y=|2OU+0Hui0FZS)unIbmRZhWbaD&GI8Y6%5|sf`8&s%#*Wdm}fFMd(Gg){AR!Q zMkX?U%Mb+p>e1>-=Y+v}pH2w+_CO}$Xg(c@?3j;YO_q*%e8MxS`f}0A&*h9^e~_h7 zF8DMNd2}VRG*8bdMl(UDV|m3hK?3I!k>pBYo)&5u+Cir(gP}1@=h;{sN=59JHxJaX zF4l42Vhwj(cxbt3qs6fKw-4{;GM z*v12f&VNtDu=a=k!{|bca~e!9$ut_?SfEWb1LbjzUtWrY9<&!!r>`1P4nxju2mOC< zV~74!6ZCd4>Ccfx6ro(wnT(=r(Ed6$C~i_0Q*Tjjhu2`?)&fS@UBC=`3s_(D>AMs+ z=r4khEkdpnZj+E(gnN%x!{R>fV~aXM(!5MpirLVW;x>tsoGqD8wGtruj+N7E)I56$ sC;SRyiMrP)YLk+8tEeqXOSqp2&VUkCBOoPBiEwotl_D4(>Qj$?1EkKuQ~&?~ literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/TestStudent.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/serializare/TestStudent.class new file mode 100644 index 0000000000000000000000000000000000000000..c6a7005ac7903b385b0b67fbac3359993e404e39 GIT binary patch literal 2684 zcma)8U2has7=F%v&9H2tEVOh=fw9oiLfcgY)bb5dtn>rjQmLpoot?H*wlnMOY+I@% zc*#Fd(DW3yY#C-G1}m0cvW$%1<6|A*#F3}o?q0RoRu}JCs$@E0bN97ZxoALB@nylO*7!`Eh;IHtng>m1sbxxVcr=w3c=|qI7{&biW{e- zsG>kZ)7+GGOP*=TiU~A^4z5q8lfoe!7U+KYkypyW!x+ySETM9#l(**$Q%1-OvpyPKZO$J z1^P_Gaa>Q_9^ z^#rskgH0zdu(!G<(++7uW_UM+C48R37nqk&1%aLlM^enal%arLugcbH61Z54Xu8vm zy<`Q+no@hZI~7c*Y+g6LSGSA7JgAH5dS0pETeLLnXD0s}&qVQY7h&4e5TSBR1?-qTF0*bP5;TP#T zU&Z>vR+ct7hRnQL1?iOMlUl`+0t~$=GKr+rNi~N(UEQHFRFaUdQ_06G{A=e&3j8Js zdEMD|aF$^&*vF5qLOcqVJJ}`zqlzOOr^*iKLN{mIa1_UA;pXTf;+#Wd))1M9rK9QC zD&j+HNKC9jnMkXv*tUw~uo&q%wu0?F>$ujtj;5X!q?U1^Kh~?oRIB_ zndHF`NuA?I*oj`eh7n!9zr5|B=Z}Q82oAUu&hnzR?_4Da3`}^39bv(n*oPCQY zcwXs$rQh%P1AlV<9KS)%ABd!A;6B-FI1uz5+#iKJ-X&V(!8TwA8SEs7Mk4MYVk2>y ziMWeTW*YZ6zK=cll0P*bpoOR!9-U9{qm zXy>>C9ikJRqK^`ilKP66rzo->)*%L?GDWsM@lR&ks^t|CNKS+kQA z-9uuZ!W-QCOD)P@m63{XP{5mb3lVauL?IIu{WwiqXDuFui!(S&J`H4fj*$hhNP$0MS2jRvz WYBi2rCHj9yx*9|y(Rb(?!Qj6P)sZg% literal 0 HcmV?d00001 diff --git a/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/Counter.class b/ exercises/teamnet/out/production/teamnet/ro/teamnet/zerotohero/threads/counter/Counter.class index 608355556383d464ed62e712f075e5f36ff20a00..960357742e3c6e0f51f7a4f3726ccb8025984911 100644 GIT binary patch delta 14 Vcmey*{-1rrStdr!&F7d5838cf1#18R delta 14 Vcmey*{-1rrStdr#&F7d5838aJ1xo+` diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/Student.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/Student.java new file mode 100644 index 0000000..98578aa --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/Student.java @@ -0,0 +1,24 @@ +package ro.teamnet.zerotohero.serializare; + +import java.io.Serializable; + +/** + * Created by Buli on 28.10.2014. + */ +public class Student implements Serializable{ + + int id; + String firstName; + String lastName; + + public Student(int id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + @Override + public String toString(){ + return "Student id " + id + ", First name " + firstName + ", Last name " + lastName; + } +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/TestStudent.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/TestStudent.java new file mode 100644 index 0000000..677fc27 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/serializare/TestStudent.java @@ -0,0 +1,43 @@ +package ro.teamnet.zerotohero.serializare; + +import java.io.*; + +/** + * Created by Buli on 28.10.2014. + */ +public class TestStudent { + + public static void main(String[] Args){ + + Student newStudent = new Student(1,"Vlad", "Bulimac"); + + try(ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("student.data"))){ + os.writeObject(newStudent); + } + catch(FileNotFoundException fnfe){ + System.err.println("cannot create a file with the given file name "); + } + catch(IOException ioe){ + System.err.println("IO Error"); + } + + try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream("student.data"))){ + Object obj = ois.readObject(); + if(obj != null && obj instanceof Student) { + Student newStud = (Student) obj; + System.out.println(newStud); + } + } + catch(FileNotFoundException fnfe){ + System.err.println("cannot read a file with the given file name "); + } + catch(ClassNotFoundException cnfe){ + System.err.println("cannot recognize the class of the object - is the file corrupted?"); + } + catch(IOException ioe){ + System.err.println("an I/O error occurred while processing the file"); + } + + } + +} diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/Counter.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/Counter.java index 01fb31f..4a2ae35 100644 --- a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/Counter.java +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/Counter.java @@ -7,7 +7,7 @@ public class Counter { public static long counter = 0; - public static void increment(){ + public static synchronized void increment(){ Counter.counter++; System.out.println("Valoarea counterului este:" + Counter.counter); diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/WaitThread.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/WaitThread.java new file mode 100644 index 0000000..be1f820 --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/threads/counter/WaitThread.java @@ -0,0 +1,56 @@ +package ro.teamnet.zerotohero.threads.counter; + +/** + * Created by Buli on 28.10.2014. + */ +public class WaitThread { + + public static void main(String[] Args){ + + Thread t = new Thread(){ + @Override + public void run(){ + Counter.increment(); + Counter.increment(); + Counter.increment(); + Counter.increment(); + } + }; + + Thread t2 = new Thread(){ + @Override + public void run(){ + + Counter.increment(); + Counter.increment(); + Counter.increment(); + Counter.increment(); + } + }; + + t.start(); + + try { + synchronized (t){ + t.setName("Waiting 1"); + t.wait();} + } catch (InterruptedException e) { + e.printStackTrace(); + } + + t2.start(); + + + System.out.println(t.getName()); + try { + synchronized (t2){ + t2.setName("Waiting 2"); + t2.wait();} + } catch (InterruptedException e) { + e.printStackTrace(); + } + + System.out.println(t2.getName()); + } + +} diff --git a/ exercises/teamnet/student.data b/ exercises/teamnet/student.data new file mode 100644 index 0000000000000000000000000000000000000000..7ed30d151e3568a5b99ec3dd93877b78a028835f GIT binary patch literal 137 zcmZ4UmVvdnh(WU`U#}!JF*h%@M6W8fD8D2>14!x>rxs-<=44hS7NzP1mz1WY=9P$S zT>ZuUUMmk11G6UsQ)Y?}17})hQE`c1Vs2^)gOE>FVp*boPGVlVesD=qW?s6r4+BR| jB1FEBp^kyEqJV*cfw6>vB`hZ~rG$aqsWc}uH!&FiKj$s` literal 0 HcmV?d00001 From d42b7428e2a0846b1bcd837558d7ddad95d24a17 Mon Sep 17 00:00:00 2001 From: Bulimac Vlad Date: Wed, 29 Oct 2014 18:50:22 +0200 Subject: [PATCH 03/12] Added exercises for workshop 9 - Maven --- exercises/HelloWorld-Extended/logs.log | 1 + exercises/HelloWorld-Extended/pom.xml | 20 ++++++++ .../ro/teamnet/hello2/HelloWorldExtended.java | 26 +++++++++++ exercises/HelloWorldMain/logs.log | 11 +++++ exercises/HelloWorldMain/pom.xml | 46 +++++++++++++++++++ .../java/ro/teamnet/hello/HelloWorld.java | 31 +++++++++++++ .../src/main/resources/log4j.properties | 17 +++++++ .../java/ro/teamnet/hello/HelloWorldTest.java | 25 ++++++++++ .../src/test/resources/log4j.properties | 17 +++++++ 9 files changed, 194 insertions(+) create mode 100644 exercises/HelloWorld-Extended/logs.log create mode 100644 exercises/HelloWorld-Extended/pom.xml create mode 100644 exercises/HelloWorld-Extended/src/main/java/ro/teamnet/hello2/HelloWorldExtended.java create mode 100644 exercises/HelloWorldMain/logs.log create mode 100644 exercises/HelloWorldMain/pom.xml create mode 100644 exercises/HelloWorldMain/src/main/java/ro/teamnet/hello/HelloWorld.java create mode 100644 exercises/HelloWorldMain/src/main/resources/log4j.properties create mode 100644 exercises/HelloWorldMain/src/test/java/ro/teamnet/hello/HelloWorldTest.java create mode 100644 exercises/HelloWorldMain/src/test/resources/log4j.properties diff --git a/ exercises/HelloWorld-Extended/logs.log b/ exercises/HelloWorld-Extended/logs.log new file mode 100644 index 0000000..4224871 --- /dev/null +++ b/ exercises/HelloWorld-Extended/logs.log @@ -0,0 +1 @@ +INFO main ro.teamnet.hello.HelloWorld - INFO->Enters in sayHello() method from HelloWorld diff --git a/ exercises/HelloWorld-Extended/pom.xml b/ exercises/HelloWorld-Extended/pom.xml new file mode 100644 index 0000000..c8298b9 --- /dev/null +++ b/ exercises/HelloWorld-Extended/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + ro.teamnet.zerotohero + helloworld-extended + 1.0 + + + + ro.teamnet.zerotohero + helloworld-core + 1.0 + + + + + \ No newline at end of file diff --git a/ exercises/HelloWorld-Extended/src/main/java/ro/teamnet/hello2/HelloWorldExtended.java b/ exercises/HelloWorld-Extended/src/main/java/ro/teamnet/hello2/HelloWorldExtended.java new file mode 100644 index 0000000..89eea8e --- /dev/null +++ b/ exercises/HelloWorld-Extended/src/main/java/ro/teamnet/hello2/HelloWorldExtended.java @@ -0,0 +1,26 @@ +package ro.teamnet.hello2; + +import ro.teamnet.hello.HelloWorld; + +/** + * Created by Buli on 29.10.2014. + */ +public class HelloWorldExtended { + + public HelloWorldExtended() { + } + + public void extendSayHello(){ + HelloWorld helloWorld = new HelloWorld(); + helloWorld.sayHello(); + System.out.println("The new Hello World"); + } + + public static void main(String[] Args){ + + HelloWorldExtended helloWorld = new HelloWorldExtended(); + helloWorld.extendSayHello(); + } + + +} diff --git a/ exercises/HelloWorldMain/logs.log b/ exercises/HelloWorldMain/logs.log new file mode 100644 index 0000000..4aaa8bc --- /dev/null +++ b/ exercises/HelloWorldMain/logs.log @@ -0,0 +1,11 @@ +DEBUG main ro.teamnet.hello.HelloWorld - DEBUG->Enters in sayHello() method from HelloWorld +INFO main ro.teamnet.hello.HelloWorld - INFO->Enters in sayHello() method from HelloWorld +INFO main ro.teamnet.hello.HelloWorld - INFO->Enters in sayHello() method from HelloWorld +INFO main ro.teamnet.hello.HelloWorld - INFO->Enters in sayHello() method from HelloWorld +DEBUG main ro.teamnet.hello.HelloWorld - DEBUG->Enters in sayHello() method from HelloWorld +INFO main ro.teamnet.hello.HelloWorld - INFO->Enters in sayHello() method from HelloWorld +INFO main ro.teamnet.hello.HelloWorld - INFO->Enters in sayHello() method from HelloWorld +INFO main ro.teamnet.hello.HelloWorld - INFO->Enters in sayHello() method from HelloWorld +INFO main ro.teamnet.hello.HelloWorld - INFO->Enters in sayHello() method from HelloWorld +INFO main ro.teamnet.hello.HelloWorld - INFO->Enters in sayHello() method from HelloWorld +INFO main ro.teamnet.hello.HelloWorld - INFO->Enters in sayHello() method from HelloWorld diff --git a/ exercises/HelloWorldMain/pom.xml b/ exercises/HelloWorldMain/pom.xml new file mode 100644 index 0000000..f483cd6 --- /dev/null +++ b/ exercises/HelloWorldMain/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + ro.teamnet.zerotohero + helloworld-core + 1.0 + + A Maven project for displaying a Hello World Application + Hello World Project + + + + log4j + log4j + 1.2.17 + + + + junit + junit + 4.11 + + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + + + + \ No newline at end of file diff --git a/ exercises/HelloWorldMain/src/main/java/ro/teamnet/hello/HelloWorld.java b/ exercises/HelloWorldMain/src/main/java/ro/teamnet/hello/HelloWorld.java new file mode 100644 index 0000000..f91c824 --- /dev/null +++ b/ exercises/HelloWorldMain/src/main/java/ro/teamnet/hello/HelloWorld.java @@ -0,0 +1,31 @@ +package ro.teamnet.hello; + +import org.apache.log4j.Logger; + +import java.io.IOException; + +/** + * Created by Buli on 29.10.2014. + */ +public class HelloWorld { + + static final Logger logger = Logger.getLogger(HelloWorld.class.getName()); + + public void sayHello(){ + int i=0; + System.out.println("Hello World!"); + logger.debug("DEBUG->Enters in sayHello() method from HelloWorld"); + logger.info("INFO->Enters in sayHello() method from HelloWorld"); + } + + public String returnHelloKey(){ + return "Hello Key"; + } + + public static void main(String[] args) { + HelloWorld helloWorld = new HelloWorld(); + + helloWorld.sayHello(); + } + +} diff --git a/ exercises/HelloWorldMain/src/main/resources/log4j.properties b/ exercises/HelloWorldMain/src/main/resources/log4j.properties new file mode 100644 index 0000000..7b64d41 --- /dev/null +++ b/ exercises/HelloWorldMain/src/main/resources/log4j.properties @@ -0,0 +1,17 @@ +log4j.rootLogger=info, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=logs.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n diff --git a/ exercises/HelloWorldMain/src/test/java/ro/teamnet/hello/HelloWorldTest.java b/ exercises/HelloWorldMain/src/test/java/ro/teamnet/hello/HelloWorldTest.java new file mode 100644 index 0000000..e0c7da1 --- /dev/null +++ b/ exercises/HelloWorldMain/src/test/java/ro/teamnet/hello/HelloWorldTest.java @@ -0,0 +1,25 @@ +package ro.teamnet.hello; + +import org.junit.Test; + +/** + * Created by Buli on 29.10.2014. + */ +public class HelloWorldTest { + + @Test + public void testSayHello(){ + HelloWorld helloWorld = new HelloWorld(); + helloWorld.sayHello(); + } + + @Test + public void testReturnHelloKey(){ + HelloWorld helloWorld = new HelloWorld(); + System.out.println("From Test: " + helloWorld.returnHelloKey()); + assert helloWorld.returnHelloKey().equals("Hello Key"); + } + + + +} diff --git a/ exercises/HelloWorldMain/src/test/resources/log4j.properties b/ exercises/HelloWorldMain/src/test/resources/log4j.properties new file mode 100644 index 0000000..7b64d41 --- /dev/null +++ b/ exercises/HelloWorldMain/src/test/resources/log4j.properties @@ -0,0 +1,17 @@ +log4j.rootLogger=info, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=logs.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n From 61ff840a5ba79fd29ca2a205d8b5d6a4f4a196fa Mon Sep 17 00:00:00 2001 From: Bulimac Vlad Date: Thu, 30 Oct 2014 17:34:31 +0200 Subject: [PATCH 04/12] Workshop warm-up added --- .../oop/graphicshape/MyException.java | 7 + exercises/warm-up/pom.xml | 19 +++ .../java/exercise/exercise0/Exercise0.java | 79 +++++++++ .../java/exercise/exercise1/Exercise1.java | 101 +++++++++++ .../main/java/exercise/exercise2/MyList.java | 139 ++++++++++++++++ .../java/exercise/exercise3/Exercise3.java | 59 +++++++ .../warm-up/src/test/java/Exercise1Test.java | 53 ++++++ .../warm-up/src/test/java/Exercise2Test.java | 157 ++++++++++++++++++ .../warm-up/src/test/java/Exercise3Test.java | 25 +++ .gitignore | 5 + workshops/Thumbs.db | Bin 0 -> 7680 bytes 11 files changed, 644 insertions(+) create mode 100644 exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/MyException.java create mode 100644 exercises/warm-up/pom.xml create mode 100644 exercises/warm-up/src/main/java/exercise/exercise0/Exercise0.java create mode 100644 exercises/warm-up/src/main/java/exercise/exercise1/Exercise1.java create mode 100644 exercises/warm-up/src/main/java/exercise/exercise2/MyList.java create mode 100644 exercises/warm-up/src/main/java/exercise/exercise3/Exercise3.java create mode 100644 exercises/warm-up/src/test/java/Exercise1Test.java create mode 100644 exercises/warm-up/src/test/java/Exercise2Test.java create mode 100644 exercises/warm-up/src/test/java/Exercise3Test.java create mode 100644 .gitignore create mode 100644 workshops/Thumbs.db diff --git a/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/MyException.java b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/MyException.java new file mode 100644 index 0000000..af6c7cf --- /dev/null +++ b/ exercises/teamnet/src/main/java/ro/teamnet/zerotohero/oop/graphicshape/MyException.java @@ -0,0 +1,7 @@ +package ro.teamnet.zerotohero.oop.graphicshape; + +/** + * Created by Buli on 28.10.2014. + */ +public class MyException { +} diff --git a/ exercises/warm-up/pom.xml b/ exercises/warm-up/pom.xml new file mode 100644 index 0000000..2ccc729 --- /dev/null +++ b/ exercises/warm-up/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + groupId + warm-up + 1.0-SNAPSHOT + + + + junit + junit + 4.11 + + + + \ No newline at end of file diff --git a/ exercises/warm-up/src/main/java/exercise/exercise0/Exercise0.java b/ exercises/warm-up/src/main/java/exercise/exercise0/Exercise0.java new file mode 100644 index 0000000..9a38bc0 --- /dev/null +++ b/ exercises/warm-up/src/main/java/exercise/exercise0/Exercise0.java @@ -0,0 +1,79 @@ +package exercise.exercise0; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.ListIterator; + +/** + * Created by Radu.Hoaghe on 10/29/2014. + * + * Exercise 0: Create a List (ArrayList or LinkedList), add elements to it and print all of them using ListIterator + * for loop and foreach loop + * + */ +public class Exercise0 { + + public Exercise0(){ + + } + + public void iterateThroughList(){ + + // TODO Exercise #0 a) Create a list (ArrayList or LinkedList) and add elements to it + + ArrayList myList = new ArrayList(5); + myList.add(1); + myList.add(2); + myList.add(3); + myList.add(4); + myList.add(5); + + // TODO Exercise #0 a) Don't forget to specify the type of the list (Integer, String etc.) + + // TODO Exercise #0 b) Iterate through the list using ListIterator and print all its elements + + ListIterator it = myList.listIterator(); + System.out.print("List elements: "); + while(it.hasNext()){ + int element = it.next(); + + System.out.print(element + ", "); + } + + // TODO Exercise #0 c) Iterate through the list using for loop and print all its elements + System.out.println(); + System.out.print("For loop ->"); + System.out.print("List elements: "); + for(int counter=0; counter"); + System.out.print("List elements: "); + it = myList.listIterator(); + for(Integer element : myList){ + + System.out.print(element + ", "); + } + + //backward iterator + System.out.println(); + System.out.println("Iterator backward"); + System.out.print("List elements: "); + it = myList.listIterator(); + while(it.hasPrevious()){ + int element = it.previous(); + + System.out.print(element + ", "); + } + } + + public static void main(String[] args) { + // TODO Exercise #0 e) Create a new instance of Exercise0 class and call the iterateThroughList() method + Exercise0 newEx = new Exercise0(); + newEx.iterateThroughList(); + } +} diff --git a/ exercises/warm-up/src/main/java/exercise/exercise1/Exercise1.java b/ exercises/warm-up/src/main/java/exercise/exercise1/Exercise1.java new file mode 100644 index 0000000..9cbe65b --- /dev/null +++ b/ exercises/warm-up/src/main/java/exercise/exercise1/Exercise1.java @@ -0,0 +1,101 @@ +package exercise.exercise1; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; + +/** + * Created by Radu.Hoaghe on 10/28/2014. + * + * Exercise 1: Compute the sum, the minimum and the maximum element from a given list (givenList) using three + * different ways to iterate over a List: + * a) ListIterator (implement it in the iterateUsingListIterator() method) + * b) for loop (implement it in the iterateUsingForLoop() method) + * c) foreach loop (implement it in the iterateUsingForEachLoop() method) + * + * In order to test your implementations you need to run the Exercise1Test from the test/java package + * (right-click on Exercise1Test class then click Run 'Exercise1Test' ) + */ +public class Exercise1{ + private List givenList; + + public Exercise1(List l) { + this.givenList = l; + } + + // TODO Exercise #1 a) Compute sum and get the min and the max from above 'givenList' iterating through it using ListIterator + public List iterateUsingListIterator(){ + // This List is used only for testing so you don't need to modify it + List testValues = new ArrayList(); + + + // TODO Exercise #1 a1) In order to pass the tests you need to name your variables sum, min and max or if + // TODO Exercise #1 a1) you want to name them differently you need to modify when you add them to testValues below + int sum=0, max=givenList.get(0), min=givenList.get(0); + ListIterator it = givenList.listIterator(); + while(it.hasNext()){ + int element = it.next(); + sum += element; + if(element > max) + max = element; + if(element < min) + min = element; + } + + // Adding the results to the List in order to be tested + // TODO Exercise #1 a2) Uncomment the following three lines in order to test your implementation + testValues.add(sum); + testValues.add(min); + testValues.add(max); + + return testValues; + } + + // TODO Exercise #0 b) Compute sum and get the min and the max from list iterating through it using foreach loop + public List iterateUsingForEachLoop(){ + + // This List is used only for testing so you don't need to modify it + List testValues = new ArrayList(); + + int sum=0, max=givenList.get(0), min=givenList.get(0); + for(Integer element : givenList){ + sum += element; + if(element > max) + max = element; + if(element < min) + min = element; + } + + // Adding the results to the List in order to be tested + // TODO Exercise #1 b1) Uncomment the following three lines in order to test your implementation + testValues.add(sum); + testValues.add(min); + testValues.add(max); + + return testValues; + } + + public List iterateUsingForLoop(){ + + // This List is used only for testing so you don't need to modify it + List testValues = new ArrayList(); + + int sum=0, max=givenList.get(0), min=givenList.get(0); + for(int i=0; i max) + max = element; + if(element < min) + min = element; + } + + // Adding the results to the List in order to be tested + // TODO Exercise #1 b1) Uncomment the following three lines in order to test your implementation + testValues.add(sum); + testValues.add(min); + testValues.add(max); + + return testValues; + } +} diff --git a/ exercises/warm-up/src/main/java/exercise/exercise2/MyList.java b/ exercises/warm-up/src/main/java/exercise/exercise2/MyList.java new file mode 100644 index 0000000..c91757a --- /dev/null +++ b/ exercises/warm-up/src/main/java/exercise/exercise2/MyList.java @@ -0,0 +1,139 @@ +package exercise.exercise2; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.ListIterator; + +/** + * Created by Radu.Hoaghe on 28.10.2014. + * + * Exercise 2: Create a class that inherits ArrayList (class MyList). + * + * This list (MyList) should have the following functionality, besides the functionality + * that ArrayList already offers: it should retain in every moment how many different + * elements exist in the list. + * + * Examples: 1. If you have a List that contains: 7 5 3 2 4 1, there are 6 different elements. + * 2. If you have a List that contains: 5 6 1 2 5 6, there are 4 different elements. + * + * A variable that retains the number of different elements that exist in the list in + * every moment was already defined (differentElements). + * + * First of all, you will need to override the add methods so that every time a different + * element is added the counter will be updated. + * Hint : check out the List documentation to see the methods signatures. + * + * Secondly, you will also need to override the remove methods (Hint: Of course the List + * documentation) because the number of different elements in the list could change if + * the last element of its kind in the list is removed and by not overrriding it the + * counter will remain unchanged. + * + * Finally, you will need to override the clear method and create a getter method for the + * counter (in order to access it outside the class). + * + * In order to add/remove/clear the elements into/from the list you will need to use the + * add/remove/clear methods inherited from ArrayList. + * + * To test your implementation run the Exercise2Test class. + * + */ +public class MyList extends ArrayList { + + // A counter to hold the number of adds that were made on the list + private int differentElements; + + public MyList(){ + super(); + differentElements = 0; + } + + // TODO Exercise #2 a) Override add() and addAll() methods so that the list should retain the number of + // TODO Exercise #2 a) different elements + + private ArrayList myList = this; + + @Override + public boolean add(Integer integer) { + + if (!myList.contains(integer)) + differentElements ++; + return super.add(integer); + } + + @Override + public boolean addAll(Collection c) { + for(Object el : c) { + if (!myList.contains(el)) + differentElements++; + } + return super.addAll(c); + } + + @Override + public void add(int index, Integer element) { + if (!myList.contains(element)) + differentElements ++; + super.add(index, element); + } + + @Override + public boolean addAll(int index, Collection c) { + for(Object el : c) { + if (!myList.contains(el)) + differentElements++; + } + return super.addAll(index, c); + } + + public int getDifferentElements() { + return differentElements; + } + // TODO Exercise #2 b) Override the remove methods so that the number of different elements is updated when + // TODO Exercise #2 b) an element is removed + // TODO Exercise #2 b) hint: you need to update the number of different elements only when + // TODO Exercise #2 b) the element that needs to be removed is the last element of its kind in the list + + @Override + public Integer remove(int index) { + Integer el = this.get(index); + super.remove(index); + + if(!myList.contains(el)) + differentElements --; + return el; + } + + @Override + public boolean remove(Object o) { + boolean r = super.remove(o); + if(!myList.contains(o)) + differentElements --; + return r; + } + + /* + @Override + public boolean removeAll(Collection c) { + boolean ok = false; + super.removeAll(c); + for(Object el : c) { + if (!myList.contains(el)) + ok = true; + } + return ok; + } +*/ + // TODO Exercise #2 c) Override the clear method (hint: don't forget to reset the number of different elements) + + @Override + public void clear() { + differentElements = 0; + super.clear(); + } + + + // TODO Exercise #2 d) Generate a getter method in order to get the counter value + + // TODO Exercise #2 e) Uncomment all the lines from Exercise2Test.java in order to test your implementation +} diff --git a/ exercises/warm-up/src/main/java/exercise/exercise3/Exercise3.java b/ exercises/warm-up/src/main/java/exercise/exercise3/Exercise3.java new file mode 100644 index 0000000..a64b52a --- /dev/null +++ b/ exercises/warm-up/src/main/java/exercise/exercise3/Exercise3.java @@ -0,0 +1,59 @@ +package exercise.exercise3; + +import java.util.*; + +/** + * Created by Radu.Hoaghe on 10/28/2014. + * + * Exercise 3: Fill three Set implementations that you know (Hint: they were described during + * the earlier presentation) with the List that is given to this class by + * its constructor. + * + * Check out the elements that the list mentioned above contains and then, add them + * to your three Sets. After this check out the elements of your Sets. What do you + * remark? What could be the reason? + * + * Finally, add to the one of the three Sets some elements + * that already exist in the Set (e.g add("that") and add("collection")) + * + * To run your implementation, run the Exercise3Test class. + */ +public class Exercise3 { + + // List containing some elements that need to be added into the Set + private List listToAdd; + + public Exercise3(List l) { + listToAdd = l; + } + + public void addElementsToSets(){ + // hint: you should create an instance for every type of discussed Set implementation + + HashSet hashSet = new HashSet(); + LinkedHashSet linkedHashSet = new LinkedHashSet(); + TreeSet treeSet = new TreeSet(); + + System.out.println("The elements that will be added to the Sets: "); + // TODO Exercise #3 a) Print the content of the elements you will add into the Set + ListIterator it = listToAdd.listIterator(); + while (it.hasNext()){ + System.out.println(it.next()); + } + // TODO Exercise #3 b) add the elements from listToAdd to the Sets + hashSet.addAll(listToAdd); + linkedHashSet.addAll(listToAdd); + treeSet.addAll(listToAdd); + + // TODO Exercise #3 c) Print the content of the Sets + System.out.println("HashSet: " + hashSet.toString()); + System.out.println("LinkedHashSet" + linkedHashSet.toString()); + System.out.println("TreeHashSet" + treeSet.toString()); + + // TODO Exercise #3 d) Add to the TreeSet two elements that already exist in the Set + treeSet.add("no"); + treeSet.add("that"); + // TODO Exercise #3 d) and print again the TreeSet. What do you see? + System.out.println("TreeHashSet" + treeSet.toString()); + } +} diff --git a/ exercises/warm-up/src/test/java/Exercise1Test.java b/ exercises/warm-up/src/test/java/Exercise1Test.java new file mode 100644 index 0000000..3f7cf75 --- /dev/null +++ b/ exercises/warm-up/src/test/java/Exercise1Test.java @@ -0,0 +1,53 @@ +import exercise.exercise1.Exercise1; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Created by Radu.Hoaghe on 10/29/2014. + */ +public class Exercise1Test { + private Integer[] v = {15, 5, 34, 23, 7, 19, 20, 22, 78, 39, 8, 30, 27, 62, 28, 7}; + private List listToTest; + private List expected; + + private Exercise1 ex1; + + @Before + public void setUp() throws Exception { + listToTest = Arrays.asList(v); + ex1 = new Exercise1(listToTest); + expected = new ArrayList(); + expected.add(424); // sum + expected.add(5); // min + expected.add(78); // max + } + + @Test + public void testIterator() throws Exception { + List testResults = ex1.iterateUsingListIterator(); + Assert.assertEquals("Test sum with iterator", expected.get(0), testResults.get(0)); + Assert.assertEquals("Test min with iterator", expected.get(1), testResults.get(1)); + Assert.assertEquals("Test max with iterator", expected.get(2), testResults.get(2)); + } + + @Test + public void testFor() throws Exception { + List testResults = ex1.iterateUsingForLoop(); + Assert.assertEquals("Test sum with for", expected.get(0), testResults.get(0)); + Assert.assertEquals("Test min with for", expected.get(1), testResults.get(1)); + Assert.assertEquals("Test max with for", expected.get(2), testResults.get(2)); + } + + @Test + public void testForEach() throws Exception { + List testResults = ex1.iterateUsingForEachLoop(); + Assert.assertEquals("Test sum with foreach", expected.get(0), testResults.get(0)); + Assert.assertEquals("Test min with foreach", expected.get(1), testResults.get(1)); + Assert.assertEquals("Test max with foreach", expected.get(2), testResults.get(2)); + } +} diff --git a/ exercises/warm-up/src/test/java/Exercise2Test.java b/ exercises/warm-up/src/test/java/Exercise2Test.java new file mode 100644 index 0000000..0af58e3 --- /dev/null +++ b/ exercises/warm-up/src/test/java/Exercise2Test.java @@ -0,0 +1,157 @@ +import exercise.exercise2.MyList; +import junit.framework.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; + +/** +* Created by Radu.Hoaghe on 10/29/2014. +*/ +public class Exercise2Test { + private MyList listToTest; + private int addExpectedTest1, addExpectedTest2; + private int insertExpectedTest1; + private int removeExpectedTest1, removeExpectedTest2; + private int addAllExpectedTest1, addAllExpectedTest2; + private Integer[] v = new Integer[5]; + + @Before + public void setUp() throws Exception { + listToTest = new MyList(); + addExpectedTest1 = 10; + addExpectedTest2 = 11; + insertExpectedTest1 = 13; + addAllExpectedTest1 = 10; + addAllExpectedTest2 = 13; + removeExpectedTest1 = 8; + removeExpectedTest2 = 8; + } + + @Test + public void testAdd() throws Exception { + listToTest.clear(); + Assert.assertEquals("Test clear method", 0, listToTest.getDifferentElements()); + + for(int i = 0; i < 10; i++) + listToTest.add(i); + + Assert.assertEquals("Test add method with all different elements", addExpectedTest1, listToTest.getDifferentElements()); + + listToTest.add(5); + listToTest.add(3); + listToTest.add(11); + listToTest.add(8); + + Assert.assertEquals("Test add method with some equal elements", addExpectedTest2, listToTest.getDifferentElements()); + } + + @Test + public void testAddAtIndex() throws Exception { + listToTest.clear(); + Assert.assertEquals("Test clear method", 0, listToTest.getDifferentElements()); + + + for(int i = 0; i < 10; i++) + listToTest.add(i); + + listToTest.add(8, 11); + listToTest.add(5, 12); + listToTest.add(3, 13); + + Assert.assertEquals("Test insert different elements", insertExpectedTest1, listToTest.getDifferentElements()); + + listToTest.add(7, 8); + listToTest.add(4, 4); + listToTest.add(5, 12); + + Assert.assertEquals("Test insert equal elements", insertExpectedTest1, listToTest.getDifferentElements()); + + } + + @Test + public void testAddAll() throws Exception { + listToTest.clear(); + Assert.assertEquals("Test clear method", 0, listToTest.getDifferentElements()); + + for(int i = 0; i < 10; i++) + listToTest.add(i); + + for(int i = 0; i < 5; i++) + v[i] = i; + + listToTest.addAll(Arrays.asList(v)); + Assert.assertEquals("Test addAll with all equal elements", addAllExpectedTest1, listToTest.getDifferentElements()); + + for(int i = 0; i < 5; i++) + v[i] = 5 * i; + + listToTest.addAll(Arrays.asList(v)); + Assert.assertEquals("Test addAll with all some different elements", addAllExpectedTest2, listToTest.getDifferentElements()); + + } + + @Test + public void testAddAllAtIndex() throws Exception { + listToTest.clear(); + Assert.assertEquals("Test clear method", 0, listToTest.getDifferentElements()); + + for(int i = 0; i < 10; i++) + listToTest.add(i); + + for(int i = 0; i < 5; i++) + v[i] = i; + + listToTest.addAll(5, Arrays.asList(v)); + Assert.assertEquals("Test addAll with all equal elements", addAllExpectedTest1, listToTest.getDifferentElements()); + + for(int i = 0; i < 5; i++) + v[i] = 5 * i; + + listToTest.addAll(10, Arrays.asList(v)); + Assert.assertEquals("Test addAll with some different elements", addAllExpectedTest2, listToTest.getDifferentElements()); + + } + + @Test + public void testRemove() throws Exception { + listToTest.clear(); + Assert.assertEquals("Test clear method", 0, listToTest.getDifferentElements()); + + for(int i = 0; i < 10; i++) + listToTest.add(i); + + listToTest.remove(5); + listToTest.remove(3); + + Assert.assertEquals("Test remove elements with 1 occurence", removeExpectedTest1, listToTest.getDifferentElements()); + + listToTest.add(7); + listToTest.add(7); + listToTest.remove(5); + + Assert.assertEquals("Test remove element with 3 occurences", removeExpectedTest2, listToTest.getDifferentElements()); + + } + + @Test + public void testRemoveObject() throws Exception { + listToTest.clear(); + Assert.assertEquals("Test clear method", 0, listToTest.getDifferentElements()); + + for(int i = 0; i < 10; i++) + listToTest.add(i); + + listToTest.remove((Integer) 5); + listToTest.remove((Integer) 3); + + Assert.assertEquals("Test remove elements with 1 occurence", removeExpectedTest1, listToTest.getDifferentElements()); + + listToTest.add(7); + listToTest.add(7); + listToTest.remove((Integer) 7); + + Assert.assertEquals("Test remove element with 3 occurences", removeExpectedTest2, listToTest.getDifferentElements()); + + } +} diff --git a/ exercises/warm-up/src/test/java/Exercise3Test.java b/ exercises/warm-up/src/test/java/Exercise3Test.java new file mode 100644 index 0000000..5fd7b7e --- /dev/null +++ b/ exercises/warm-up/src/test/java/Exercise3Test.java @@ -0,0 +1,25 @@ +import exercise.exercise3.Exercise3; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by Radu.Hoaghe on 10/29/2014. + */ +public class Exercise3Test { + private Exercise3 exercise3; + private String[] stringsToAddToSet = {"A", "collection", "that", "contains", "no", "duplicate", "elements", "."}; + + @Before + public void setUp() throws Exception { + exercise3 = new Exercise3(Arrays.asList(stringsToAddToSet)); + + } + + @Test + public void testExercise3() throws Exception { + exercise3.addElementsToSets(); + + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d6340a --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea +.iml +*.iml + +*.class \ No newline at end of file diff --git a/workshops/Thumbs.db b/workshops/Thumbs.db new file mode 100644 index 0000000000000000000000000000000000000000..fb60476b35f2fe19e5f1cbd4477430860f773868 GIT binary patch literal 7680 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 etG19+6`WJ Date: Fri, 31 Oct 2014 16:08:47 +0200 Subject: [PATCH 05/12] warm-up 2 added --- exercises/warm-up2/pom.xml | 19 +++ .../src/main/java/exercise0/Exercise0.java | 50 ++++++ .../src/main/java/exercise1/Exercise1.java | 82 +++++++++ .../src/main/java/exercise2/Exercise2.java | 46 +++++ .../src/main/java/exercise2/Student.java | 58 +++++++ .../warm-up2/src/test/java/Exercise1Test.java | 159 ++++++++++++++++++ .../warm-up2/src/test/java/Exercise2Test.java | 73 ++++++++ 7 files changed, 487 insertions(+) create mode 100644 exercises/warm-up2/pom.xml create mode 100644 exercises/warm-up2/src/main/java/exercise0/Exercise0.java create mode 100644 exercises/warm-up2/src/main/java/exercise1/Exercise1.java create mode 100644 exercises/warm-up2/src/main/java/exercise2/Exercise2.java create mode 100644 exercises/warm-up2/src/main/java/exercise2/Student.java create mode 100644 exercises/warm-up2/src/test/java/Exercise1Test.java create mode 100644 exercises/warm-up2/src/test/java/Exercise2Test.java diff --git a/ exercises/warm-up2/pom.xml b/ exercises/warm-up2/pom.xml new file mode 100644 index 0000000..9913300 --- /dev/null +++ b/ exercises/warm-up2/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + warm-up2 + warm-up2 + 1.0-SNAPSHOT + + + + junit + junit + 4.11 + + + + \ No newline at end of file diff --git a/ exercises/warm-up2/src/main/java/exercise0/Exercise0.java b/ exercises/warm-up2/src/main/java/exercise0/Exercise0.java new file mode 100644 index 0000000..8b42247 --- /dev/null +++ b/ exercises/warm-up2/src/main/java/exercise0/Exercise0.java @@ -0,0 +1,50 @@ +package exercise0; + +import java.util.*; + +/** + * Created by Radu.Hoaghe on 10/29/2014. + * + * Exercise 0: Iterate over the keys of a Map using keySet method (this method returns a Set of all the map keys) + */ +public class Exercise0 { + + public Exercise0(){ + + } + + // TODO Exercise #0 a) iterate over a Map's keys using keySet method + public void iterateThroughMap(){ + + Map myMap = new HashMap(); + myMap.put("a1",1); + myMap.put("a2",2); + myMap.put("a3",3); + myMap.put("a4",4); + myMap.put("b1",1); + myMap.put("b2",2); + myMap.put("b3",3); + myMap.put("b4",4); + Set mySet = myMap.keySet(); + Iterator it = mySet.iterator(); + while(it.hasNext()){ + System.out.println(it.next()); + } + + // TODO Exercise #0 b) Create a Map (HashMap) and add elements to it (using put() method) + // TODO Exercise #0 b) Don't forget to specify the types of the key and value when creating the Map + + // TODO Exercise #0 c) Iterate over the Map using keySet() method and print all its elements + // TODO Exercise #0 c) The elements are printed like this: [key1=value1, key2=value2, ...] + + for(String s : mySet){ + System.out.println("[" + s + " = " +myMap.get(s) + "]"); + } + + } + + public static void main(String[] args) { + Exercise0 exercise0 = new Exercise0(); + exercise0.iterateThroughMap(); + } +} diff --git a/ exercises/warm-up2/src/main/java/exercise1/Exercise1.java b/ exercises/warm-up2/src/main/java/exercise1/Exercise1.java new file mode 100644 index 0000000..13cf5cb --- /dev/null +++ b/ exercises/warm-up2/src/main/java/exercise1/Exercise1.java @@ -0,0 +1,82 @@ +package exercise1; + +import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry; + +import java.util.*; + +/** + * Created by Radu.Hoaghe on 10/29/2014. + * + * Exercise 1: You have a Map that holds in each element a country with its capital (countries Map) + * a) Find all the countries that start with 'R' character, iterating through the keys of the Map using + * keySet() method + * b) Find all the countries that start with 'R' character, iterating through the keys of the Map using + * Map.Entry, and convert all the characters of the countries found to lowercase + * c) Find the capital city with the longest name, iterating through the values of the Map (values() method) + * + */ +public class Exercise1 { + + // A map that holds some key-value pairs, the key represents the country and its value represents + // the capital city of the country + private Map countries; + + public Exercise1(Map countries){ + this.countries = countries; + } + + // TODO Exercise #1 a) You need to iterate over the map keys using a foreach loop (see Map.keySet()) + // TODO Exercise #1 a) and add the countries that start with 'R' character into the seekingCountries list + // TODO Exercise #1 a) hint: see String documentation + public List iteratingOverKeys(){ + + // The list of countries that start with the 'R' character + List seekingCountries = new ArrayList(); + Set mySet = countries.keySet(); + for(String country : mySet){ + if(country.startsWith("R") || country.startsWith("r")) + seekingCountries.add(country); + } + + return seekingCountries; + } + + // TODO Exercise #1 b) You need to iterate over the map entries using a foreach loop (see Map.Entry) + // TODO Exercise #1 b) and convert to lowercase (hint: String documentation) all the countries that start with 'R' + // TODO Exercise #1 b) character into the seekingCountries list + public List iteratingOverEntries(){ + + // The list of countries that start with the 'R' character and will be converted to lowercase + List seekingCountries = new ArrayList(); + + Set> mySet2 = countries.entrySet(); + + for(Map.Entry country : mySet2){ + if(country.getKey().startsWith("R")) + seekingCountries.add(country.getKey().toLowerCase()); + } + + return seekingCountries; + } + + // TODO Exercise #1 c) You need to iterate over the map values using a foreach loop (see Map.values()) + // TODO Exercise #1 c) and find the capital city with the longest name + public String iteratingOverValues(){ + + // The country that has the capital city with the longest name + String seekingCapital = ""; + + int max = seekingCapital.length(); + + Collection myColl = countries.values(); + + for(String value : myColl){ + if(value.length() > max){ + max = value.length(); + seekingCapital = value; + } + } + + return seekingCapital; + } +} diff --git a/ exercises/warm-up2/src/main/java/exercise2/Exercise2.java b/ exercises/warm-up2/src/main/java/exercise2/Exercise2.java new file mode 100644 index 0000000..b64e5d9 --- /dev/null +++ b/ exercises/warm-up2/src/main/java/exercise2/Exercise2.java @@ -0,0 +1,46 @@ +package exercise2; + +import java.util.*; + +/** + * Created by Radu.Hoaghe on 10/30/2014. + * + * Exercise 2: Overriding equals() and hashCode() methods. + * Create a Set and a Map and add some elements to them before and after overriding equals() and hashCode() + * For this exercise you need to follow in order all the TODO steps. + */ +public class Exercise2 { + private List studentList; + private List cnps; + + public Exercise2(List studentList, List cnps){ + this.studentList = studentList; + this.cnps = cnps; + } + + public void addStudents(){ + + System.out.println("The list of students is: " + studentList); + + // TODO Exercise 2 a) Make a new Set, add the elements from the studentList into it + // TODO and print them (hint: notice the duplicate elements) + // TODO (hint: in order to print the elements of Student class in a human readable way you should override + // TODO the toString() method from Student class + + // TODO Exercise 2 b) Remove all elements from the Set using clear() method and go to TODO Exercise 2 c) from Student class + + // TODO Exercise 2 e) Add the elements from studentList into the Set after you finished the TODO Exercise 2 c) + // TODO from Student class. What do you notice? + + // TODO Exercise 2 f) Remove all elements from the Set using clear() method and go to TODO Exercise 2 g) from Student class + + // TODO Exercise 2 i) Add the elements from studentList into the Set after you finished the TODO Exercise 2 g) + // TODO from Student class. What do you notice this time? + + // TODO Exercise 2 j) Create a new Map so that it holds in the key all the Students from the + // TODO (Important !) Set you have just already created, and in the keys' value, the CNP of the Student found in cnps List + // TODO (suggestion: after you implement this, you could comment, firstly, the equals() method from Student class + // TODO and then the hashCode() method in order to see some differences). + + } +} diff --git a/ exercises/warm-up2/src/main/java/exercise2/Student.java b/ exercises/warm-up2/src/main/java/exercise2/Student.java new file mode 100644 index 0000000..087ea84 --- /dev/null +++ b/ exercises/warm-up2/src/main/java/exercise2/Student.java @@ -0,0 +1,58 @@ +package exercise2; + +/** + * Created by Radu.Hoaghe on 31.10.2014. + */ +public class Student { + private final String firstName; + private final String lastName; + private final Double averageGrade; + + public Student(String firstName, String lastName, Double averageGrade) { + this.firstName = firstName; + this.lastName = lastName; + this.averageGrade = averageGrade; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public Double getAverageGrade() { + return averageGrade; + } + + // TODO Exercise 2 c) Override the equals() method + @Override + public boolean equals(Object o) { + // TODO Exercise 2 c1) Check if the current instance is the same instance as the one from Object o + + // TODO Exercise 2 c2) Check if Object o is null + + // TODO Exercise 2 c3) Cast the object into a Student variable + // TODO Exercise 2 c3) Check if all the fields from Student class are equal to the ones from + // TODO Exercise 2 c3) the variable that you casted earlier (lastName, firstName, averageGrade) + + return true; + // TODO Exercise 2 d) After you finished implementing equals method go to TODO Exercise 2 e) from Exercise2 class + } + + // TODO Exercise 2 g) Override the hashCode() method + // TODO Exercise 2 g) Hint: Don't forget to include in the hashCode result all the fields from + // TODO Exercise 2 g) the Student class + @Override + public int hashCode() { + return 0; + // TODO Exercise 2 h) After you finished implementing hashCode go to TODO Exercise 2 i) from Exercise2 class + } + + // TODO You should override the toString() method in order to print the Student class' elements + @Override + public String toString() { + return ""; + } +} diff --git a/ exercises/warm-up2/src/test/java/Exercise1Test.java b/ exercises/warm-up2/src/test/java/Exercise1Test.java new file mode 100644 index 0000000..e53f644 --- /dev/null +++ b/ exercises/warm-up2/src/test/java/Exercise1Test.java @@ -0,0 +1,159 @@ +import exercise1.Exercise1; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by Radu.Hoaghe on 10/29/2014. + */ +public class Exercise1Test { + public static final String[][] data = { + // Africa + {"ALGERIA","Algiers"}, {"ANGOLA","Luanda"}, + {"BENIN","Porto-Novo"}, {"BOTSWANA","Gaberone"}, + {"BURKINA FASO","Ouagadougou"}, {"BURUNDI","Bujumbura"}, + {"CAMEROON","Yaounde"}, {"CAPE VERDE","Praia"}, + {"CENTRAL AFRICAN REPUBLIC","Bangui"}, + {"CHAD","N’djamena"}, {"COMOROS","Moroni"}, + {"CONGO","Brazzaville"}, {"DJIBOUTI","Dijibouti"}, + {"EGYPT","Cairo"}, {"EQUATORIAL GUINEA","Malabo"}, + {"ERITREA","Asmara"}, {"ETHIOPIA","Addis Ababa"}, + {"GABON","Libreville"}, {"THE GAMBIA","Banjul"}, + {"GHANA","Accra"}, {"GUINEA","Conakry"}, + {"BISSAU","Bissau"}, {"COTE D’IVOIRE (IVORY COAST)","Yamoussoukro"}, + {"KENYA","Nairobi"}, {"LESOTHO","Maseru"}, + {"LIBERIA","Monrovia"}, {"LIBYA","Tripoli"}, + {"MADAGASCAR","Antananarivo"}, {"MALAWI","Lilongwe"}, + {"MALI","Bamako"}, {"MAURITANIA","Nouakchott"}, + {"MAURITIUS","Port Louis"}, {"MOROCCO","Rabat"}, + {"MOZAMBIQUE","Maputo"}, {"NAMIBIA","Windhoek"}, + {"NIGER","Niamey"}, {"NIGERIA","Abuja"}, + {"RWANDA","Kigali"}, {"SAO TOME E PRINCIPE","Sao Tome"}, + {"SENEGAL","Dakar"}, {"SEYCHELLES","Victoria"}, + {"SIERRA LEONE","Freetown"}, {"SOMALIA","Mogadishu"}, + {"SOUTH AFRICA","Pretoria/Cape Town"}, + {"SUDAN","Khartoum"}, {"SWAZILAND","Mbabane"}, {"TANZANIA","Dodoma"}, + {"TOGO","Lome"}, {"TUNISIA","Tunis"}, + {"UGANDA","Kampala"},{"DEMOCRATIC REPUBLIC OF THE CONGO (ZAIRE)", "Kinshasa"}, + {"ZAMBIA","Lusaka"}, {"ZIMBABWE","Harare"}, + // Asia + {"AFGHANISTAN","Kabul"}, {"BAHRAIN","Manama"}, + {"BANGLADESH","Dhaka"}, {"BHUTAN","Thimphu"}, + {"BRUNEI","Bandar Seri Begawan"}, + {"CAMBODIA","Phnom Penh"}, + {"CHINA","Beijing"}, {"CYPRUS","Nicosia"}, + {"INDIA","New Delhi"}, {"INDONESIA","Jakarta"}, + {"IRAN","Tehran"}, {"IRAQ","Baghdad"}, + {"ISRAEL","Jerusalem"}, {"JAPAN","Tokyo"}, + {"JORDAN","Amman"}, {"KUWAIT","Kuwait City"}, + {"LAOS","Vientiane"}, {"LEBANON","Beirut"}, + {"MALAYSIA","Kuala Lumpur"}, {"THE MALDIVES","Male"}, + {"MONGOLIA","Ulan Bator"}, {"MYANMAR (BURMA)","Rangoon"}, + {"NEPAL","Katmandu"}, {"NORTH KOREA","P’yongyang"}, + {"OMAN","Muscat"}, {"PAKISTAN","Islamabad"}, + {"PHILIPPINES","Manila"}, {"QATAR","Doha"}, + {"SAUDI ARABIA","Riyadh"}, {"SINGAPORE","Singapore"}, + {"SOUTH KOREA","Seoul"}, {"SRI LANKA","Colombo"}, + {"SYRIA","Damascus"}, {"TAIWAN (REPUBLIC OF CHINA)","Taipei"}, + {"THAILAND","Bangkok"}, {"TURKEY","Ankara"}, + {"UNITED ARAB EMIRATES","Abu Dhabi"}, + {"VIETNAM","Hanoi"}, {"YEMEN","Sana’a"}, + // Australia and Oceania + {"AUSTRALIA","Canberra"}, {"FIJI","Suva"}, + {"KIRIBATI","Bairiki"},{"MARSHALL ISLANDS","Dalap-Uliga-Darrit"}, + {"MICRONESIA","Palikir"}, {"NAURU","Yaren"}, + {"NEW ZEALAND","Wellington"}, {"PALAU","Koror"}, + {"PAPUA NEW GUINEA","Port Moresby"}, + {"SOLOMON ISLANDS","Honaira"}, {"TONGA","Nuku’alofa"}, + {"TUVALU","Fongafale"}, {"VANUATU","Port-Vila"}, + {"WESTERN SAMOA","Apia"}, + // Eastern Europe and former USSR + {"ARMENIA","Yerevan"}, {"AZERBAIJAN","Baku"}, + {"BELARUS (BYELORUSSIA)","Minsk"}, + {"BULGARIA","Sofia"}, {"GEORGIA","Tbilisi"}, + {"KAZAKSTAN","Almaty"}, {"KYRGYZSTAN","Alma-Ata"}, + {"MOLDOVA","Chisinau"}, {"RUSSIA","Moscow"}, + {"TAJIKISTAN","Dushanbe"}, {"TURKMENISTAN","Ashkabad"}, + {"UKRAINE","Kyiv"}, {"UZBEKISTAN","Tashkent"}, + // Europe + {"ALBANIA","Tirana"}, {"ANDORRA","Andorra la Vella"}, + {"AUSTRIA","Vienna"}, {"BELGIUM","Brussels"}, + {"BOSNIA-HERZEGOVINA","Sarajevo"}, + {"CROATIA","Zagreb"}, {"CZECH REPUBLIC","Prague"}, + {"DENMARK","Copenhagen"}, {"ESTONIA","Tallinn"}, + {"FINLAND","Helsinki"}, {"FRANCE","Paris"}, + {"GERMANY","Berlin"}, {"GREECE","Athens"}, + {"HUNGARY","Budapest"}, {"ICELAND","Reykjavik"}, + {"IRELAND","Dublin"}, {"ITALY","Rome"}, + {"LATVIA","Riga"}, {"LIECHTENSTEIN","Vaduz"}, + {"LITHUANIA","Vilnius"}, {"LUXEMBOURG","Luxembourg"}, + {"MACEDONIA","Skopje"}, {"MALTA","Valletta"}, + {"MONACO","Monaco"}, {"MONTENEGRO","Podgorica"}, + {"THE NETHERLANDS","Amsterdam"}, {"NORWAY","Oslo"}, + {"POLAND","Warsaw"}, {"PORTUGAL","Lisbon"}, + {"ROMANIA","Bucharest"}, {"SAN MARINO","San Marino"}, + {"SERBIA","Belgrade"}, {"SLOVAKIA","Bratislava"}, + {"SLOVENIA","Ljuijana"}, {"SPAIN","Madrid"}, + {"SWEDEN","Stockholm"}, {"SWITZERLAND","Berne"}, + {"UNITED KINGDOM","London"}, {"VATICAN CITY","Vatican"}, + // North and Central America + {"ANTIGUA AND BARBUDA","Saint John’s"}, {"BAHAMAS","Nassau"}, + {"BARBADOS","Bridgetown"}, {"BELIZE","Belmopan"}, + {"CANADA","Ottawa"}, {"COSTA RICA","San Jose"}, + {"CUBA","Havana"}, {"DOMINICA","Roseau"}, + {"DOMINICAN REPUBLIC","Santo Domingo"}, + {"EL SALVADOR","San Salvador"}, {"GRENADA","Saint George’s"}, + {"GUATEMALA","Guatemala City"}, {"HAITI","Port-au-Prince"}, + {"HONDURAS","Tegucigalpa"}, {"JAMAICA","Kingston"}, + {"MEXICO","Mexico City"}, {"NICARAGUA","Managua"}, + {"PANAMA","Panama City"}, {"ST. KITTS-NEVIS","Basseterre"}, {"ST. LUCIA","Castries"}, + {"ST. VINCENT AND THE GRENADINES","Kingstown"}, + {"UNITED STATES OF AMERICA","Washington, D.C."}, + // South America + {"ARGENTINA","Buenos Aires"}, {"BOLIVIA","La Paz"}, + {"BRAZIL","Brasilia"}, {"CHILE","Santiago"}, + {"COLOMBIA","Bogota"}, {"ECUADOR","Quito"}, + {"GUYANA","Georgetown"}, {"PARAGUAY","Asuncion"}, + {"PERU","Lima"}, {"SURINAME","Paramaribo"}, + {"TRINIDAD AND TOBAGO","Port of Spain"}, + {"URUGUAY","Montevideo"}, {"VENEZUELA","Caracas"}, + }; + private Exercise1 exercise1; + private Map countries; + private String[] expected = {"romania", "rwanda", "russia"}; + private String[] expected2 = {"ROMANIA", "RWANDA", "RUSSIA"}; + private String expectedCapital = "Bandar Seri Begawan"; + + @Before + public void setUp() throws Exception { + countries = new HashMap(); + for(String[] countryAndCapital : data){ + countries.put(countryAndCapital[0], countryAndCapital[1]); + } + exercise1 = new Exercise1(countries); + + } + + @Test + public void testIteratingOverKeys() throws Exception { + List testResults = exercise1.iteratingOverKeys(); + Assert.assertEquals("Test Iterating Over Keys", Arrays.asList(expected2), testResults); + } + + @Test + public void testIteratingOverEntries() throws Exception { + List testResults = exercise1.iteratingOverEntries(); + Assert.assertEquals("Test Iterating Over Entries", Arrays.asList(expected), testResults); + } + + @Test + public void testIteratingOverValues() throws Exception { + String capital = exercise1.iteratingOverValues(); + Assert.assertEquals("Test Iterating Over Values", expectedCapital, capital); + } +} diff --git a/ exercises/warm-up2/src/test/java/Exercise2Test.java b/ exercises/warm-up2/src/test/java/Exercise2Test.java new file mode 100644 index 0000000..a1b00d7 --- /dev/null +++ b/ exercises/warm-up2/src/test/java/Exercise2Test.java @@ -0,0 +1,73 @@ +import exercise2.Exercise2; +import exercise2.Student; +import junit.framework.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Created by radu992 on 31.10.2014. + */ +public class Exercise2Test { + private Student[] students = {new Student("Popescu", "Mihai", 8.66), + new Student("Ionescu", "Ion", 7.92), + new Student("Popa", "Cristina", 9.34), + new Student("Barbu", "Mihai", 5.01), + new Student("Popescu", "Mihai", 8.66), + new Student("Serban", "Alin", 9.66), + new Student("Georgescu", "Andreea", 5.01), + new Student("Popa", "Cristina", 9.34), + new Student("Popescu", "Mihai", 8.66),}; + + private Long[] cnps = {1851021345131L, + 1920617149053L, + 1870505168646L, + 1870619152998L, + 1921204325416L, + 1931011351347L}; + + private List studentList; + private List cnpsList; + @Before + public void setUp() throws Exception { + studentList = new ArrayList(Arrays.asList(students)); + cnpsList = new ArrayList(Arrays.asList(cnps)); + + } + + @Test + public void testEqualsMethod() throws Exception { + new Exercise2(studentList, cnpsList).addStudents(); + Student student1 = studentList.get(0); // Mihai Popescu + Student student2 = studentList.get(4); // Mihai Popescu + Student student3 = studentList.get(8); // Mihai Popescu + Assert.assertEquals("Test equals method from student", true, student1.equals(student2)); + + Assert.assertEquals("Test reflexitivity on equals method", true, student1.equals(student1)); + + Assert.assertEquals("Test symmetry on equals method", student2.equals(student1), student1.equals(student2)); + + Assert.assertEquals("Test transitivity on equals method", student1.equals(student3), student1.equals(student2) + && student2.equals(student3)); + + Assert.assertEquals("Test null on equals method", false, student1.equals(null)); + } + + @Test + public void testHashCodeMethod() throws Exception { + Student student1 = studentList.get(0); // Mihai Popescu + Student student2 = studentList.get(4); // Mihai Popescu + Student student3 = studentList.get(1); + Student student4 = new Student("Mihai", "Popescu", 8.98); // Mihai Popescu with other averageGrade + + Assert.assertEquals("Test equal elements to have the same hashCode", student1.hashCode(), student2.hashCode()); + + Assert.assertNotSame("Test different elements to have different hashCode", student1.hashCode(), student3.hashCode()); + + Assert.assertNotSame("Test different elements that differ by one field to have different hashCode", student1.hashCode(), + student4.hashCode()); + } +} From 4bc84f267588961785a07b4dd9e68d5c8136e30f Mon Sep 17 00:00:00 2001 From: Bulimac Vlad Date: Fri, 31 Oct 2014 18:05:53 +0200 Subject: [PATCH 06/12] warm-up2 workshop ex2 added --- .../src/main/java/exercise2/Exercise2.java | 26 ++++++++++++++++++- .../src/main/java/exercise2/Student.java | 17 +++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/ exercises/warm-up2/src/main/java/exercise2/Exercise2.java b/ exercises/warm-up2/src/main/java/exercise2/Exercise2.java index b64e5d9..601eacb 100644 --- a/ exercises/warm-up2/src/main/java/exercise2/Exercise2.java +++ b/ exercises/warm-up2/src/main/java/exercise2/Exercise2.java @@ -20,15 +20,39 @@ public Exercise2(List studentList, List cnps){ public void addStudents(){ - System.out.println("The list of students is: " + studentList); + //System.out.println("The list of students is: " + studentList); // TODO Exercise 2 a) Make a new Set, add the elements from the studentList into it + Set mySet = new HashSet(); + mySet.addAll(studentList); +// System.out.println(mySet.toString()); +// +// mySet.clear(); +// +// mySet.addAll(studentList); +// System.out.println(mySet.toString()); +// +// mySet.clear(); +// +// mySet.addAll(studentList); +// System.out.println(mySet.toString()); + + Map myMap = new HashMap(); + List list = new ArrayList(mySet); + + int counter = 0; + for(int i=0;i + 4.0.0 + ro.teamnet.zth + zth-app + jar + 1.0-SNAPSHOT + zth-app + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + + com.oracle + ojdbc6 + 11.2.0.3 + + + diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java new file mode 100644 index 0000000..da2b833 --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java @@ -0,0 +1,37 @@ +package ro.teamnet.zth; + +import java.sql.Connection; +import java.util.HashMap; + +import ro.teamnet.zth.utils.DatabaseManager; + +/** + * Hello world! + * + */ +public class App +{ + + private static final String USERNAME = "ZTH_01"; + private static final String PASSWORD = "passw0rd"; + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + + Connection con = null; + + HashMap hashMap = new HashMap(); + hashMap.put("id", "number primary key"); + hashMap.put("first_name", "varchar2(40) not null"); + hashMap.put("last_name", "varchar2(40) not null"); + hashMap.put("phone_number", "varchar2(35)"); + + con = DatabaseManager.getConnection(USERNAME,PASSWORD); + DatabaseManager.checkConnection(con); + DatabaseManager.getFirstRow(con); +// DatabaseManager.create(con,"test_jdbc",hashMap); +// DatabaseManager.drop(con,"test_jdbc"); + DatabaseManager.closeConnecction(con); + + } +} diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java new file mode 100644 index 0000000..31411ea --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java @@ -0,0 +1,7 @@ +package ro.teamnet.zth.dao; + +/** + * Created by Buli on 04.11.2014. + */ +public class DepartmentDao { +} diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java new file mode 100644 index 0000000..be5bc8a --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java @@ -0,0 +1,7 @@ +package ro.teamnet.zth.dao; + +/** + * Created by Buli on 04.11.2014. + */ +public class EmployeeDao { +} diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeViewDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeViewDao.java new file mode 100644 index 0000000..0cc0444 --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeViewDao.java @@ -0,0 +1,7 @@ +package ro.teamnet.zth.dao; + +/** + * Created by Buli on 04.11.2014. + */ +public class EmployeeViewDao { +} diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java new file mode 100644 index 0000000..2167590 --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java @@ -0,0 +1,7 @@ +package ro.teamnet.zth.dao; + +/** + * Created by Buli on 04.11.2014. + */ +public class JobDao { +} diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java new file mode 100644 index 0000000..2baae30 --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java @@ -0,0 +1,26 @@ +package ro.teamnet.zth.domain; + +/** + * Created by Buli on 04.11.2014. + */ +public class Department { + + private Long departmentId; + private String departmentName; + + public Long getDepartmentId() { + return departmentId; + } + + public void setDepartmentId(Long departmentId) { + this.departmentId = departmentId; + } + + public String getDepartmentName() { + return departmentName; + } + + public void setDepartmentName(String departmentName) { + this.departmentName = departmentName; + } +} diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Employee.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Employee.java new file mode 100644 index 0000000..c4e25ba --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Employee.java @@ -0,0 +1,109 @@ +package ro.teamnet.zth.domain; + +import java.util.Date; + +/** + * Created by Buli on 04.11.2014. + */ +public class Employee { + + private Long employeeId; + private String firstName; + private String lastName; + private Employee manager; + private String email; + private Date hireDate; + private Double salary; + private Double commisionPoints; + private String phoneNmber; + private Job job; + private Department department; + + public Long getEmployeeId() { + return employeeId; + } + + public void setEmployeeId(Long employeeId) { + this.employeeId = employeeId; + } + + 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 Employee getManager() { + return manager; + } + + public void setManager(Employee manager) { + this.manager = manager; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Date getHireDate() { + return hireDate; + } + + public void setHireDate(Date hireDate) { + this.hireDate = hireDate; + } + + public Double getSalary() { + return salary; + } + + public void setSalary(Double salary) { + this.salary = salary; + } + + public Double getCommisionPoints() { + return commisionPoints; + } + + public void setCommisionPoints(Double commisionPoints) { + this.commisionPoints = commisionPoints; + } + + public String getPhoneNmber() { + return phoneNmber; + } + + public void setPhoneNmber(String phoneNmber) { + this.phoneNmber = phoneNmber; + } + + public Job getJob() { + return job; + } + + public void setJob(Job job) { + this.job = job; + } + + public Department getDepartment() { + return department; + } + + public void setDepartment(Department department) { + this.department = department; + } +} diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Job.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Job.java new file mode 100644 index 0000000..2b6bb56 --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Job.java @@ -0,0 +1,44 @@ +package ro.teamnet.zth.domain; + +/** + * Created by Buli on 04.11.2014. + */ +public class Job { + + private String jobId; + private String jobTitle; + private Double minSalary; + private Double maxSalary; + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public String getJobTitle() { + return jobTitle; + } + + public void setJobTitle(String jobTitle) { + this.jobTitle = jobTitle; + } + + public Double getMinSalary() { + return minSalary; + } + + public void setMinSalary(Double minSalary) { + this.minSalary = minSalary; + } + + public Double getMaxSalary() { + return maxSalary; + } + + public void setMaxSalary(Double maxSalary) { + this.maxSalary = maxSalary; + } +} diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java new file mode 100644 index 0000000..4fe6ed9 --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java @@ -0,0 +1,139 @@ +package ro.teamnet.zth.utils; + +import javax.swing.plaf.nimbus.State; +import java.sql.*; +import java.util.HashMap; + +/** + * Created by Buli on 04.11.2014. + */ +public class DatabaseManager { + + public static Connection getConnection(String username, String password) { + + Connection con = null; + try { + con = DriverManager.getConnection( + "jdbc:oracle:thin:@10.6.33.102:1521:orcl", + username, + password); + } catch (SQLException e) { + e.printStackTrace(); + } + return con; + } + + public static void checkConnection(Connection con) { + + Statement statement = null; + try { + statement = con.createStatement(); + ResultSet rs = null; + rs = statement.executeQuery("SELECT SYSDATE from DUAL"); + + if (rs.next()) { + Date currentDate = rs.getDate(1); + System.out.println("Current date from oracle is : " + currentDate); + } + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + public static void getFirstRow(Connection con) { + + Statement statement = null; + try { + statement = con.createStatement(); + ResultSet rs = null; + rs = statement.executeQuery("SELECT * from EMPLOYEES WHERE employee_id = 1"); + + if (rs.next()) { + + System.out.println("Current date from oracle is : " + rs.getString(1) + ""); + } + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + statement.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + public static void create(Connection con, String tableName, HashMap columnData) { + + Statement stat = null; + + try { + stat = con.createStatement(); + String createTableString = "CREATE TABLE " + tableName + " ( "; + StringBuilder sqlStatement = new StringBuilder(); + sqlStatement.append(createTableString); + Integer columnsCount = columnData.keySet().size(); + + for(String columnName : columnData.keySet()){ + columnsCount --; + String columnString = columnName + " " + columnData.get(columnName) + (columnsCount != 0 ? " , " : ")"); + sqlStatement.append(columnString); + } + + stat.executeUpdate(sqlStatement.toString()); + + System.out.println("Created table " + tableName + " in database..."); + + } catch (SQLException e) { + e.printStackTrace(); + } + finally { + try { + stat.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + + } + + public static void drop(Connection con, String tableName) { + + Statement stmt = null; + + ResultSet rs = null; + try { + stmt = con.createStatement(); + String sqlStatement = "DROP TABLE " + tableName; + stmt.executeUpdate(sqlStatement); + System.out.println("Droped table " + tableName + "from database..."); + } catch (SQLException e) { + e.printStackTrace(); + } + finally { + try { + stmt.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + public static void closeConnecction(Connection con) { + try { + con.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} diff --git a/ exercises/zth-app/src/test/java/ro/teamnet/zth/AppTest.java b/ exercises/zth-app/src/test/java/ro/teamnet/zth/AppTest.java new file mode 100644 index 0000000..3f5a4ca --- /dev/null +++ b/ exercises/zth-app/src/test/java/ro/teamnet/zth/AppTest.java @@ -0,0 +1,38 @@ +package ro.teamnet.zth; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} From 3856971efb35d9148e2c6b300a4a80a8cd1c4672 Mon Sep 17 00:00:00 2001 From: Bulimac Vlad Date: Wed, 5 Nov 2014 00:41:09 +0200 Subject: [PATCH 08/12] PreparedStatement added OracleDataSource added --- .../src/main/java/ro/teamnet/zth/App.java | 4 +- .../ro/teamnet/zth/utils/DatabaseManager.java | 68 +++++++++++++++---- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java index da2b833..7df137b 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java @@ -14,6 +14,7 @@ public class App private static final String USERNAME = "ZTH_01"; private static final String PASSWORD = "passw0rd"; + private static final String URL = "jdbc:oracle:thin:@10.6.33.102:1521:orcl"; public static void main( String[] args ) { System.out.println( "Hello World!" ); @@ -26,7 +27,8 @@ public static void main( String[] args ) hashMap.put("last_name", "varchar2(40) not null"); hashMap.put("phone_number", "varchar2(35)"); - con = DatabaseManager.getConnection(USERNAME,PASSWORD); +// con = DatabaseManager.getConnection(USERNAME,PASSWORD); + con = DatabaseManager.getConnection(USERNAME,PASSWORD,URL); DatabaseManager.checkConnection(con); DatabaseManager.getFirstRow(con); // DatabaseManager.create(con,"test_jdbc",hashMap); diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java index 4fe6ed9..3fa575f 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java @@ -1,8 +1,17 @@ package ro.teamnet.zth.utils; +import oracle.jdbc.pool.OracleDataSource; + +import javax.sql.DataSource; import javax.swing.plaf.nimbus.State; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; import java.sql.*; import java.util.HashMap; +import java.util.Properties; +import java.util.logging.Logger; /** * Created by Buli on 04.11.2014. @@ -11,15 +20,45 @@ public class DatabaseManager { public static Connection getConnection(String username, String password) { + Properties info = new Properties(); + info.put("ORACLE_DB_USERNAME", username); + info.put("ORACLE_DB_PASSWORD", password); + info.put("ORACLE_DB_URL","jdbc:oracle:thin:@10.6.33.102:1521:orcl"); + Connection con = null; + try { - con = DriverManager.getConnection( - "jdbc:oracle:thin:@10.6.33.102:1521:orcl", - username, - password); + OracleDataSource ds = new OracleDataSource(); + ds.setURL(info.getProperty("ORACLE_DB_URL")); + ds.setUser(info.getProperty("ORACLE_DB_USERNAME")); + ds.setPassword(info.getProperty("ORACLE_DB_PASSWORD")); + con = ds.getConnection(); } catch (SQLException e) { e.printStackTrace(); } + + return con; + } + + public static Connection getConnection(String username, String password, String URL) { + + Properties info = new Properties(); + info.put("ORACLE_DB_USERNAME", username); + info.put("ORACLE_DB_PASSWORD", password); + info.put("ORACLE_DB_URL",URL); + + Connection con = null; + + try { + OracleDataSource ds = new OracleDataSource(); + ds.setURL(info.getProperty("ORACLE_DB_URL")); + ds.setUser(info.getProperty("ORACLE_DB_USERNAME")); + ds.setPassword(info.getProperty("ORACLE_DB_PASSWORD")); + con = ds.getConnection(); + } catch (SQLException e) { + e.printStackTrace(); + } + return con; } @@ -49,14 +88,15 @@ public static void checkConnection(Connection con) { public static void getFirstRow(Connection con) { - Statement statement = null; + PreparedStatement statement = null; try { - statement = con.createStatement(); + String sqlStatement = ""; ResultSet rs = null; - rs = statement.executeQuery("SELECT * from EMPLOYEES WHERE employee_id = 1"); + statement = con.prepareStatement("SELECT * from EMPLOYEES where employee_id = ?"); + statement.setInt(1,100); + rs = statement.executeQuery(); if (rs.next()) { - System.out.println("Current date from oracle is : " + rs.getString(1) + ""); } rs.close(); @@ -73,10 +113,9 @@ public static void getFirstRow(Connection con) { public static void create(Connection con, String tableName, HashMap columnData) { - Statement stat = null; + PreparedStatement stat = null; try { - stat = con.createStatement(); String createTableString = "CREATE TABLE " + tableName + " ( "; StringBuilder sqlStatement = new StringBuilder(); sqlStatement.append(createTableString); @@ -88,7 +127,8 @@ public static void create(Connection con, String tableName, HashMap Date: Fri, 7 Nov 2014 16:57:09 +0200 Subject: [PATCH 09/12] Dao implemented --- .../src/main/java/ro/teamnet/zth/App.java | 29 +++++- .../ro/teamnet/zth/dao/DepartmentDao.java | 54 +++++++++++ .../java/ro/teamnet/zth/dao/EmployeeDao.java | 85 ++++++++++++++++++ .../main/java/ro/teamnet/zth/dao/JobDao.java | 55 ++++++++++++ .../ro/teamnet/zth/domain/Department.java | 8 ++ .../java/ro/teamnet/zth/domain/Employee.java | 17 ++++ .../main/java/ro/teamnet/zth/domain/Job.java | 10 +++ .../ro/teamnet/zth/utils/DatabaseManager.java | 6 +- .../zth/utils/ResultSetToPojoConvert.java | 68 ++++++++++++++ workshops/Thumbs.db | Bin 7680 -> 12800 bytes 10 files changed, 327 insertions(+), 5 deletions(-) create mode 100644 exercises/zth-app/src/main/java/ro/teamnet/zth/utils/ResultSetToPojoConvert.java diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java index 7df137b..cdf8d6a 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java @@ -1,8 +1,15 @@ package ro.teamnet.zth; import java.sql.Connection; +import java.util.ArrayList; import java.util.HashMap; +import ro.teamnet.zth.dao.DepartmentDao; +import ro.teamnet.zth.dao.EmployeeDao; +import ro.teamnet.zth.dao.JobDao; +import ro.teamnet.zth.domain.Department; +import ro.teamnet.zth.domain.Employee; +import ro.teamnet.zth.domain.Job; import ro.teamnet.zth.utils.DatabaseManager; /** @@ -29,10 +36,28 @@ public static void main( String[] args ) // con = DatabaseManager.getConnection(USERNAME,PASSWORD); con = DatabaseManager.getConnection(USERNAME,PASSWORD,URL); - DatabaseManager.checkConnection(con); - DatabaseManager.getFirstRow(con); +// DatabaseManager.checkConnection(con); +// DatabaseManager.getFirstRow(con); // DatabaseManager.create(con,"test_jdbc",hashMap); // DatabaseManager.drop(con,"test_jdbc"); + +// JobDao job = new JobDao(); +// ArrayList arrayList = job.getAllJobs(con); +// System.out.println(arrayList.toString()); + +// DepartmentDao depDao = new DepartmentDao(); +// ArrayList arrayList = depDao.getAllDepartments(con); +// Department dep = depDao.getDepartmentById(con,50); +// System.out.println(dep.toString()); +// System.out.println(arrayList.toString()); + +// EmployeeDao employeeDao = new EmployeeDao(); +// ArrayList arrayList = employeeDao.getAllEmployees(con); +// Employee employee = employeeDao.getEmployeeById(con,203); +// System.out.println(employee.toString()); +// System.out.println(arrayList.toString()); + + DatabaseManager.closeConnecction(con); } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java index 31411ea..36535f7 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java @@ -1,7 +1,61 @@ package ro.teamnet.zth.dao; +import ro.teamnet.zth.domain.Department; +import ro.teamnet.zth.utils.ResultSetToPojoConvert; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + /** * Created by Buli on 04.11.2014. */ public class DepartmentDao { + + public ArrayList getAllDepartments(Connection con) { + PreparedStatement stmt = null; + ResultSet rs = null; + String selectAllFromTableString = "Select * from Departments"; + try { + stmt = con.prepareStatement(selectAllFromTableString); + rs = stmt.executeQuery(); + return ResultSetToPojoConvert.convertToDepartment(rs, con); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + stmt.close(); + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return new ArrayList(); + } + + public Department getDepartmentById(Connection con, int id) { + String selectAllFromTableString = "Select * from Departments where department_id = ?"; + PreparedStatement stmt = null; + ResultSet rs = null; + ArrayList departments = null; + try { + stmt = con.prepareStatement(selectAllFromTableString); + stmt.setInt(1, id); + rs = stmt.executeQuery(); + departments = ResultSetToPojoConvert.convertToDepartment(rs, con); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + stmt.close(); + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return departments.size() > 0 ? departments.get(0) : null; + } + } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java index be5bc8a..737a852 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java @@ -1,7 +1,92 @@ package ro.teamnet.zth.dao; +import ro.teamnet.zth.domain.Employee; +import ro.teamnet.zth.utils.ResultSetToPojoConvert; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; + /** * Created by Buli on 04.11.2014. */ public class EmployeeDao { + + public ArrayList getAllEmployees(Connection con) { + PreparedStatement stmt = null; + ResultSet rs = null; + String selectAllFromTableString = "Select * from employees"; + try { + stmt = con.prepareStatement(selectAllFromTableString); + stmt.setMaxRows(5); + rs = stmt.executeQuery(); + return ResultSetToPojoConvert.convertToEmployee(rs, con); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + stmt.close(); + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return new ArrayList(); + } + + public Employee getEmployeeById(Connection con, int id) { + String selectAllFromTableString = "Select * from employees where employee_id = ?"; + PreparedStatement stmt = null; + ResultSet rs = null; + ArrayList employees = null; + try { + stmt = con.prepareStatement(selectAllFromTableString); + stmt.setInt(1, id); + rs = stmt.executeQuery(); + employees = ResultSetToPojoConvert.convertToEmployee(rs, con); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + stmt.close(); + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return employees.size() > 0 ? employees.get(0) : null; + } +/* insert delete update*/ + + public void saveEmployee(Employee employee, Connection con){ + HashMap insertIntoTableEmployees = new HashMap(); + String tableName = "employees"; + + insertIntoTableEmployees.put("employee_id", employee.getEmployeeId().toString()); + insertIntoTableEmployees.put("first_name", employee.getFirstName()); + insertIntoTableEmployees.put("last_name", employee.getLastName()); + insertIntoTableEmployees.put("email", employee.getEmail()); + insertIntoTableEmployees.put("phone_number", employee.getPhoneNmber()); + insertIntoTableEmployees.put("hire_date", "TO_DATE('" + employee.getHireDate() + "','yyyy-mm-dd"); + insertIntoTableEmployees.put("job_id",employee.getJob().getJobId().toString()); + insertIntoTableEmployees.put("salary", employee.getSalary().toString()); + insertIntoTableEmployees.put("commision_pct", employee.getCommisionPoints().toString()); + insertIntoTableEmployees.put("manager_id", employee.getManager().getEmployeeId().toString()); + insertIntoTableEmployees.put("department_id", employee.getDepartment().getDepartmentId().toString()); + + PreparedStatement stmt; + try { + stmt = con.prepareStatement(""); + String createTableString = "INSERT INTO " + tableName + " ( "; + StringBuilder sqlStatement = new StringBuilder(); + sqlStatement.append(createTableString); + Integer valuesCount = insertIntoTableEmployees.keySet().size(); + + } catch (SQLException e) { + e.printStackTrace(); + } + } } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java index 2167590..6829dde 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java @@ -1,7 +1,62 @@ package ro.teamnet.zth.dao; +import ro.teamnet.zth.domain.Job; +import ro.teamnet.zth.utils.ResultSetToPojoConvert; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + /** * Created by Buli on 04.11.2014. */ public class JobDao { + + public ArrayList getAllJobs(Connection con) { + PreparedStatement stmt = null; + ResultSet rs = null; + String selectAllFromTableString = "Select job_id, job_title, min_salary, max_salary from Jobs"; + try { + stmt = con.prepareStatement(selectAllFromTableString); + stmt.setMaxRows(5); + rs = stmt.executeQuery(); + return ResultSetToPojoConvert.convertToJob(rs, con); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + stmt.close(); + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return new ArrayList(); + } + + public Job getJobById(Connection con, String id) { + String selectAllFromTableString = "Select * from Jobs where job_id = ?"; + PreparedStatement stmt = null; + ResultSet rs = null; + ArrayList jobs = null; + try { + stmt = con.prepareStatement(selectAllFromTableString); + stmt.setString(1, id); + rs = stmt.executeQuery(); + jobs = ResultSetToPojoConvert.convertToJob(rs, con); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + stmt.close(); + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return jobs.size() > 0 ? jobs.get(0) : null; + } + } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java index 2baae30..0a0cb12 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java @@ -23,4 +23,12 @@ public String getDepartmentName() { public void setDepartmentName(String departmentName) { this.departmentName = departmentName; } + + @Override + public String toString() { + return "Department{" + + "departmentId=" + departmentId + + ", departmentName='" + departmentName + '\'' + + '}' + "\n"; + } } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Employee.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Employee.java index c4e25ba..af0b1df 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Employee.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Employee.java @@ -106,4 +106,21 @@ public Department getDepartment() { public void setDepartment(Department department) { this.department = department; } + + @Override + public String toString() { + return "Employee{" + + "employeeId=" + employeeId + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", manager=" + manager + + ", email='" + email + '\'' + + ", hireDate=" + hireDate + + ", salary=" + salary + + ", commisionPoints=" + commisionPoints + + ", phoneNmber='" + phoneNmber + '\'' + + ", job=" + job + + ", department=" + department + + '}'; + } } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Job.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Job.java index 2b6bb56..dac80f6 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Job.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Job.java @@ -41,4 +41,14 @@ public Double getMaxSalary() { public void setMaxSalary(Double maxSalary) { this.maxSalary = maxSalary; } + + @Override + public String toString() { + return "Job{" + + "jobId='" + jobId + '\'' + + ", jobTitle='" + jobTitle + '\'' + + ", minSalary=" + minSalary + + ", maxSalary=" + maxSalary + + "} \n"; + } } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java index 3fa575f..11de3a3 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/DatabaseManager.java @@ -64,11 +64,11 @@ public static Connection getConnection(String username, String password, String public static void checkConnection(Connection con) { - Statement statement = null; + PreparedStatement statement = null; try { - statement = con.createStatement(); + statement = con.prepareStatement("SELECT SYSDATE from DUAL"); ResultSet rs = null; - rs = statement.executeQuery("SELECT SYSDATE from DUAL"); + rs = statement.executeQuery(); if (rs.next()) { Date currentDate = rs.getDate(1); diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/ResultSetToPojoConvert.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/ResultSetToPojoConvert.java new file mode 100644 index 0000000..d474006 --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/ResultSetToPojoConvert.java @@ -0,0 +1,68 @@ +package ro.teamnet.zth.utils; + +import ro.teamnet.zth.dao.DepartmentDao; +import ro.teamnet.zth.dao.EmployeeDao; +import ro.teamnet.zth.dao.JobDao; +import ro.teamnet.zth.domain.Department; +import ro.teamnet.zth.domain.Employee; +import ro.teamnet.zth.domain.Job; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Objects; + +/** + * Created by Buli on 11/5/2014. + */ +public class ResultSetToPojoConvert { + + + + public static ArrayList convertToEmployee(ResultSet rs, Connection con) throws SQLException{ + ArrayList arrayListFromResultSet = new ArrayList(); + JobDao jobDao = new JobDao(); + EmployeeDao employeeDao = new EmployeeDao(); + while(rs.next()){ + Employee newEmployee = new Employee(); + newEmployee.setEmployeeId(rs.getLong("employee_id")); + newEmployee.setFirstName(rs.getString("first_name")); + newEmployee.setLastName(rs.getString("last_name")); + newEmployee.setEmail(rs.getString("email")); + newEmployee.setHireDate(rs.getDate("hire_date")); + newEmployee.setJob(jobDao.getJobById(con,rs.getString("job_id"))); + newEmployee.setSalary(rs.getDouble("salary")); + newEmployee.setCommisionPoints(rs.getDouble("commission_pct")); + newEmployee.setManager(employeeDao.getEmployeeById(con,rs.getInt("manager_id"))); + newEmployee.setDepartment((new DepartmentDao().getDepartmentById(con,rs.getInt("department_id")))); + arrayListFromResultSet.add(newEmployee); + } + return arrayListFromResultSet; + } + + public static ArrayList convertToJob(ResultSet rs, Connection con) throws SQLException{ + ArrayList arrayListFromResultSet = new ArrayList(); + while(rs.next()){ + Job newJob = new Job(); + newJob.setJobId(rs.getString("job_id")); + newJob.setJobTitle(rs.getString("job_title")); + newJob.setMinSalary(rs.getDouble("min_salary")); + newJob.setMaxSalary(rs.getDouble("max_salary")); + arrayListFromResultSet.add(newJob); + } + return arrayListFromResultSet; + } + + public static ArrayList convertToDepartment(ResultSet rs, Connection con) throws SQLException{ + ArrayList arrayListFromResultSet = new ArrayList(); + while (rs.next()){ + Department department = new Department(); + department.setDepartmentId(rs.getLong("department_id")); + department.setDepartmentName(rs.getString("department_name")); + arrayListFromResultSet.add(department); + } + return arrayListFromResultSet; + } + +} diff --git a/workshops/Thumbs.db b/workshops/Thumbs.db index fb60476b35f2fe19e5f1cbd4477430860f773868..52bf308d48de360b944c159e81e4dcc9ddeb84b1 100644 GIT binary patch delta 4297 zcma)=c{G&$`^Rs)iY#T{vWJj;$(jsVvV|<6>@#*LgjvP49-K?);#$&$6Q zWM<0xV8%MOncq0)`98mMe&2t7*Ez4xxj&!l+}C|w@9UiFe9j%K73)!_PA$v=001im zHVW(%E>O5gfrA1k1+GQ~>I$lCT0i=$Ki@+h5s@LZ)=bnC2l*dEQqhSi(NYdvPhX{& zBA^1O01HHK$WU zzJ2ePAOm93f8UUQQh044`ZA4EH^`;iq-9jRvR}x79>1c}Bhp2R&}ScDRk-_Nz~&{r z`UnHJmTx#3D==Ju9U&TOsbTVK*;Wa9a&p-kQ;h4QCv(I42gys^JNtdQ$y$;%pFw=x zCm%8MGtbxmSg>I)PwO1VfffXbTXRye5=f@H$Zxpj6Y)47l_SPEN(-I3^xC#n2Q8lU_01*B0RtDC=k-}8R6OqO$| z$^jidWWaa}_bW4aYpEi#lh9rZFX|CwB2XlbZ||sYX-(ZWbLs>;9C88f%vxdNB}7-_ zu?EJK3;l#7)?Mw3@2y(f43=%PL=W_0egcxs;ft}#PT2JxSC-l~|1iwCkI{-3n^kMX z$KoD%y45^sk$zivM(FA?ohzD{A6!9ORfWyy|fQ>X3QOln+s{RoZpvQo~Z^w*;lx{ zyz6qCUr*d%Uinym4Wdp4c!Bm;QN}G3ZQ@vSN1RFah$a5-P?fzxZ~LRHTrR&@w?vw_ z3`VU;95EEfve#UXS@y;k>?Y>a-j^}I?v!w8q%qhWd@($GT-=~E&HW}y1(S=$xP~}QRmgiq>V1a zCIniUDzIBngJ4%oc-#}i^&Y>mF4yP7A#tIq3FQaB0atj=?#8Mv^OE-q@#Ntku87*V zMNp~@#4qMP3?%&squX|(YEb{e>DC#&K@YZXIz`6hV+FWyF-=tlrTKG0J*+>gpTjO& zG$<=HY_ZHU%uGbuki^3wxSk^RDCTI10*(!2dDEI}ik`Gu-xEa^*Idv9_#H)q8{A|G zKi5}y>BB^An{CPRVQPQ5^Q;E@tf=DK82l0#@>e&*+Kxa&l+lq|T$ns3tWW?whFa#) z>B?B${w1>@!5TevMepZL95N#a&D|!iT8T&A!EYvA5ph^Dj=u__mLHT>*yE?MId;Ui zlYx{D!JB0(A%^FRX}W{`7rg^>FVLS2UW3OdQ#o~!0oF}%xCN+M z(1GzbP0(-sbcy*LgZd|dh~1$noh!5Ya;;&dL>)3<|Lp|3CmoHv*3qx|HyQBck4KyPd5)z0TYeLcYntVL?D&!K&MpiTFFUVNcM z>}R@mRP1NI2p>!Ype9G9$l;qO+rE0N_3{1tBc2a!@ldve=1+d*$DYGn zTJphnp3QSkmFHu`yBu1c7tg4pe{H>J3`kaFiHhsBB6ec}FTe^l*_o-L48W41igS;B z%G$5?dIrB=^tL=tDy`RYf1<~ihwdHZ)8^~S%PCBXe#63UD5_6;MQdR0qQHwjmah+y zne=B?91L)fvMI-xzW5`nXjkJoi3+clWcQZ%%WkBAUoWzdD7hG$J0wp0qcqVZ4BY;M zMl3O8V?~}Z^Xk?NpO|33wl;{Sns5lWaWEZ84Q+p8J8k1tv>hrT`$L!NeJaq7ElO3* z(@DofTaVx9n7|Qu1DX;=XsgWbO`2?-xfZLn5E7c&4Z`=yfajzLqEi#O`qMxO%2@=n zkYl_a$j%e|m+{CK`f!y?_{6p=Iu|NYd?)>Fl=RgQ@L8LeXq>2x5r94ng$8w3&qZWb+Z;e`U&%Im^2}>De&WclJ-+w8 zenQK@{WVdM4A>&|b9!e}g6ezfMKE@Yr5 zIBD!}t0~p2sCr?!e&OqXwTh~b7~CR8;NBKpgnbxJ0WmY_oJYpSOoTzr&&W&nflE|y zxzJzQAMDRzEzYkwo=?J$J2fFq5zhGCS16dw+Us=5IYxV1P}`J=-+j$KhIW26ufGQr zf@v1l`<5Ls$@#fPon7HuQ~|Nls);%%s=pst83GsoA8>qiCenP`ce&&riPNilZski` zqty924Sw%K*h1)C?bFLk=Yo~tMc@>ze;%liSOoKOj6_4m$lY=OT1@(Jk3%VQQ#~BM zgDt~vB$N>!TX6EKB(&#rU}uEkm&Nw6s5eLilM#5ZIJj3b=7HpL;b==xn!5Hn6j5w- zycRIM_Y|-E@kU-u>lyV~Gqy}!DWyYu(@)c`9^0k)_r&)`U?puG-MEo%SOUGj3w9J& z)*NzS=Rm(EO+KyYd;l4kAeIk-YgKLFAu9(9i*58XfBqO=r`xU(vsTW>f~xqiZo0T$ zM^LOfk`|p@G@#<==;|;papd$y(wXMPZ>Fn}52|N9S|F>{;;5|qspf;LQlZv&M=A9( zT`oxl{-talJ?}c4=b0Rq#emauj^^Nb9~+jZKnAEUj)(c_{%HgEM=QK!N}$p-5il~K zjodCj`7lm;%rfxJi+`{c^h&J?J7;mQYH>_Ee(N>tWKkE-t8u3lH`{7xty$1=)7!VHe5>@hu^XsZzFfg3mkPuTb7JOxlo8ulhm)8b?a1QpaXq4G5%J~ zhv8(G3`~_~B~hGqsh>4b1;vy+!yFn(HM)*baF;2`rBvBlV49g>Cv=&mqv2pHofVi2Bu*X5z}9TZ4#! zsgt6NHt#dDTIN-)D@TJBfs3$b3DUn!t)!Lzv{^N2nTJOyff4gRqU;F24Sc53;7iQ3 zexPDglP3WI_7ZTzFjK@nwx1N2x^4WdrYk4y(#aw zWB^O(Ida44DXxP17?zMAJuBm2N~K>LzgF=QC$c&G z;5iv!(~*u&nX#B^6Ve{-e=abb^@v>%5;7R_I~Xj&Xc77yhYy?=sMBp&o9ORt2B zf`k42n?FTKDgL!2#y~PaTo0WFo6xAkf^*233-oekGtyB8V3Sm^) z5OLtz80cO$SN?TZUM5)bWXIfVt6~hYmV9rok|dcxx!Jl!nUR54T=8f;JB|z>zL5du zCj=!@tP49C=rl!;bX|IDWSeUPn!%sFIT^31)x$EjrZk>jrS+g^V4#H`O=;lCK>UOo zQK_4GcdS_GGgQ#lzAW9n=g#BDqdwcNL_eVvaEAtuAW=JmghO3SU5q#x7-i|wC7uZ; z1O02Sb(uQ&Xtu+3Xm-#agpO`cJ#571V}>?!_M#?_X?io9IC28d!B zvp62!t~fe0BAUU}Vtd{t5{4W0_x=t5yWNgWDG~_9gLuyWNDxPmA;re9{Ud?%vkJWC ziX6uSG?&l5g8xC@s?~A+w_=6?wLt70JBN(1_DMEOvO(STvtQr<&_43I}=G9Wk z*(aM0T5`gHoPqrPbh70cOC&xTtm_GIEJ_AqTZE2d5JW$g|Hv~-k!PEZs866nPcCN; zk^$%4b6zBCTV@MPEdsT20B+~MYMV}2b>Sg!=KD=+CdO6%=z1|HwwIBr7^G;tTU}7I3>8wG z{VC1<{ZNL)$MAm>{kM;&i5^TdjDCw-G0jC}Ya=2J!AhLtec4-St{zzjTEDgF%+kzH zhsEs-hk+=VU5N`+J^S7D9EdObjhqniH^nBc?A9u&VhPY$sUaiw$${*$pO>@6-v)~t zowXgX&Z@Q&GaakBff{&LeYvyJ>oWt?z{EErNJ=Epc+v$@VLa(*R|WBh=TxE6EwU(! zIS;6+2&rmNxhZPv;8@AstY}v?)}#Ze8dFjBlsNS?>71TeD$ z%}W_N|A})jr3Q+J8&>^-C?K9;`gbe9uA4RTPD@DA2Wd1Zp4m&`&E2<>+%RvfpmJQ(~N5(}Nnwrihe_vfOb2r6wMhsYv{F z!Sc(*0qR From 0a9bcc5d1ac4f414e3d5cd53521b9a6ebb39f798 Mon Sep 17 00:00:00 2001 From: Bulimac Vlad Date: Sun, 9 Nov 2014 23:29:25 +0200 Subject: [PATCH 10/12] Dao and POJO completed + OracleDataSource --- .../src/main/resources/liquibase_file.xml | 31 ++++ .../target/classes/liquibase_file.xml | 31 ++++ .../target/classes/log4j.properties | 17 ++ .../compile/default-compile/createdFiles.lst | 1 + .../compile/default-compile/inputFiles.lst | 1 + .../ro/teamnet/zth/dao/DepartmentDao.java | 88 ++++++++++ .../java/ro/teamnet/zth/dao/EmployeeDao.java | 86 ++++++++++ .../ro/teamnet/zth/dao/EmployeeViewDao.java | 25 +++ .../main/java/ro/teamnet/zth/dao/JobDao.java | 90 ++++++++++ .../java/ro/teamnet/zth/dao/LocationDao.java | 154 ++++++++++++++++++ .../ro/teamnet/zth/domain/Department.java | 9 + .../java/ro/teamnet/zth/domain/Location.java | 53 ++++++ .../zth/utils/ResultSetToPojoConvert.java | 31 ++++ .../ro/teamnet/zth/views/EmployeeView.java | 37 +++++ workshops/SQL/Thumbs.db | Bin 0 -> 8704 bytes 15 files changed, 654 insertions(+) create mode 100644 exercises/HelloWorldMain/src/main/resources/liquibase_file.xml create mode 100644 exercises/HelloWorldMain/target/classes/liquibase_file.xml create mode 100644 exercises/HelloWorldMain/target/classes/log4j.properties create mode 100644 exercises/HelloWorldMain/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100644 exercises/HelloWorldMain/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100644 exercises/zth-app/src/main/java/ro/teamnet/zth/dao/LocationDao.java create mode 100644 exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Location.java create mode 100644 exercises/zth-app/src/main/java/ro/teamnet/zth/views/EmployeeView.java create mode 100644 workshops/SQL/Thumbs.db diff --git a/ exercises/HelloWorldMain/src/main/resources/liquibase_file.xml b/ exercises/HelloWorldMain/src/main/resources/liquibase_file.xml new file mode 100644 index 0000000..f8e272c --- /dev/null +++ b/ exercises/HelloWorldMain/src/main/resources/liquibase_file.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ exercises/HelloWorldMain/target/classes/liquibase_file.xml b/ exercises/HelloWorldMain/target/classes/liquibase_file.xml new file mode 100644 index 0000000..f8e272c --- /dev/null +++ b/ exercises/HelloWorldMain/target/classes/liquibase_file.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ exercises/HelloWorldMain/target/classes/log4j.properties b/ exercises/HelloWorldMain/target/classes/log4j.properties new file mode 100644 index 0000000..7b64d41 --- /dev/null +++ b/ exercises/HelloWorldMain/target/classes/log4j.properties @@ -0,0 +1,17 @@ +log4j.rootLogger=info, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=logs.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n diff --git a/ exercises/HelloWorldMain/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/ exercises/HelloWorldMain/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..f77e005 --- /dev/null +++ b/ exercises/HelloWorldMain/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1 @@ +ro\teamnet\hello\HelloWorld.class diff --git a/ exercises/HelloWorldMain/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/ exercises/HelloWorldMain/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..2507747 --- /dev/null +++ b/ exercises/HelloWorldMain/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +C:\Users\Buli\Documents\GitHub\Java\ exercises\HelloWorldMain\src\main\java\ro\teamnet\hello\HelloWorld.java diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java index 36535f7..0c54258 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/DepartmentDao.java @@ -1,6 +1,7 @@ package ro.teamnet.zth.dao; import ro.teamnet.zth.domain.Department; +import ro.teamnet.zth.domain.Job; import ro.teamnet.zth.utils.ResultSetToPojoConvert; import java.sql.Connection; @@ -8,6 +9,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; /** * Created by Buli on 04.11.2014. @@ -58,4 +60,90 @@ public Department getDepartmentById(Connection con, int id) { return departments.size() > 0 ? departments.get(0) : null; } + public void saveDepartment(Department department, Connection con) { + HashMap insertIntoTableDepartments = new HashMap(); + String tableName = "departments"; + + insertIntoTableDepartments.put("department_id", department.getDepartmentId().toString()); + insertIntoTableDepartments.put("department_name", department.getDepartmentName()); + insertIntoTableDepartments.put("department_location", department.getLocation().getLocationId().toString()); + + PreparedStatement stmt; + try { + stmt = con.prepareStatement(""); + String createTableString = "INSERT INTO " + tableName + " ( "; + StringBuilder sqlStatement = new StringBuilder(); + sqlStatement.append(createTableString); + Integer valuesCount = insertIntoTableDepartments.keySet().size(); + + for (String value : insertIntoTableDepartments.keySet()) { + valuesCount--; + String columnName = value + (valuesCount != 0 ? " , " : " ) "); + sqlStatement.append(columnName); + } + + sqlStatement.append(" VALUES ( '"); + valuesCount = insertIntoTableDepartments.keySet().size(); + + for (String valueName : insertIntoTableDepartments.keySet()) { + valuesCount--; + String columnString = insertIntoTableDepartments.get(valueName) + (valuesCount != 0 ? "' , '" : "')"); + sqlStatement.append(columnString); + } + + stmt.executeQuery(sqlStatement.toString()); + stmt.close(); + System.out.println("Inserted into table " + tableName + "..."); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void updateDepartment(Department department, Connection con){ + HashMap insertIntoTableDepartments = new HashMap(); + String tableName = "departments"; + + insertIntoTableDepartments.put("department_id", department.getDepartmentId().toString()); + insertIntoTableDepartments.put("department_name", department.getDepartmentName()); + insertIntoTableDepartments.put("department_location", department.getLocation().getLocationId().toString()); + + PreparedStatement stmt; + + try { + stmt = con.prepareStatement(""); + String updateTableString = "UPDATE " + tableName + " SET "; + StringBuilder sqlStatement = new StringBuilder(); + sqlStatement.append(updateTableString); + Integer columnsCount = insertIntoTableDepartments.keySet().size(); + + for(String columnName : insertIntoTableDepartments.keySet()){ + columnsCount --; + String columnString = columnName + " = '" + insertIntoTableDepartments.get(columnName) + (columnsCount != 0 ? "' , " : "' "); + sqlStatement.append(columnString); + } + + sqlStatement.append("WHERE department_id = " + department.getDepartmentId()); + stmt.executeQuery(sqlStatement.toString()); + stmt.close(); + System.out.println("Created table " + tableName + " in database..."); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void deleteDepartment(Department department, Connection con){ + PreparedStatement stmt; + String tableName = "departments"; + try { + stmt = con.prepareStatement(""); + String deleteStatement = "DELETE FROM " + tableName + " WHERE department_id = " + department.getDepartmentId(); + stmt.executeUpdate(deleteStatement); + stmt.close(); + System.out.println("Dropped table " + tableName + " from database..."); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java index 737a852..a6ce8e3 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java @@ -85,6 +85,92 @@ public void saveEmployee(Employee employee, Connection con){ sqlStatement.append(createTableString); Integer valuesCount = insertIntoTableEmployees.keySet().size(); + for(String value : insertIntoTableEmployees.keySet()){ + valuesCount --; + String columnName = value + (valuesCount != 0 ? " , " : " ) "); + sqlStatement.append(columnName); + } + + sqlStatement.append(" VALUES ( '"); + valuesCount = insertIntoTableEmployees.keySet().size(); + + for(String valueName : insertIntoTableEmployees.keySet()){ + valuesCount --; + String columnString; + if (valueName.equals("hire_date")) { + columnString = insertIntoTableEmployees.get(valueName) + (valuesCount != 0 ? " , '" : "')"); + }else if (valueName.equals("first_name")) { + columnString = insertIntoTableEmployees.get(valueName) + (valuesCount != 0 ? "' , " : "')"); + }else + { + columnString = insertIntoTableEmployees.get(valueName) + (valuesCount != 0 ? "' , '" : "')"); + } + sqlStatement.append(columnString); + } + + stmt.executeQuery(sqlStatement.toString()); + stmt.close(); + System.out.println("Inserted into table " + tableName + "..."); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void updateEmployee(Employee employee, Connection con){ + HashMap insertIntoTableEmployees = new HashMap(); + String tableName = "employees"; + + insertIntoTableEmployees.put("employee_id", employee.getEmployeeId().toString()); + insertIntoTableEmployees.put("first_name", employee.getFirstName()); + insertIntoTableEmployees.put("last_name", employee.getLastName()); + insertIntoTableEmployees.put("email", employee.getEmail()); + insertIntoTableEmployees.put("phone_number", employee.getPhoneNmber()); + insertIntoTableEmployees.put("hire_date", "TO_DATE('" + employee.getHireDate() + "','yyyy-mm-dd"); + insertIntoTableEmployees.put("job_id",employee.getJob().getJobId().toString()); + insertIntoTableEmployees.put("salary", employee.getSalary().toString()); + insertIntoTableEmployees.put("commision_pct", employee.getCommisionPoints().toString()); + insertIntoTableEmployees.put("manager_id", employee.getManager().getEmployeeId().toString()); + insertIntoTableEmployees.put("department_id", employee.getDepartment().getDepartmentId().toString()); + + PreparedStatement stmt; + + try { + stmt = con.prepareStatement(""); + String updateTableString = "UPDATE " + tableName + " SET "; + StringBuilder sqlStatement = new StringBuilder(); + sqlStatement.append(updateTableString); + Integer columnsCount = insertIntoTableEmployees.keySet().size(); + + for(String columnName : insertIntoTableEmployees.keySet()){ + columnsCount --; + String columnString; + if (columnName.equals("hire_date")) { + columnString = columnName + " = " + insertIntoTableEmployees.get(columnName) + (columnsCount != 0 ? " , " : "' "); + } else { + columnString = columnName + " = '" + insertIntoTableEmployees.get(columnName) + (columnsCount != 0 ? "' , " : "' "); + } + sqlStatement.append(columnString); + } + + sqlStatement.append("WHERE employee_id = " + employee.getEmployeeId()); + stmt.executeQuery(sqlStatement.toString()); + stmt.close(); + System.out.println("Created table " + tableName + " in database..."); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void deleteEmployee(Employee employee, Connection con){ + PreparedStatement stmt; + String tableName = "employees"; + try { + stmt = con.prepareStatement(""); + String deleteStatement = "DELETE FROM " + tableName + " WHERE employee_id = " + employee.getEmployeeId(); + stmt.executeUpdate(deleteStatement); + stmt.close(); + System.out.println("Dropped table " + tableName + " from database..."); } catch (SQLException e) { e.printStackTrace(); } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeViewDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeViewDao.java index 0cc0444..a93caa3 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeViewDao.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeViewDao.java @@ -1,7 +1,32 @@ package ro.teamnet.zth.dao; +import ro.teamnet.zth.utils.ResultSetToPojoConvert; +import ro.teamnet.zth.views.EmployeeView; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + /** * Created by Buli on 04.11.2014. */ public class EmployeeViewDao { + + public EmployeeView getEmployeeView(Connection con, Long id){ + PreparedStatement stmt; + ArrayList employeeViews = null; + try { + stmt = con.prepareStatement(""); + String query = "SELECT * " + "FROM EMPLOYEE_LIST " + "WHERE employee_id=" + id; + ResultSet rs = stmt.executeQuery(query); + employeeViews = ResultSetToPojoConvert.convertToEmployeeView(rs,con); + stmt.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return employeeViews.size() > 0 ? employeeViews.get(0) : null; + } + } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java index 6829dde..02cb655 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/JobDao.java @@ -1,5 +1,6 @@ package ro.teamnet.zth.dao; +import ro.teamnet.zth.domain.Employee; import ro.teamnet.zth.domain.Job; import ro.teamnet.zth.utils.ResultSetToPojoConvert; @@ -8,6 +9,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; /** * Created by Buli on 04.11.2014. @@ -59,4 +61,92 @@ public Job getJobById(Connection con, String id) { return jobs.size() > 0 ? jobs.get(0) : null; } + public void saveJob(Job job, Connection con) { + HashMap insertIntoTableJobs = new HashMap(); + String tableName = "jobs"; + + insertIntoTableJobs.put("job_id", job.getJobId()); + insertIntoTableJobs.put("job_title", job.getJobTitle()); + insertIntoTableJobs.put("min_salary", job.getMinSalary().toString()); + insertIntoTableJobs.put("max_salary", job.getMaxSalary().toString()); + + PreparedStatement stmt; + try { + stmt = con.prepareStatement(""); + String createTableString = "INSERT INTO " + tableName + " ( "; + StringBuilder sqlStatement = new StringBuilder(); + sqlStatement.append(createTableString); + Integer valuesCount = insertIntoTableJobs.keySet().size(); + + for (String value : insertIntoTableJobs.keySet()) { + valuesCount--; + String columnName = value + (valuesCount != 0 ? " , " : " ) "); + sqlStatement.append(columnName); + } + + sqlStatement.append(" VALUES ( '"); + valuesCount = insertIntoTableJobs.keySet().size(); + + for (String valueName : insertIntoTableJobs.keySet()) { + valuesCount--; + String columnString = insertIntoTableJobs.get(valueName) + (valuesCount != 0 ? "' , '" : "')"); + sqlStatement.append(columnString); + } + + stmt.executeQuery(sqlStatement.toString()); + stmt.close(); + System.out.println("Inserted into table " + tableName + "..."); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void updateJob(Job job, Connection con){ + HashMap insertIntoTableJobs = new HashMap(); + String tableName = "jobs"; + + insertIntoTableJobs.put("job_id", job.getJobId()); + insertIntoTableJobs.put("job_title", job.getJobTitle()); + insertIntoTableJobs.put("min_salary", job.getMinSalary().toString()); + insertIntoTableJobs.put("max_salary", job.getMaxSalary().toString()); + + PreparedStatement stmt; + + try { + stmt = con.prepareStatement(""); + String updateTableString = "UPDATE " + tableName + " SET "; + StringBuilder sqlStatement = new StringBuilder(); + sqlStatement.append(updateTableString); + Integer columnsCount = insertIntoTableJobs.keySet().size(); + + for(String columnName : insertIntoTableJobs.keySet()){ + columnsCount --; + String columnString = columnName + " = '" + insertIntoTableJobs.get(columnName) + (columnsCount != 0 ? "' , " : "' "); + sqlStatement.append(columnString); + } + + sqlStatement.append("WHERE job_id = " + job.getJobId()); + stmt.executeQuery(sqlStatement.toString()); + stmt.close(); + System.out.println("Created table " + tableName + " in database..."); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void deleteJob(Job job, Connection con){ + PreparedStatement stmt; + String tableName = "jobs"; + try { + stmt = con.prepareStatement(""); + String deleteStatement = "DELETE FROM " + tableName + " WHERE job_id = " + job.getJobId(); + stmt.executeUpdate(deleteStatement); + stmt.close(); + System.out.println("Dropped table " + tableName + " from database..."); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/LocationDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/LocationDao.java new file mode 100644 index 0000000..cf436a0 --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/LocationDao.java @@ -0,0 +1,154 @@ +package ro.teamnet.zth.dao; + +import ro.teamnet.zth.domain.Employee; +import ro.teamnet.zth.domain.Location; +import ro.teamnet.zth.utils.ResultSetToPojoConvert; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; + +/** + * Created by Buli on 11/9/2014. + */ +public class LocationDao { + + public ArrayList getAllLocations(Connection con){ + PreparedStatement stmt = null; + ResultSet rs = null; + String selectAllFromTableString = "Select * from locations"; + try { + stmt = con.prepareStatement(selectAllFromTableString); + stmt.setMaxRows(5); + rs = stmt.executeQuery(); + return ResultSetToPojoConvert.convertToLocation(rs, con); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + stmt.close(); + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return new ArrayList(); + } + + public Location getLocationById(Connection con, int id) { + String selectAllFromTableString = "Select * from locations where location_id = ?"; + PreparedStatement stmt = null; + ResultSet rs = null; + ArrayList location = null; + try { + stmt = con.prepareStatement(selectAllFromTableString); + stmt.setInt(1, id); + rs = stmt.executeQuery(); + location = ResultSetToPojoConvert.convertToLocation(rs, con); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + stmt.close(); + rs.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return location.size() > 0 ? location.get(0) : null; + } + + public void saveLocation(Location location, Connection con){ + HashMap insertIntoTablelocation = new HashMap(); + String tableName = "locations"; + + insertIntoTablelocation.put("location_id",location.getLocationId().toString()); + insertIntoTablelocation.put("street_address",location.getStreetAdress().toString()); + insertIntoTablelocation.put("postal_code",location.getPostalCode().toString()); + insertIntoTablelocation.put("city",location.getCity().toString()); + insertIntoTablelocation.put("state_province",location.getStateProvince().toString()); + + PreparedStatement stmt; + try { + stmt = con.prepareStatement(""); + String createTableString = "INSERT INTO " + tableName + " ( "; + StringBuilder sqlStatement = new StringBuilder(); + sqlStatement.append(createTableString); + Integer valuesCount = insertIntoTablelocation.keySet().size(); + + for(String value : insertIntoTablelocation.keySet()){ + valuesCount --; + String columnName = value + (valuesCount != 0 ? " , " : " ) "); + sqlStatement.append(columnName); + } + + sqlStatement.append(" VALUES ( '"); + valuesCount = insertIntoTablelocation.keySet().size(); + + for(String valueName : insertIntoTablelocation.keySet()){ + valuesCount --; + String columnString = insertIntoTablelocation.get(valueName) + (valuesCount != 0 ? "' , '" : "')"); + sqlStatement.append(columnString); + } + + stmt.executeQuery(sqlStatement.toString()); + stmt.close(); + System.out.println("Inserted into table " + tableName + "..."); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void updateLocation(Location location, Connection con){ + HashMap insertIntoTablelocation = new HashMap(); + String tableName = "locations"; + + insertIntoTablelocation.put("location_id",location.getLocationId().toString()); + insertIntoTablelocation.put("street_address",location.getStreetAdress().toString()); + insertIntoTablelocation.put("postal_code",location.getPostalCode().toString()); + insertIntoTablelocation.put("city",location.getCity().toString()); + insertIntoTablelocation.put("state_province",location.getStateProvince().toString()); + + PreparedStatement stmt; + + try { + stmt = con.prepareStatement(""); + String updateTableString = "UPDATE " + tableName + " SET "; + StringBuilder sqlStatement = new StringBuilder(); + sqlStatement.append(updateTableString); + Integer columnsCount = insertIntoTablelocation.keySet().size(); + + for(String columnName : insertIntoTablelocation.keySet()){ + columnsCount --; + String columnString = columnName + " = '" + insertIntoTablelocation.get(columnName) + (columnsCount != 0 ? "' , " : "' "); + sqlStatement.append(columnString); + } + + sqlStatement.append("WHERE location_id = " + location.getLocationId()); + stmt.executeQuery(sqlStatement.toString()); + stmt.close(); + System.out.println("Created table " + tableName + " in database..."); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public void deleteLocation(Location location, Connection con){ + PreparedStatement stmt; + String tableName = "location"; + try { + stmt = con.prepareStatement(""); + String deleteStatement = "DELETE FROM " + tableName + " WHERE location_id = " + location.getLocationId(); + stmt.executeUpdate(deleteStatement); + stmt.close(); + System.out.println("Dropped table " + tableName + " from database..."); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java index 0a0cb12..d888288 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Department.java @@ -7,6 +7,15 @@ public class Department { private Long departmentId; private String departmentName; + private Location location; + + public Location getLocation() { + return location; + } + + public void setLocation(Location location) { + this.location = location; + } public Long getDepartmentId() { return departmentId; diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Location.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Location.java new file mode 100644 index 0000000..1217c50 --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/domain/Location.java @@ -0,0 +1,53 @@ +package ro.teamnet.zth.domain; + +/** + * Created by Buli on 11/9/2014. + */ +public class Location { + + private Long locationId; + private String streetAdress; + private String postalCode; + private String city; + private String stateProvince; + + public Long getLocationId() { + return locationId; + } + + public void setLocationId(Long locationId) { + this.locationId = locationId; + } + + public String getStreetAdress() { + return streetAdress; + } + + public void setStreetAdress(String streetAdress) { + this.streetAdress = streetAdress; + } + + public String getPostalCode() { + return postalCode; + } + + public void setPostalCode(String postalCode) { + this.postalCode = postalCode; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getStateProvince() { + return stateProvince; + } + + public void setStateProvince(String stateProvince) { + this.stateProvince = stateProvince; + } +} diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/ResultSetToPojoConvert.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/ResultSetToPojoConvert.java index d474006..4435b77 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/ResultSetToPojoConvert.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/utils/ResultSetToPojoConvert.java @@ -3,9 +3,12 @@ import ro.teamnet.zth.dao.DepartmentDao; import ro.teamnet.zth.dao.EmployeeDao; import ro.teamnet.zth.dao.JobDao; +import ro.teamnet.zth.dao.LocationDao; import ro.teamnet.zth.domain.Department; import ro.teamnet.zth.domain.Employee; import ro.teamnet.zth.domain.Job; +import ro.teamnet.zth.domain.Location; +import ro.teamnet.zth.views.EmployeeView; import java.sql.Connection; import java.sql.ResultSet; @@ -56,13 +59,41 @@ public static ArrayList convertToJob(ResultSet rs, Connection con) throws S public static ArrayList convertToDepartment(ResultSet rs, Connection con) throws SQLException{ ArrayList arrayListFromResultSet = new ArrayList(); + LocationDao locationDao = new LocationDao(); while (rs.next()){ Department department = new Department(); department.setDepartmentId(rs.getLong("department_id")); department.setDepartmentName(rs.getString("department_name")); + department.setLocation(locationDao.getLocationById(con,rs.getInt("location_id"))); arrayListFromResultSet.add(department); } return arrayListFromResultSet; } + public static ArrayList convertToLocation(ResultSet rs, Connection con) throws SQLException{ + ArrayList arrayListFromResultSet = new ArrayList(); + while (rs.next()){ + Location location = new Location(); + location.setLocationId(rs.getLong("location_id")); + location.setStreetAdress(rs.getString("street_address")); + location.setPostalCode(rs.getString("postal_code")); + location.setCity(rs.getString("city")); + location.setStateProvince(rs.getString("state_province")); + arrayListFromResultSet.add(location); + } + return arrayListFromResultSet; + } + + public static ArrayList convertToEmployeeView(ResultSet rs, Connection con) throws SQLException{ + ArrayList arrayListFromResultSet = new ArrayList(); + while(rs.next()){ + EmployeeView employeeView = new EmployeeView(); + employeeView.setEmployeeId(rs.getLong("employee_id")); + employeeView.setFirstName(rs.getString("first_name")); + employeeView.setDepartmentName(rs.getString("department_name")); + arrayListFromResultSet.add(employeeView); + } + return arrayListFromResultSet; + } + } diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/views/EmployeeView.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/views/EmployeeView.java new file mode 100644 index 0000000..280217c --- /dev/null +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/views/EmployeeView.java @@ -0,0 +1,37 @@ +package ro.teamnet.zth.views; + +import ro.teamnet.zth.domain.Department; + +/** + * Created by Buli on 11/9/2014. + */ +public class EmployeeView { + + private Long employeeId; + private String firstName; + private String departmentName; + + public Long getEmployeeId() { + return employeeId; + } + + public void setEmployeeId(Long employeeId) { + this.employeeId = employeeId; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getDepartmentName() { + return departmentName; + } + + public void setDepartmentName(String departmentName) { + this.departmentName = departmentName; + } +} diff --git a/workshops/SQL/Thumbs.db b/workshops/SQL/Thumbs.db new file mode 100644 index 0000000000000000000000000000000000000000..c9e0d577d7026a19982e25c512ef45e4643a8163 GIT binary patch literal 8704 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 WObY^+(zPUB{K$Xg@A&_9QvU^Ke4$|g literal 0 HcmV?d00001 From c7115fa651550ead030061f3ccc3b8ef2f39cedf Mon Sep 17 00:00:00 2001 From: Bulimac Vlad Date: Mon, 10 Nov 2014 22:09:36 +0200 Subject: [PATCH 11/12] EmployeeDao updated --- .../src/main/java/ro/teamnet/zth/App.java | 26 +++++++++++++++++++ .../java/ro/teamnet/zth/dao/EmployeeDao.java | 17 ++++++------ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java index cdf8d6a..adf388c 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/App.java @@ -1,7 +1,11 @@ package ro.teamnet.zth; import java.sql.Connection; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; +import java.util.GregorianCalendar; import java.util.HashMap; import ro.teamnet.zth.dao.DepartmentDao; @@ -57,6 +61,28 @@ public static void main( String[] args ) // System.out.println(employee.toString()); // System.out.println(arrayList.toString()); +// Job job = new Job(); +// Department dep = new Department(); +// Employee manager = new Employee(); +// Date date = new Date(1346524199000l); +// manager.setEmployeeId(100L); +// dep.setDepartmentId(150L); +// job.setJobId("SA_REP"); +// Employee employee = new Employee(); +// employee.setEmployeeId(900L); +// employee.setFirstName("Vlad"); +// employee.setLastName("Bulimac"); +// employee.setEmail("buli.vlad@yahoo.com"); +// employee.setPhoneNmber("0742387589"); +// employee.setHireDate(date); +// employee.setJob(job); +// employee.setSalary(12000.2); +// employee.setCommisionPoints(20.2); +// employee.setDepartment(dep); +// employee.setManager(manager); +// +// EmployeeDao emp = new EmployeeDao(); +// emp.saveEmployee(employee,con); DatabaseManager.closeConnecction(con); diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java index a6ce8e3..02e5b65 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java @@ -70,16 +70,16 @@ public void saveEmployee(Employee employee, Connection con){ insertIntoTableEmployees.put("last_name", employee.getLastName()); insertIntoTableEmployees.put("email", employee.getEmail()); insertIntoTableEmployees.put("phone_number", employee.getPhoneNmber()); - insertIntoTableEmployees.put("hire_date", "TO_DATE('" + employee.getHireDate() + "','yyyy-mm-dd"); + insertIntoTableEmployees.put("hire_date", "TO_DATE('" + employee.getHireDate().toString() + "','yyyy-mm-dd')"); insertIntoTableEmployees.put("job_id",employee.getJob().getJobId().toString()); insertIntoTableEmployees.put("salary", employee.getSalary().toString()); - insertIntoTableEmployees.put("commision_pct", employee.getCommisionPoints().toString()); + insertIntoTableEmployees.put("commission_pct", employee.getCommisionPoints().toString()); insertIntoTableEmployees.put("manager_id", employee.getManager().getEmployeeId().toString()); insertIntoTableEmployees.put("department_id", employee.getDepartment().getDepartmentId().toString()); PreparedStatement stmt; try { - stmt = con.prepareStatement(""); + String createTableString = "INSERT INTO " + tableName + " ( "; StringBuilder sqlStatement = new StringBuilder(); sqlStatement.append(createTableString); @@ -99,7 +99,7 @@ public void saveEmployee(Employee employee, Connection con){ String columnString; if (valueName.equals("hire_date")) { columnString = insertIntoTableEmployees.get(valueName) + (valuesCount != 0 ? " , '" : "')"); - }else if (valueName.equals("first_name")) { + }else if (valueName.equals("phone_number")) { columnString = insertIntoTableEmployees.get(valueName) + (valuesCount != 0 ? "' , " : "')"); }else { @@ -107,8 +107,9 @@ public void saveEmployee(Employee employee, Connection con){ } sqlStatement.append(columnString); } - - stmt.executeQuery(sqlStatement.toString()); + System.out.println(sqlStatement.toString()); + stmt = con.prepareStatement(sqlStatement.toString()); + ResultSet rs = stmt.executeQuery(); stmt.close(); System.out.println("Inserted into table " + tableName + "..."); @@ -126,10 +127,10 @@ public void updateEmployee(Employee employee, Connection con){ insertIntoTableEmployees.put("last_name", employee.getLastName()); insertIntoTableEmployees.put("email", employee.getEmail()); insertIntoTableEmployees.put("phone_number", employee.getPhoneNmber()); - insertIntoTableEmployees.put("hire_date", "TO_DATE('" + employee.getHireDate() + "','yyyy-mm-dd"); + insertIntoTableEmployees.put("hire_date", "TO_DATE('" + employee.getHireDate().toString() + "','yyyy-mm-dd')"); insertIntoTableEmployees.put("job_id",employee.getJob().getJobId().toString()); insertIntoTableEmployees.put("salary", employee.getSalary().toString()); - insertIntoTableEmployees.put("commision_pct", employee.getCommisionPoints().toString()); + insertIntoTableEmployees.put("commission_pct", employee.getCommisionPoints().toString()); insertIntoTableEmployees.put("manager_id", employee.getManager().getEmployeeId().toString()); insertIntoTableEmployees.put("department_id", employee.getDepartment().getDepartmentId().toString()); From ffaba3c3913dca72d5051d2bba1a5736b01400cc Mon Sep 17 00:00:00 2001 From: Bulimac Vlad Date: Thu, 13 Nov 2014 18:07:49 +0200 Subject: [PATCH 12/12] EmployeeDao modified --- .../src/main/java/ro/teamnet/zth/dao/EmployeeDao.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java index 02e5b65..b3c08fa 100644 --- a/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java +++ b/ exercises/zth-app/src/main/java/ro/teamnet/zth/dao/EmployeeDao.java @@ -137,7 +137,7 @@ public void updateEmployee(Employee employee, Connection con){ PreparedStatement stmt; try { - stmt = con.prepareStatement(""); + String updateTableString = "UPDATE " + tableName + " SET "; StringBuilder sqlStatement = new StringBuilder(); sqlStatement.append(updateTableString); @@ -155,7 +155,8 @@ public void updateEmployee(Employee employee, Connection con){ } sqlStatement.append("WHERE employee_id = " + employee.getEmployeeId()); - stmt.executeQuery(sqlStatement.toString()); + stmt = con.prepareStatement(sqlStatement.toString()); + stmt.executeQuery(); stmt.close(); System.out.println("Created table " + tableName + " in database..."); } catch (SQLException e) { @@ -167,9 +168,10 @@ public void deleteEmployee(Employee employee, Connection con){ PreparedStatement stmt; String tableName = "employees"; try { - stmt = con.prepareStatement(""); + String deleteStatement = "DELETE FROM " + tableName + " WHERE employee_id = " + employee.getEmployeeId(); - stmt.executeUpdate(deleteStatement); + stmt = con.prepareStatement(deleteStatement); + stmt.executeUpdate(); stmt.close(); System.out.println("Dropped table " + tableName + " from database..."); } catch (SQLException e) {