瀏覽代碼

lab complete maybe

Jared Norris 6 年之前
父節點
當前提交
e7d6ceb9b4
共有 7 個文件被更改,包括 323 次插入32 次删除
  1. 115
    31
      .idea/workspace.xml
  2. 2
    0
      idkwhattowritehere.iml
  3. 25
    1
      pom.xml
  4. 65
    0
      src/main/java/pack/Account.java
  5. 116
    0
      src/main/java/pack/AccountApp.java
  6. 二進制
      target/classes/pack/Account.class
  7. 二進制
      target/classes/pack/AccountApp.class

+ 115
- 31
.idea/workspace.xml 查看文件

@@ -1,7 +1,10 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4
-    <list default="true" id="b025ecbd-8308-4b9f-b63f-ce99454d436f" name="Default" comment="" />
4
+    <list default="true" id="b025ecbd-8308-4b9f-b63f-ce99454d436f" name="Default" comment="">
5
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6
+      <change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
7
+    </list>
5 8
     <ignored path="$PROJECT_DIR$/out/" />
6 9
     <ignored path="$PROJECT_DIR$/target/" />
7 10
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -12,8 +15,8 @@
12 15
     <option name="LAST_RESOLUTION" value="IGNORE" />
13 16
   </component>
14 17
   <component name="FileEditorManager">
15
-    <leaf>
16
-      <file leaf-file-name="README.md" pinned="false" current-in-tab="true">
18
+    <leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
19
+      <file leaf-file-name="README.md" pinned="false" current-in-tab="false">
17 20
         <entry file="file://$PROJECT_DIR$/README.md">
18 21
           <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
19 22
             <state split_layout="SPLIT">
@@ -23,6 +26,24 @@
23 26
           </provider>
24 27
         </entry>
25 28
       </file>
29
+      <file leaf-file-name="AccountApp.java" pinned="false" current-in-tab="true">
30
+        <entry file="file://$PROJECT_DIR$/src/main/java/pack/AccountApp.java">
31
+          <provider selected="true" editor-type-id="text-editor">
32
+            <state relative-caret-position="45">
33
+              <caret line="7" column="13" selection-start-line="7" selection-start-column="13" selection-end-line="7" selection-end-column="13" />
34
+            </state>
35
+          </provider>
36
+        </entry>
37
+      </file>
38
+      <file leaf-file-name="Account.java" pinned="false" current-in-tab="false">
39
+        <entry file="file://$PROJECT_DIR$/src/main/java/pack/Account.java">
40
+          <provider selected="true" editor-type-id="text-editor">
41
+            <state relative-caret-position="45">
42
+              <caret line="4" column="13" selection-start-line="4" selection-start-column="13" selection-end-line="4" selection-end-column="13" />
43
+            </state>
44
+          </provider>
45
+        </entry>
46
+      </file>
26 47
     </leaf>
27 48
   </component>
28 49
   <component name="Git.Settings">
@@ -41,12 +62,20 @@
41 62
     <detection-done>true</detection-done>
42 63
     <sorting>DEFINITION_ORDER</sorting>
43 64
   </component>
65
+  <component name="MavenImportPreferences">
66
+    <option name="importingSettings">
67
+      <MavenImportingSettings>
68
+        <option name="importAutomatically" value="true" />
69
+      </MavenImportingSettings>
70
+    </option>
71
+  </component>
44 72
   <component name="NodePackageJsonFileManager">
45 73
     <packageJsonPaths />
46 74
   </component>
47
-  <component name="ProjectFrameBounds" extendedState="6">
48
-    <option name="width" value="1920" />
49
-    <option name="height" value="1080" />
75
+  <component name="ProjectFrameBounds">
76
+    <option name="y" value="23" />
77
+    <option name="width" value="1280" />
78
+    <option name="height" value="709" />
50 79
   </component>
51 80
   <component name="ProjectView">
52 81
     <navigator proportions="" version="1">
@@ -54,8 +83,6 @@
54 83
     </navigator>
55 84
     <panes>
56 85
       <pane id="PackagesPane" />
57
-      <pane id="Scope" />
58
-      <pane id="AndroidView" />
59 86
       <pane id="ProjectPane">
60 87
         <subPane>
61 88
           <expand>
@@ -74,15 +101,33 @@
74 101
               <item name="src" type="462c0819:PsiDirectoryNode" />
75 102
               <item name="main" type="462c0819:PsiDirectoryNode" />
76 103
             </path>
104
+            <path>
105
+              <item name="test" type="b2602c69:ProjectViewProjectNode" />
106
+              <item name="ZCW-ORM-SimpleAccount" type="462c0819:PsiDirectoryNode" />
107
+              <item name="src" type="462c0819:PsiDirectoryNode" />
108
+              <item name="main" type="462c0819:PsiDirectoryNode" />
109
+              <item name="java" type="462c0819:PsiDirectoryNode" />
110
+            </path>
111
+            <path>
112
+              <item name="test" type="b2602c69:ProjectViewProjectNode" />
113
+              <item name="ZCW-ORM-SimpleAccount" type="462c0819:PsiDirectoryNode" />
114
+              <item name="src" type="462c0819:PsiDirectoryNode" />
115
+              <item name="main" type="462c0819:PsiDirectoryNode" />
116
+              <item name="java" type="462c0819:PsiDirectoryNode" />
117
+              <item name="pack" type="462c0819:PsiDirectoryNode" />
118
+            </path>
77 119
           </expand>
78 120
           <select />
79 121
         </subPane>
80 122
       </pane>
123
+      <pane id="AndroidView" />
124
+      <pane id="Scope" />
81 125
     </panes>
82 126
   </component>
83 127
   <component name="PropertiesComponent">
84 128
     <property name="WebServerToolWindowFactoryState" value="false" />
85 129
     <property name="aspect.path.notification.shown" value="true" />
130
+    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
86 131
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
87 132
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
88 133
     <property name="project.structure.last.edited" value="Modules" />
@@ -103,6 +148,17 @@
103 148
     </option>
104 149
   </component>
105 150
   <component name="RunManager">
151
+    <configuration name="AccountApp" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
152
+      <option name="MAIN_CLASS_NAME" value="pack.AccountApp" />
153
+      <module name="test" />
154
+      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
155
+      <extension name="coverage">
156
+        <pattern>
157
+          <option name="PATTERN" value="pack.*" />
158
+          <option name="ENABLED" value="true" />
159
+        </pattern>
160
+      </extension>
161
+    </configuration>
106 162
     <configuration default="true" type="Application" factoryName="Application">
107 163
       <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
108 164
     </configuration>
@@ -144,6 +200,11 @@
144 200
       <properties />
145 201
       <listeners />
146 202
     </configuration>
203
+    <recent_temporary>
204
+      <list>
205
+        <item itemvalue="Application.AccountApp" />
206
+      </list>
207
+    </recent_temporary>
147 208
   </component>
148 209
   <component name="SvnConfiguration">
149 210
     <configuration />
@@ -156,44 +217,45 @@
156 217
       <option name="presentableId" value="Default" />
157 218
       <updated>1528901053138</updated>
158 219
       <workItem from="1528901058054" duration="196000" />
220
+      <workItem from="1528917376547" duration="58000" />
159 221
     </task>
160 222
     <servers />
161 223
   </component>
162 224
   <component name="TimeTrackingManager">
163
-    <option name="totallyTimeSpent" value="196000" />
225
+    <option name="totallyTimeSpent" value="254000" />
164 226
   </component>
165 227
   <component name="ToolWindowManager">
166 228
     <frame x="0" y="23" width="1280" height="709" extended-state="6" />
167
-    <editor active="true" />
168 229
     <layout>
169
-      <window_info anchor="right" id="Palette" />
230
+      <window_info anchor="right" id="Palette" order="3" />
170 231
       <window_info anchor="bottom" id="TODO" order="6" />
171
-      <window_info anchor="right" id="Palette&#9;" />
172
-      <window_info id="Image Layers" />
173
-      <window_info anchor="right" id="Capture Analysis" />
174
-      <window_info anchor="bottom" id="Event Log" side_tool="true" />
175
-      <window_info anchor="right" id="Maven Projects" />
176
-      <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
177
-      <window_info anchor="bottom" id="Run" order="2" />
178
-      <window_info anchor="bottom" id="Version Control" />
179
-      <window_info anchor="bottom" id="Terminal" />
180
-      <window_info id="Capture Tool" />
181
-      <window_info id="Designer" />
182
-      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24959612" />
183
-      <window_info anchor="right" id="Database" />
184
-      <window_info id="Learn" />
232
+      <window_info anchor="bottom" id="Messages" weight="0.32843137" />
233
+      <window_info anchor="right" id="Palette&#9;" order="3" />
234
+      <window_info id="Image Layers" order="2" />
235
+      <window_info anchor="right" id="Capture Analysis" order="3" />
236
+      <window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
237
+      <window_info anchor="right" id="Maven Projects" order="3" />
238
+      <window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
239
+      <window_info anchor="bottom" id="Run" order="2" weight="0.32843137" />
240
+      <window_info anchor="bottom" id="Version Control" order="7" />
241
+      <window_info anchor="bottom" id="Terminal" order="7" />
242
+      <window_info id="Capture Tool" order="2" />
243
+      <window_info id="Designer" order="2" />
244
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.2536349" />
245
+      <window_info anchor="right" id="Database" order="3" />
246
+      <window_info id="Learn" order="2" />
185 247
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
186 248
       <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
187
-      <window_info id="UI Designer" />
188
-      <window_info anchor="right" id="Theme Preview" />
249
+      <window_info id="UI Designer" order="2" />
250
+      <window_info anchor="right" id="Theme Preview" order="3" />
189 251
       <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
190
-      <window_info id="Favorites" side_tool="true" />
191
-      <window_info anchor="bottom" id="Find" order="1" />
192
-      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
193
-      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
252
+      <window_info id="Favorites" order="2" side_tool="true" />
194 253
       <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
254
+      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
255
+      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
195 256
       <window_info anchor="bottom" id="Message" order="0" />
196 257
       <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
258
+      <window_info anchor="bottom" id="Find" order="1" />
197 259
     </layout>
198 260
   </component>
199 261
   <component name="TypeScriptGeneratedFilesManager">
@@ -203,6 +265,14 @@
203 265
     <option name="myLimit" value="2678400000" />
204 266
   </component>
205 267
   <component name="editorHistoryManager">
268
+    <entry file="file://$PROJECT_DIR$/README.md">
269
+      <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
270
+        <state split_layout="SPLIT">
271
+          <first_editor />
272
+          <second_editor />
273
+        </state>
274
+      </provider>
275
+    </entry>
206 276
     <entry file="file://$PROJECT_DIR$/test.iml">
207 277
       <provider selected="true" editor-type-id="text-editor" />
208 278
     </entry>
@@ -221,6 +291,20 @@
221 291
         </state>
222 292
       </provider>
223 293
     </entry>
294
+    <entry file="file://$PROJECT_DIR$/src/main/java/pack/Account.java">
295
+      <provider selected="true" editor-type-id="text-editor">
296
+        <state relative-caret-position="45">
297
+          <caret line="4" column="13" selection-start-line="4" selection-start-column="13" selection-end-line="4" selection-end-column="13" />
298
+        </state>
299
+      </provider>
300
+    </entry>
301
+    <entry file="file://$PROJECT_DIR$/src/main/java/pack/AccountApp.java">
302
+      <provider selected="true" editor-type-id="text-editor">
303
+        <state relative-caret-position="45">
304
+          <caret line="7" column="13" selection-start-line="7" selection-start-column="13" selection-end-line="7" selection-end-column="13" />
305
+        </state>
306
+      </provider>
307
+    </entry>
224 308
   </component>
225 309
   <component name="masterDetails">
226 310
     <states>

+ 2
- 0
idkwhattowritehere.iml 查看文件

@@ -0,0 +1,2 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module type="JAVA_MODULE" version="4" />

+ 25
- 1
pom.xml 查看文件

@@ -4,8 +4,32 @@
4 4
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 5
     <modelVersion>4.0.0</modelVersion>
6 6
 
7
-    <groupId>com.google.guava</groupId>
7
+    <groupId>test</groupId>
8 8
     <artifactId>test</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+    <dependencies>
12
+        <!-- https://mvnrepository.com/artifact/com.j256.ormlite/ormlite-core -->
13
+        <dependency>
14
+            <groupId>com.j256.ormlite</groupId>
15
+            <artifactId>ormlite-core</artifactId>
16
+            <version>4.48</version>
17
+        </dependency>
18
+
19
+        <!-- https://mvnrepository.com/artifact/com.j256.ormlite/ormlite-jdbc -->
20
+        <dependency>
21
+            <groupId>com.j256.ormlite</groupId>
22
+            <artifactId>ormlite-jdbc</artifactId>
23
+            <version>4.48</version>
24
+        </dependency>
25
+
26
+        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
27
+        <dependency>
28
+            <groupId>mysql</groupId>
29
+            <artifactId>mysql-connector-java</artifactId>
30
+            <version>5.1.6</version>
31
+        </dependency>
32
+    </dependencies>
33
+
34
+
11 35
 </project>

+ 65
- 0
src/main/java/pack/Account.java 查看文件

@@ -0,0 +1,65 @@
1
+package pack;
2
+import com.j256.ormlite.field.DatabaseField;
3
+import com.j256.ormlite.table.DatabaseTable;
4
+
5
+public class Account {
6
+
7
+    public static final String NAME_FIELD_NAME = "name";
8
+    public static final String PASSWORD_FIELD_NAME = "password";
9
+
10
+    @DatabaseField(columnName = "id", generatedId = true)
11
+    private int id;
12
+
13
+    @DatabaseField(columnName = "name", canBeNull = false)
14
+    private String name;
15
+
16
+    @DatabaseField(columnName = "password")
17
+    private String password;
18
+
19
+    Account() {
20
+        // all persisted classes must define a no-arg constructor with at least package visibility
21
+    }
22
+
23
+    public Account(String name) {
24
+        this.name = name;
25
+    }
26
+
27
+    public Account(String name, String password) {
28
+        this.name = name;
29
+        this.password = password;
30
+    }
31
+
32
+    public int getId() {
33
+        return id;
34
+    }
35
+
36
+    public String getName() {
37
+        return name;
38
+    }
39
+
40
+    public void setName(String name) {
41
+        this.name = name;
42
+    }
43
+
44
+    public String getPassword() {
45
+        return password;
46
+    }
47
+
48
+    public void setPassword(String password) {
49
+        this.password = password;
50
+    }
51
+
52
+    @Override
53
+    public int hashCode() {
54
+        return name.hashCode();
55
+    }
56
+
57
+    @Override
58
+    public boolean equals(Object other) {
59
+        if (other == null || other.getClass() != getClass()) {
60
+            return false;
61
+        }
62
+        return name.equals(((Account) other).name);
63
+    }
64
+
65
+}

+ 116
- 0
src/main/java/pack/AccountApp.java 查看文件

@@ -0,0 +1,116 @@
1
+package pack;
2
+import com.j256.ormlite.dao.Dao;
3
+import com.j256.ormlite.dao.DaoManager;
4
+import com.j256.ormlite.jdbc.JdbcConnectionSource;
5
+import com.j256.ormlite.support.ConnectionSource;
6
+import java.util.*;
7
+
8
+public class AccountApp {
9
+    // we are using a MySQl database
10
+    private final static String DATABASE_URL = "jdbc:mysql://localhost:3306/orm_lab?useUnicode=true";
11
+    Account account;
12
+    private int id;
13
+    private String name, pw;
14
+    private Scanner kb;
15
+    private Dao<Account, Integer> accountDao;
16
+
17
+    public static void main(String[] args) throws Exception {
18
+        // turn our static method into an instance of Main
19
+        new AccountApp().doMain(args);
20
+    }
21
+
22
+    private void doMain(String[] args) throws Exception {
23
+        ConnectionSource connectionSource = null;
24
+        try {
25
+            // create our data-source for the database
26
+            connectionSource = new JdbcConnectionSource(DATABASE_URL, "root", "Crapshoes1337");
27
+            // setup our  DAOs
28
+            setupDao(connectionSource);
29
+            // read, write and delete some data
30
+            processData();
31
+
32
+            System.out.println("\n\nIt seems to have worked\n\n");
33
+        } finally {
34
+            // destroy the data source which should close underlying connections
35
+            if (connectionSource != null) {
36
+                connectionSource.close();
37
+            }
38
+        }
39
+    }
40
+
41
+    private void processData() throws Exception {
42
+        kb = new Scanner(System.in);
43
+        int input;
44
+        while(true) {
45
+            mainMenu();
46
+            input = kb.nextInt();
47
+            if (input == 0) break;
48
+            switch (input) {
49
+                case 1: create(); break;
50
+                case 2: read(); break;
51
+                case 3: update(); break;
52
+                case 4: delete(); break;
53
+                default:
54
+                    System.out.println("Not a valid command");
55
+            }
56
+        }
57
+    }
58
+
59
+    public void mainMenu() {
60
+        System.out.println("Main menu! options:");
61
+        System.out.println("0.) exit.");
62
+        System.out.println("1.) Create a new user / password");
63
+        System.out.println("2.) Read a user by their ID");
64
+        System.out.println("3.) Update a user's info by their ID");
65
+        System.out.println("4.) Delete a user by their ID");
66
+    }
67
+
68
+    public void create() throws Exception {
69
+        System.out.println("Enter a name for new user");
70
+        name = kb.next();
71
+        account = new Account(name);
72
+        accountDao.create(account);
73
+        id = account.getId();
74
+        System.out.println("your account id is " + id);
75
+        System.out.println("Please type a password");
76
+        pw = kb.next();
77
+        account.setPassword(pw);
78
+        accountDao.update(account);
79
+    }
80
+
81
+    public void read() throws Exception {
82
+        System.out.println("Enter an ID to read from database");
83
+        id = kb.nextInt();
84
+        System.out.println("User : " + accountDao.queryForId(id).getName() + " found at ID# " + id);
85
+    }
86
+
87
+    public void update() throws Exception {
88
+        System.out.println("Enter an ID to change password");
89
+        id = kb.nextInt();
90
+        Account a = accountDao.queryForId(id);
91
+        a.setPassword(setNewPass(a));
92
+        accountDao.update(a);
93
+    }
94
+
95
+    public String setNewPass(Account a) {
96
+        System.out.println(a.getName() + " Please enter a new password.");
97
+        return kb.next();
98
+    }
99
+
100
+    public void delete() throws Exception {
101
+        System.out.println("enter an ID to delete from user database");
102
+        id = kb.nextInt();
103
+        accountDao.deleteById(id);
104
+        System.out.println("Successfully deleted user @ id: " + id);
105
+    }
106
+
107
+    /**
108
+     * Setup our  DAOs
109
+     */
110
+    private void setupDao(ConnectionSource connectionSource) throws Exception {
111
+
112
+        accountDao = DaoManager.createDao(connectionSource, Account.class);
113
+
114
+    }
115
+
116
+}

二進制
target/classes/pack/Account.class 查看文件


二進制
target/classes/pack/AccountApp.class 查看文件