Bladeren bron

Completed ORM

Tommy Rogers 6 jaren geleden
bovenliggende
commit
2c5842eb6e
3 gewijzigde bestanden met toevoegingen van 208 en 120 verwijderingen
  1. 150
    62
      .idea/workspace.xml
  2. 58
    58
      src/main/java/AccountApp.java
  3. BIN
      target/classes/AccountApp.class

+ 150
- 62
.idea/workspace.xml Bestand weergeven

@@ -2,8 +2,8 @@
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4 4
     <list default="true" id="0df8da2e-7f64-41e2-baac-86bf1af2ff40" name="Default" comment="">
5
-      <change afterPath="$PROJECT_DIR$/src/main/java/AccountApp.java" afterDir="false" />
6 5
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6
+      <change beforePath="$PROJECT_DIR$/src/main/java/AccountApp.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AccountApp.java" afterDir="false" />
7 7
     </list>
8 8
     <ignored path="$PROJECT_DIR$/out/" />
9 9
     <ignored path="$PROJECT_DIR$/target/" />
@@ -18,12 +18,12 @@
18 18
     <favorites_list name="ORM-Lab" />
19 19
   </component>
20 20
   <component name="FileEditorManager">
21
-    <leaf>
21
+    <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
22 22
       <file leaf-file-name="pom.xml" pinned="false" current-in-tab="false">
23 23
         <entry file="file://$PROJECT_DIR$/pom.xml">
24 24
           <provider selected="true" editor-type-id="text-editor">
25
-            <state relative-caret-position="130">
26
-              <caret line="23" column="17" lean-forward="true" selection-start-line="23" selection-start-column="17" selection-end-line="23" selection-end-column="17" />
25
+            <state relative-caret-position="345">
26
+              <caret line="23" column="17" selection-start-line="23" selection-start-column="17" selection-end-line="23" selection-end-column="17" />
27 27
             </state>
28 28
           </provider>
29 29
         </entry>
@@ -31,24 +31,14 @@
31 31
       <file leaf-file-name="Account.java" pinned="false" current-in-tab="false">
32 32
         <entry file="file://$PROJECT_DIR$/src/main/java/Account.java">
33 33
           <provider selected="true" editor-type-id="text-editor">
34
-            <state relative-caret-position="112">
35
-              <caret line="18" column="8" lean-forward="true" selection-start-line="18" selection-start-column="8" selection-end-line="29" selection-end-column="9" />
34
+            <state relative-caret-position="210">
35
+              <caret line="14" lean-forward="true" selection-start-line="14" selection-end-line="14" />
36 36
               <folding>
37 37
                 <element signature="imports" expanded="true" />
38
+                <element signature="e#716#717#0" expanded="true" />
38 39
                 <element signature="e#756#757#0" expanded="true" />
39
-                <element signature="e#796#797#0" expanded="true" />
40
-                <element signature="e#960#961#0" expanded="true" />
41
-                <element signature="e#993#994#0" expanded="true" />
42
-                <element signature="e#1028#1029#0" expanded="true" />
43
-                <element signature="e#1063#1064#0" expanded="true" />
40
+                <element signature="e#1067#1068#0" expanded="true" />
44 41
                 <element signature="e#1107#1108#0" expanded="true" />
45
-                <element signature="e#1147#1148#0" expanded="true" />
46
-                <element signature="e#1186#1187#0" expanded="true" />
47
-                <element signature="e#1225#1226#0" expanded="true" />
48
-                <element signature="e#1277#1278#0" expanded="true" />
49
-                <element signature="e#1325#1326#0" expanded="true" />
50
-                <element signature="e#1376#1377#0" expanded="true" />
51
-                <element signature="e#1422#1423#0" expanded="true" />
52 42
               </folding>
53 43
             </state>
54 44
           </provider>
@@ -57,8 +47,8 @@
57 47
       <file leaf-file-name="AccountApp.java" pinned="false" current-in-tab="true">
58 48
         <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
59 49
           <provider selected="true" editor-type-id="text-editor">
60
-            <state relative-caret-position="311">
61
-              <caret line="77" selection-start-line="77" selection-end-line="77" />
50
+            <state relative-caret-position="804">
51
+              <caret line="105" column="36" selection-start-line="105" selection-start-column="36" selection-end-line="105" selection-end-column="36" />
62 52
               <folding>
63 53
                 <element signature="imports" expanded="true" />
64 54
               </folding>
@@ -104,7 +94,7 @@
104 94
     <packageJsonPaths />
105 95
   </component>
106 96
   <component name="ProjectFrameBounds">
107
-    <option name="x" value="128" />
97
+    <option name="x" value="-252" />
108 98
     <option name="y" value="-1057" />
109 99
     <option name="width" value="1165" />
110 100
     <option name="height" value="709" />
@@ -154,9 +144,9 @@
154 144
           <select />
155 145
         </subPane>
156 146
       </pane>
157
-      <pane id="AndroidView" />
158
-      <pane id="Scope" />
159 147
       <pane id="PackagesPane" />
148
+      <pane id="Scope" />
149
+      <pane id="AndroidView" />
160 150
     </panes>
161 151
   </component>
162 152
   <component name="PropertiesComponent">
@@ -164,6 +154,9 @@
164 154
     <property name="aspect.path.notification.shown" value="true" />
165 155
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
166 156
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
157
+    <property name="project.structure.last.edited" value="Modules" />
158
+    <property name="project.structure.proportion" value="0.0" />
159
+    <property name="project.structure.side.proportion" value="0.0" />
167 160
   </component>
168 161
   <component name="RunDashboard">
169 162
     <option name="ruleStates">
@@ -240,42 +233,44 @@
240 233
       <option name="number" value="Default" />
241 234
       <option name="presentableId" value="Default" />
242 235
       <updated>1529876073719</updated>
243
-      <workItem from="1529876077870" duration="11993000" />
236
+      <workItem from="1529876077870" duration="12173000" />
237
+      <workItem from="1529950725218" duration="4356000" />
244 238
     </task>
245 239
     <servers />
246 240
   </component>
247 241
   <component name="TimeTrackingManager">
248
-    <option name="totallyTimeSpent" value="11993000" />
242
+    <option name="totallyTimeSpent" value="16529000" />
249 243
   </component>
250 244
   <component name="ToolWindowManager">
251
-    <frame x="128" y="-1057" width="1165" height="709" extended-state="0" />
245
+    <frame x="-252" y="-1057" width="1165" height="709" extended-state="0" />
246
+    <editor active="true" />
252 247
     <layout>
253
-      <window_info anchor="right" id="Palette" />
248
+      <window_info anchor="right" id="Palette" order="3" />
254 249
       <window_info anchor="bottom" id="TODO" order="6" />
255
-      <window_info anchor="bottom" id="Messages" weight="0.3293718" />
256
-      <window_info anchor="right" id="Palette&#9;" />
257
-      <window_info id="Image Layers" />
258
-      <window_info anchor="right" id="Capture Analysis" />
259
-      <window_info anchor="bottom" id="Event Log" side_tool="true" />
260
-      <window_info anchor="right" id="Maven Projects" />
261
-      <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
262
-      <window_info anchor="bottom" id="Run" order="2" weight="0.3293718" />
263
-      <window_info anchor="bottom" id="Version Control" />
264
-      <window_info active="true" anchor="bottom" id="Terminal" visible="true" weight="0.3293718" />
265
-      <window_info id="Capture Tool" />
266
-      <window_info id="Designer" />
267
-      <window_info content_ui="combo" id="Project" order="0" sideWeight="0.49873418" visible="true" weight="0.24933214" />
268
-      <window_info anchor="right" id="Database" />
250
+      <window_info anchor="bottom" id="Messages" order="7" weight="0.3293718" />
251
+      <window_info anchor="right" id="Palette&#9;" order="3" />
252
+      <window_info id="Image Layers" order="2" />
253
+      <window_info anchor="right" id="Capture Analysis" order="3" />
254
+      <window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
255
+      <window_info anchor="right" id="Maven Projects" order="3" />
256
+      <window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
257
+      <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.3293718" />
258
+      <window_info anchor="bottom" id="Version Control" order="7" />
259
+      <window_info anchor="bottom" id="Terminal" order="7" weight="0.3293718" />
260
+      <window_info id="Capture Tool" order="2" />
261
+      <window_info id="Designer" order="2" />
262
+      <window_info content_ui="combo" id="Project" order="0" sideWeight="0.49873418" visible="true" weight="0.2537845" />
263
+      <window_info anchor="right" id="Database" order="3" />
264
+      <window_info anchor="bottom" id="Find" order="1" weight="0.3293718" />
269 265
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
270 266
       <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
271
-      <window_info id="UI Designer" />
272
-      <window_info anchor="right" id="Theme Preview" />
267
+      <window_info id="UI Designer" order="2" />
268
+      <window_info anchor="right" id="Theme Preview" order="3" />
273 269
       <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
274
-      <window_info id="Favorites" sideWeight="0.5012658" side_tool="true" weight="0.24933214" />
275
-      <window_info anchor="bottom" id="Find" order="1" />
276
-      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
270
+      <window_info id="Favorites" order="2" sideWeight="0.5012658" side_tool="true" weight="0.24933214" />
277 271
       <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
278 272
       <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
273
+      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
279 274
       <window_info anchor="bottom" id="Message" order="0" />
280 275
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
281 276
     </layout>
@@ -289,39 +284,60 @@
289 284
   <component name="editorHistoryManager">
290 285
     <entry file="file://$PROJECT_DIR$/pom.xml">
291 286
       <provider selected="true" editor-type-id="text-editor">
292
-        <state relative-caret-position="130">
287
+        <state relative-caret-position="345">
293 288
           <caret line="23" column="17" lean-forward="true" selection-start-line="23" selection-start-column="17" selection-end-line="23" selection-end-column="17" />
294 289
         </state>
295 290
       </provider>
296 291
     </entry>
297 292
     <entry file="file://$PROJECT_DIR$/src/main/java/Account.java">
298 293
       <provider selected="true" editor-type-id="text-editor">
299
-        <state relative-caret-position="112">
294
+        <state relative-caret-position="255">
300 295
           <caret line="18" column="8" lean-forward="true" selection-start-line="18" selection-start-column="8" selection-end-line="29" selection-end-column="9" />
301 296
           <folding>
302 297
             <element signature="imports" expanded="true" />
298
+            <element signature="e#716#717#0" expanded="true" />
303 299
             <element signature="e#756#757#0" expanded="true" />
304
-            <element signature="e#796#797#0" expanded="true" />
305
-            <element signature="e#960#961#0" expanded="true" />
306
-            <element signature="e#993#994#0" expanded="true" />
307
-            <element signature="e#1028#1029#0" expanded="true" />
308
-            <element signature="e#1063#1064#0" expanded="true" />
300
+            <element signature="e#1067#1068#0" expanded="true" />
309 301
             <element signature="e#1107#1108#0" expanded="true" />
310
-            <element signature="e#1147#1148#0" expanded="true" />
311
-            <element signature="e#1186#1187#0" expanded="true" />
312
-            <element signature="e#1225#1226#0" expanded="true" />
313
-            <element signature="e#1277#1278#0" expanded="true" />
314
-            <element signature="e#1325#1326#0" expanded="true" />
315
-            <element signature="e#1376#1377#0" expanded="true" />
316
-            <element signature="e#1422#1423#0" expanded="true" />
317 302
           </folding>
318 303
         </state>
319 304
       </provider>
320 305
     </entry>
321 306
     <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
322 307
       <provider selected="true" editor-type-id="text-editor">
323
-        <state relative-caret-position="311">
324
-          <caret line="77" selection-start-line="77" selection-end-line="77" />
308
+        <state relative-caret-position="1035">
309
+          <caret line="77" lean-forward="true" selection-start-line="77" selection-end-line="77" />
310
+          <folding>
311
+            <element signature="imports" expanded="true" />
312
+          </folding>
313
+        </state>
314
+      </provider>
315
+    </entry>
316
+    <entry file="file://$PROJECT_DIR$/pom.xml">
317
+      <provider selected="true" editor-type-id="text-editor">
318
+        <state relative-caret-position="345">
319
+          <caret line="23" column="17" selection-start-line="23" selection-start-column="17" selection-end-line="23" selection-end-column="17" />
320
+        </state>
321
+      </provider>
322
+    </entry>
323
+    <entry file="file://$PROJECT_DIR$/src/main/java/Account.java">
324
+      <provider selected="true" editor-type-id="text-editor">
325
+        <state relative-caret-position="210">
326
+          <caret line="14" lean-forward="true" selection-start-line="14" selection-end-line="14" />
327
+          <folding>
328
+            <element signature="imports" expanded="true" />
329
+            <element signature="e#716#717#0" expanded="true" />
330
+            <element signature="e#756#757#0" expanded="true" />
331
+            <element signature="e#1067#1068#0" expanded="true" />
332
+            <element signature="e#1107#1108#0" expanded="true" />
333
+          </folding>
334
+        </state>
335
+      </provider>
336
+    </entry>
337
+    <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
338
+      <provider selected="true" editor-type-id="text-editor">
339
+        <state relative-caret-position="804">
340
+          <caret line="105" column="36" selection-start-line="105" selection-start-column="36" selection-end-line="105" selection-end-column="36" />
325 341
           <folding>
326 342
             <element signature="imports" expanded="true" />
327 343
           </folding>
@@ -331,6 +347,66 @@
331 347
   </component>
332 348
   <component name="masterDetails">
333 349
     <states>
350
+      <state key="ArtifactsStructureConfigurable.UI">
351
+        <settings>
352
+          <artifact-editor />
353
+          <splitter-proportions>
354
+            <option name="proportions">
355
+              <list>
356
+                <option value="0.2" />
357
+              </list>
358
+            </option>
359
+          </splitter-proportions>
360
+        </settings>
361
+      </state>
362
+      <state key="FacetStructureConfigurable.UI">
363
+        <settings>
364
+          <last-edited>No facets are configured</last-edited>
365
+          <splitter-proportions>
366
+            <option name="proportions">
367
+              <list>
368
+                <option value="0.2" />
369
+              </list>
370
+            </option>
371
+          </splitter-proportions>
372
+        </settings>
373
+      </state>
374
+      <state key="GlobalLibrariesConfigurable.UI">
375
+        <settings>
376
+          <splitter-proportions>
377
+            <option name="proportions">
378
+              <list>
379
+                <option value="0.2" />
380
+              </list>
381
+            </option>
382
+          </splitter-proportions>
383
+        </settings>
384
+      </state>
385
+      <state key="JdkListConfigurable.UI">
386
+        <settings>
387
+          <last-edited>1.8</last-edited>
388
+          <splitter-proportions>
389
+            <option name="proportions">
390
+              <list>
391
+                <option value="0.2" />
392
+              </list>
393
+            </option>
394
+          </splitter-proportions>
395
+        </settings>
396
+      </state>
397
+      <state key="ModuleStructureConfigurable.UI">
398
+        <settings>
399
+          <last-edited>ORM-Lab</last-edited>
400
+          <splitter-proportions>
401
+            <option name="proportions">
402
+              <list>
403
+                <option value="0.2" />
404
+                <option value="0.6" />
405
+              </list>
406
+            </option>
407
+          </splitter-proportions>
408
+        </settings>
409
+      </state>
334 410
       <state key="ProjectJDKs.UI">
335 411
         <settings>
336 412
           <last-edited>1.8</last-edited>
@@ -343,6 +419,18 @@
343 419
           </splitter-proportions>
344 420
         </settings>
345 421
       </state>
422
+      <state key="ProjectLibrariesConfigurable.UI">
423
+        <settings>
424
+          <last-edited>Maven: com.j256.ormlite:ormlite-core:4.48</last-edited>
425
+          <splitter-proportions>
426
+            <option name="proportions">
427
+              <list>
428
+                <option value="0.2" />
429
+              </list>
430
+            </option>
431
+          </splitter-proportions>
432
+        </settings>
433
+      </state>
346 434
     </states>
347 435
   </component>
348 436
 </project>

+ 58
- 58
src/main/java/AccountApp.java Bestand weergeven

@@ -4,8 +4,6 @@ import com.j256.ormlite.jdbc.JdbcConnectionSource;
4 4
 import com.j256.ormlite.support.ConnectionSource;
5 5
 
6 6
 import java.sql.SQLException;
7
-import java.util.Arrays;
8
-import java.util.List;
9 7
 import java.util.Scanner;
10 8
 
11 9
 public class AccountApp {
@@ -43,80 +41,82 @@ public class AccountApp {
43 41
      * Read and write some example data.
44 42
      */
45 43
     private void processData() throws Exception {
46
-        // create an instance of Account
44
+        Boolean flag = true;
45
+       while(flag) {
46
+           System.out.println("Select C, R, U, D, or exit");
47
+           Scanner scanner = new Scanner(System.in);
48
+           String option = scanner.next();
49
+           if(option.equals("exit"))
50
+               flag =false;
51
+           else
52
+               selectOption(option);
53
+       }
54
+    }
55
+    public void selectOption(String input) throws Exception{
56
+            if(input.equals("C"))
57
+            System.out.println(create());
58
+            else if(input.equals("R"))
59
+            System.out.println(read());
60
+            else if(input.equals("U"))
61
+            System.out.println(update());
62
+            else if(input.equals("D"))
63
+            System.out.println(delete());
64
+            else
65
+                System.out.println("Incorrect command");
66
+        }
67
+
68
+
69
+    public String create() throws SQLException {
47 70
         Account account = new Account();
71
+        account.setName(addName());
72
+        account.setPassword(addPassword());
73
+        accountDao.create(account);
74
+        accountDao.update(account);
75
+        return "New account is #" + account.getId();
76
+    }
77
+
78
+    public String addName(){
48 79
         System.out.println("Enter account name");
49 80
         Scanner scan = new Scanner(System.in);
50
-        String name = scan.nextLine();
51
-        account.setName(name);
81
+        return scan.nextLine();
82
+    }
52 83
 
84
+    public String addPassword(){
53 85
         System.out.println("Enter password");
54 86
         Scanner scan2 = new Scanner(System.in);
55
-        String password = scan2.nextLine();
56
-        account.setPassword(password);
57
-
58
-        // persist the account object to the database
59
-        // update the database after changing the object
60
-        System.out.println(create(account));
87
+        return scan2.nextLine();
88
+    }
61 89
 
90
+    public String read() throws SQLException{
91
+        Account account = getAccount();
92
+        int id = account.getId();
93
+        String name = account.getName();
94
+        String password = account.getPassword();
95
+        System.out.println("| ID |   Name    |   Password   |");
96
+        return "  "+id + "  " + name +"   " + password;
97
+    }
98
+    public Account getAccount() throws SQLException {
62 99
         System.out.println("Enter ID");
63 100
         Scanner scan4 = new Scanner(System.in);
64 101
         int x = scan4.nextInt();
65
-        System.out.println(findById(x));
66
-
67
-        System.out.println("Enter ID and Name");
68
-        Scanner scan5 = new Scanner(System.in);
69
-        String j = scan5.nextLine();
70
-
71
-        String newRow = j.replaceAll("\n", "");
72
-        List<String> items = Arrays.asList(newRow.split("\\s*,\\s*"));
73
-        long y = Long.parseLong(items.get(0));
74
-        String updatedName = items.get(1);
75
-        System.out.println(updateName(y, updatedName));
76
-
77
-
78
-
79
-        // delete the account
80
-        System.out.println("Enter ID");
81
-        Scanner scan3 = new Scanner(System.in);
82
-        int id = scan2.nextInt();
83
-        accountDao.deleteById(id);
84
-    }
85
-    public int create(Account account) throws SQLException {
86
-        accountDao.create(account);
87
-        accountDao.update(account);
88
-        return (int) account.getId();
102
+        return accountDao.queryForId(x);
89 103
     }
90 104
 
91
-    /**
92
-     * Find the user in the database with the given id
93
-     * @param id id of the user
94
-     * @return The user associated with that id
95
-     * @throws SQLException
96
-     */
97
-    public Account findById(long id) throws SQLException {
98
-        return accountDao.queryForId((int) id);
99
-    }
100
-
101
-    /**
102
-     * Given a user id, find the user, and update the user name.
103
-     * @param id id of the user
104
-     * @param newName the user new name
105
-     * @throws SQLException
106
-     */
107
-    public String updateName(long id, String newName) throws SQLException {
108
-        Account temp = findById(id);
109
-        temp.setName(newName);
105
+    public String update() throws SQLException {
106
+        Account temp = getAccount();
107
+        temp.setName(addName());
110 108
         accountDao.update(temp);
111 109
         return "Account Updated";
112 110
     }
113 111
 
114
-    public void deleteById(long id) throws SQLException {
115
-        accountDao.deleteById((int) id);
112
+    public String delete() throws SQLException {
113
+        System.out.println("Enter ID");
114
+        Scanner scan3 = new Scanner(System.in);
115
+        int id = scan3.nextInt();
116
+        accountDao.deleteById(id);
117
+        return "Account deleted";
116 118
     }
117 119
 
118
-
119
-
120 120
     /**
121 121
      * Setup our  DAOs
122 122
      */

BIN
target/classes/AccountApp.class Bestand weergeven