ソースを参照

created username

Tommy Rogers 6 年 前
コミット
8d44d1af6d
共有4 個のファイルを変更した185 個の追加20 個の削除を含む
  1. 57
    20
      .idea/workspace.xml
  2. 128
    0
      src/main/java/AccountApp.java
  3. バイナリ
      target/classes/Account.class
  4. バイナリ
      target/classes/AccountApp.class

+ 57
- 20
.idea/workspace.xml ファイルの表示

@@ -2,7 +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/Account.java" afterDir="false" />
5
+      <change afterPath="$PROJECT_DIR$/src/main/java/AccountApp.java" afterDir="false" />
6
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6 7
     </list>
7 8
     <ignored path="$PROJECT_DIR$/out/" />
8 9
     <ignored path="$PROJECT_DIR$/target/" />
@@ -13,22 +14,25 @@
13 14
     <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
14 15
     <option name="LAST_RESOLUTION" value="IGNORE" />
15 16
   </component>
17
+  <component name="FavoritesManager">
18
+    <favorites_list name="ORM-Lab" />
19
+  </component>
16 20
   <component name="FileEditorManager">
17 21
     <leaf>
18 22
       <file leaf-file-name="pom.xml" pinned="false" current-in-tab="false">
19 23
         <entry file="file://$PROJECT_DIR$/pom.xml">
20 24
           <provider selected="true" editor-type-id="text-editor">
21
-            <state relative-caret-position="120">
22
-              <caret line="8" column="35" lean-forward="true" selection-start-line="8" selection-start-column="35" selection-end-line="8" selection-end-column="35" />
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" />
23 27
             </state>
24 28
           </provider>
25 29
         </entry>
26 30
       </file>
27
-      <file leaf-file-name="Account.java" pinned="false" current-in-tab="true">
31
+      <file leaf-file-name="Account.java" pinned="false" current-in-tab="false">
28 32
         <entry file="file://$PROJECT_DIR$/src/main/java/Account.java">
29 33
           <provider selected="true" editor-type-id="text-editor">
30
-            <state relative-caret-position="184">
31
-              <caret line="55" lean-forward="true" selection-start-line="55" selection-end-line="55" />
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" />
32 36
               <folding>
33 37
                 <element signature="imports" expanded="true" />
34 38
                 <element signature="e#756#757#0" expanded="true" />
@@ -50,6 +54,18 @@
50 54
           </provider>
51 55
         </entry>
52 56
       </file>
57
+      <file leaf-file-name="AccountApp.java" pinned="false" current-in-tab="true">
58
+        <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
59
+          <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" />
62
+              <folding>
63
+                <element signature="imports" expanded="true" />
64
+              </folding>
65
+            </state>
66
+          </provider>
67
+        </entry>
68
+      </file>
53 69
     </leaf>
54 70
   </component>
55 71
   <component name="FileTemplateManagerImpl">
@@ -67,6 +83,7 @@
67 83
       <list>
68 84
         <option value="$PROJECT_DIR$/pom.xml" />
69 85
         <option value="$PROJECT_DIR$/src/main/java/Account.java" />
86
+        <option value="$PROJECT_DIR$/src/main/java/AccountApp.java" />
70 87
       </list>
71 88
     </option>
72 89
   </component>
@@ -87,8 +104,8 @@
87 104
     <packageJsonPaths />
88 105
   </component>
89 106
   <component name="ProjectFrameBounds">
90
-    <option name="x" value="199" />
91
-    <option name="y" value="-1023" />
107
+    <option name="x" value="128" />
108
+    <option name="y" value="-1057" />
92 109
     <option name="width" value="1165" />
93 110
     <option name="height" value="709" />
94 111
   </component>
@@ -161,6 +178,11 @@
161 178
     </option>
162 179
   </component>
163 180
   <component name="RunManager">
181
+    <configuration name="AccountApp" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
182
+      <option name="MAIN_CLASS_NAME" value="AccountApp" />
183
+      <module name="ORM-Lab" />
184
+      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
185
+    </configuration>
164 186
     <configuration default="true" type="Application" factoryName="Application">
165 187
       <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
166 188
     </configuration>
@@ -202,6 +224,11 @@
202 224
       <properties />
203 225
       <listeners />
204 226
     </configuration>
227
+    <recent_temporary>
228
+      <list>
229
+        <item itemvalue="Application.AccountApp" />
230
+      </list>
231
+    </recent_temporary>
205 232
   </component>
206 233
   <component name="SvnConfiguration">
207 234
     <configuration />
@@ -213,38 +240,38 @@
213 240
       <option name="number" value="Default" />
214 241
       <option name="presentableId" value="Default" />
215 242
       <updated>1529876073719</updated>
216
-      <workItem from="1529876077870" duration="506000" />
243
+      <workItem from="1529876077870" duration="11993000" />
217 244
     </task>
218 245
     <servers />
219 246
   </component>
220 247
   <component name="TimeTrackingManager">
221
-    <option name="totallyTimeSpent" value="506000" />
248
+    <option name="totallyTimeSpent" value="11993000" />
222 249
   </component>
223 250
   <component name="ToolWindowManager">
224
-    <frame x="199" y="-1023" width="1165" height="709" extended-state="0" />
225
-    <editor active="true" />
251
+    <frame x="128" y="-1057" width="1165" height="709" extended-state="0" />
226 252
     <layout>
227 253
       <window_info anchor="right" id="Palette" />
228 254
       <window_info anchor="bottom" id="TODO" order="6" />
255
+      <window_info anchor="bottom" id="Messages" weight="0.3293718" />
229 256
       <window_info anchor="right" id="Palette&#9;" />
230 257
       <window_info id="Image Layers" />
231 258
       <window_info anchor="right" id="Capture Analysis" />
232 259
       <window_info anchor="bottom" id="Event Log" side_tool="true" />
233 260
       <window_info anchor="right" id="Maven Projects" />
234 261
       <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
235
-      <window_info anchor="bottom" id="Run" order="2" />
262
+      <window_info anchor="bottom" id="Run" order="2" weight="0.3293718" />
236 263
       <window_info anchor="bottom" id="Version Control" />
237
-      <window_info anchor="bottom" id="Terminal" visible="true" weight="0.3293718" />
264
+      <window_info active="true" anchor="bottom" id="Terminal" visible="true" weight="0.3293718" />
238 265
       <window_info id="Capture Tool" />
239 266
       <window_info id="Designer" />
240
-      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24933214" />
267
+      <window_info content_ui="combo" id="Project" order="0" sideWeight="0.49873418" visible="true" weight="0.24933214" />
241 268
       <window_info anchor="right" id="Database" />
242 269
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
243 270
       <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
244 271
       <window_info id="UI Designer" />
245 272
       <window_info anchor="right" id="Theme Preview" />
246 273
       <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
247
-      <window_info id="Favorites" side_tool="true" />
274
+      <window_info id="Favorites" sideWeight="0.5012658" side_tool="true" weight="0.24933214" />
248 275
       <window_info anchor="bottom" id="Find" order="1" />
249 276
       <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
250 277
       <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@@ -262,15 +289,15 @@
262 289
   <component name="editorHistoryManager">
263 290
     <entry file="file://$PROJECT_DIR$/pom.xml">
264 291
       <provider selected="true" editor-type-id="text-editor">
265
-        <state relative-caret-position="120">
266
-          <caret line="8" column="35" lean-forward="true" selection-start-line="8" selection-start-column="35" selection-end-line="8" selection-end-column="35" />
292
+        <state relative-caret-position="130">
293
+          <caret line="23" column="17" lean-forward="true" selection-start-line="23" selection-start-column="17" selection-end-line="23" selection-end-column="17" />
267 294
         </state>
268 295
       </provider>
269 296
     </entry>
270 297
     <entry file="file://$PROJECT_DIR$/src/main/java/Account.java">
271 298
       <provider selected="true" editor-type-id="text-editor">
272
-        <state relative-caret-position="184">
273
-          <caret line="55" lean-forward="true" selection-start-line="55" selection-end-line="55" />
299
+        <state relative-caret-position="112">
300
+          <caret line="18" column="8" lean-forward="true" selection-start-line="18" selection-start-column="8" selection-end-line="29" selection-end-column="9" />
274 301
           <folding>
275 302
             <element signature="imports" expanded="true" />
276 303
             <element signature="e#756#757#0" expanded="true" />
@@ -291,6 +318,16 @@
291 318
         </state>
292 319
       </provider>
293 320
     </entry>
321
+    <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
322
+      <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" />
325
+          <folding>
326
+            <element signature="imports" expanded="true" />
327
+          </folding>
328
+        </state>
329
+      </provider>
330
+    </entry>
294 331
   </component>
295 332
   <component name="masterDetails">
296 333
     <states>

+ 128
- 0
src/main/java/AccountApp.java ファイルの表示

@@ -0,0 +1,128 @@
1
+import com.j256.ormlite.dao.Dao;
2
+import com.j256.ormlite.dao.DaoManager;
3
+import com.j256.ormlite.jdbc.JdbcConnectionSource;
4
+import com.j256.ormlite.support.ConnectionSource;
5
+
6
+import java.sql.SQLException;
7
+import java.util.Arrays;
8
+import java.util.List;
9
+import java.util.Scanner;
10
+
11
+public class AccountApp {
12
+
13
+    // we are using a MySQl database
14
+    private final static String DATABASE_URL = "jdbc:mysql://localhost:3306/orm_lab?useUnicode=true";
15
+
16
+    private Dao<Account, Integer> accountDao;
17
+
18
+    public static void main(String[] args) throws Exception {
19
+        // turn our static method into an instance of Main
20
+        new AccountApp().doMain(args);
21
+    }
22
+
23
+    private void doMain(String[] args) throws Exception {
24
+        ConnectionSource connectionSource = null;
25
+        try {
26
+            // create our data-source for the database
27
+            connectionSource = new JdbcConnectionSource(DATABASE_URL, "root", "");
28
+            // setup our  DAOs
29
+            setupDao(connectionSource);
30
+            // read, write and delete some datase
31
+            processData();
32
+
33
+            System.out.println("\n\nIt seems to have worked\n\n");
34
+        } finally {
35
+            // destroy the data source which should close underlying connections
36
+            if (connectionSource != null) {
37
+                connectionSource.close();
38
+            }
39
+        }
40
+    }
41
+
42
+    /**
43
+     * Read and write some example data.
44
+     */
45
+    private void processData() throws Exception {
46
+        // create an instance of Account
47
+        Account account = new Account();
48
+        System.out.println("Enter account name");
49
+        Scanner scan = new Scanner(System.in);
50
+        String name = scan.nextLine();
51
+        account.setName(name);
52
+
53
+        System.out.println("Enter password");
54
+        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));
61
+
62
+        System.out.println("Enter ID");
63
+        Scanner scan4 = new Scanner(System.in);
64
+        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();
89
+    }
90
+
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);
110
+        accountDao.update(temp);
111
+        return "Account Updated";
112
+    }
113
+
114
+    public void deleteById(long id) throws SQLException {
115
+        accountDao.deleteById((int) id);
116
+    }
117
+
118
+
119
+
120
+    /**
121
+     * Setup our  DAOs
122
+     */
123
+    private void setupDao(ConnectionSource connectionSource) throws Exception {
124
+
125
+        accountDao = DaoManager.createDao(connectionSource, Account.class);
126
+
127
+    }
128
+}

バイナリ
target/classes/Account.class ファイルの表示


バイナリ
target/classes/AccountApp.class ファイルの表示