瀏覽代碼

Completed the assignment

Yesoda Sanka 6 年之前
父節點
當前提交
f37a91b1c9

+ 13
- 0
JavaAccount/.idea/compiler.xml 查看文件

@@ -0,0 +1,13 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="CompilerConfiguration">
4
+    <annotationProcessing>
5
+      <profile name="Maven default annotation processors profile" enabled="true">
6
+        <sourceOutputDir name="target/generated-sources/annotations" />
7
+        <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
8
+        <outputRelativeToContentRoot value="true" />
9
+        <module name="JavaAccount" />
10
+      </profile>
11
+    </annotationProcessing>
12
+  </component>
13
+</project>

+ 14
- 0
JavaAccount/.idea/misc.xml 查看文件

@@ -0,0 +1,14 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ExternalStorageConfigurationManager" enabled="true" />
4
+  <component name="MavenProjectsManager">
5
+    <option name="originalFiles">
6
+      <list>
7
+        <option value="$PROJECT_DIR$/pom.xml" />
8
+      </list>
9
+    </option>
10
+  </component>
11
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
12
+    <output url="file://$PROJECT_DIR$/out" />
13
+  </component>
14
+</project>

+ 321
- 0
JavaAccount/.idea/workspace.xml 查看文件

@@ -0,0 +1,321 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ChangeListManager">
4
+    <list default="true" id="e64e38b0-f02f-47eb-b501-c4b668788f03" name="Default Changelist" comment="" />
5
+    <ignored path="$PROJECT_DIR$/out/" />
6
+    <ignored path="$PROJECT_DIR$/target/" />
7
+    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
8
+    <option name="SHOW_DIALOG" value="false" />
9
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
10
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
11
+    <option name="LAST_RESOLUTION" value="IGNORE" />
12
+  </component>
13
+  <component name="FUSProjectUsageTrigger">
14
+    <session id="95973368">
15
+      <usages-collector id="statistics.lifecycle.project">
16
+        <counts>
17
+          <entry key="project.open.time.5" value="1" />
18
+          <entry key="project.opened" value="1" />
19
+        </counts>
20
+      </usages-collector>
21
+      <usages-collector id="statistics.file.extensions.edit">
22
+        <counts>
23
+          <entry key="java" value="45" />
24
+          <entry key="xml" value="15" />
25
+        </counts>
26
+      </usages-collector>
27
+      <usages-collector id="statistics.file.types.edit">
28
+        <counts>
29
+          <entry key="JAVA" value="45" />
30
+          <entry key="XML" value="15" />
31
+        </counts>
32
+      </usages-collector>
33
+      <usages-collector id="statistics.file.extensions.open">
34
+        <counts>
35
+          <entry key="java" value="3" />
36
+        </counts>
37
+      </usages-collector>
38
+      <usages-collector id="statistics.file.types.open">
39
+        <counts>
40
+          <entry key="JAVA" value="3" />
41
+        </counts>
42
+      </usages-collector>
43
+    </session>
44
+  </component>
45
+  <component name="FileEditorManager">
46
+    <leaf>
47
+      <file pinned="false" current-in-tab="false">
48
+        <entry file="file://$PROJECT_DIR$/pom.xml">
49
+          <provider selected="true" editor-type-id="text-editor">
50
+            <state relative-caret-position="450">
51
+              <caret line="30" column="10" selection-start-line="30" selection-start-column="10" selection-end-line="30" selection-end-column="10" />
52
+            </state>
53
+          </provider>
54
+        </entry>
55
+      </file>
56
+      <file pinned="false" current-in-tab="true">
57
+        <entry file="file://$PROJECT_DIR$/src/main/java/Account.java">
58
+          <provider selected="true" editor-type-id="text-editor">
59
+            <state relative-caret-position="30">
60
+              <caret line="2" column="44" lean-forward="true" selection-start-line="2" selection-start-column="44" selection-end-line="2" selection-end-column="44" />
61
+              <folding>
62
+                <element signature="imports" expanded="true" />
63
+                <element signature="e#668#669#0" expanded="true" />
64
+                <element signature="e#700#701#0" expanded="true" />
65
+                <element signature="e#844#845#0" expanded="true" />
66
+                <element signature="e#869#870#0" expanded="true" />
67
+                <element signature="e#900#901#0" expanded="true" />
68
+                <element signature="e#927#928#0" expanded="true" />
69
+                <element signature="e#967#968#0" expanded="true" />
70
+                <element signature="e#999#1000#0" expanded="true" />
71
+                <element signature="e#1034#1035#0" expanded="true" />
72
+                <element signature="e#1065#1066#0" expanded="true" />
73
+                <element signature="e#1113#1114#0" expanded="true" />
74
+                <element signature="e#1153#1154#0" expanded="true" />
75
+                <element signature="e#1196#1197#0" expanded="true" />
76
+                <element signature="e#1234#1235#0" expanded="true" />
77
+              </folding>
78
+            </state>
79
+          </provider>
80
+        </entry>
81
+      </file>
82
+      <file pinned="false" current-in-tab="false">
83
+        <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
84
+          <provider selected="true" editor-type-id="text-editor">
85
+            <state relative-caret-position="360">
86
+              <caret line="24" column="47" selection-start-line="24" selection-start-column="47" selection-end-line="24" selection-end-column="47" />
87
+              <folding>
88
+                <element signature="imports" expanded="true" />
89
+              </folding>
90
+            </state>
91
+          </provider>
92
+        </entry>
93
+      </file>
94
+    </leaf>
95
+  </component>
96
+  <component name="FileTemplateManagerImpl">
97
+    <option name="RECENT_TEMPLATES">
98
+      <list>
99
+        <option value="Class" />
100
+      </list>
101
+    </option>
102
+  </component>
103
+  <component name="IdeDocumentHistory">
104
+    <option name="CHANGED_PATHS">
105
+      <list>
106
+        <option value="$PROJECT_DIR$/pom.xml" />
107
+        <option value="$PROJECT_DIR$/src/main/java/AccountApp.java" />
108
+        <option value="$PROJECT_DIR$/src/main/java/Account.java" />
109
+      </list>
110
+    </option>
111
+  </component>
112
+  <component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
113
+  <component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
114
+  <component name="JsGulpfileManager">
115
+    <detection-done>true</detection-done>
116
+    <sorting>DEFINITION_ORDER</sorting>
117
+  </component>
118
+  <component name="MavenImportPreferences">
119
+    <option name="importingSettings">
120
+      <MavenImportingSettings>
121
+        <option name="importAutomatically" value="true" />
122
+      </MavenImportingSettings>
123
+    </option>
124
+  </component>
125
+  <component name="ProjectFrameBounds">
126
+    <option name="y" value="23" />
127
+    <option name="width" value="1280" />
128
+    <option name="height" value="709" />
129
+  </component>
130
+  <component name="ProjectView">
131
+    <navigator proportions="" version="1">
132
+      <foldersAlwaysOnTop value="true" />
133
+    </navigator>
134
+    <panes>
135
+      <pane id="ProjectPane">
136
+        <subPane>
137
+          <expand>
138
+            <path>
139
+              <item name="JavaAccount" type="b2602c69:ProjectViewProjectNode" />
140
+              <item name="JavaAccount" type="462c0819:PsiDirectoryNode" />
141
+            </path>
142
+            <path>
143
+              <item name="JavaAccount" type="b2602c69:ProjectViewProjectNode" />
144
+              <item name="JavaAccount" type="462c0819:PsiDirectoryNode" />
145
+              <item name="src" type="462c0819:PsiDirectoryNode" />
146
+            </path>
147
+            <path>
148
+              <item name="JavaAccount" type="b2602c69:ProjectViewProjectNode" />
149
+              <item name="JavaAccount" type="462c0819:PsiDirectoryNode" />
150
+              <item name="src" type="462c0819:PsiDirectoryNode" />
151
+              <item name="main" type="462c0819:PsiDirectoryNode" />
152
+            </path>
153
+            <path>
154
+              <item name="JavaAccount" type="b2602c69:ProjectViewProjectNode" />
155
+              <item name="JavaAccount" type="462c0819:PsiDirectoryNode" />
156
+              <item name="src" type="462c0819:PsiDirectoryNode" />
157
+              <item name="main" type="462c0819:PsiDirectoryNode" />
158
+              <item name="java" type="462c0819:PsiDirectoryNode" />
159
+            </path>
160
+          </expand>
161
+          <select />
162
+        </subPane>
163
+      </pane>
164
+      <pane id="PackagesPane" />
165
+      <pane id="Scope" />
166
+    </panes>
167
+  </component>
168
+  <component name="PropertiesComponent">
169
+    <property name="WebServerToolWindowFactoryState" value="false" />
170
+    <property name="aspect.path.notification.shown" value="true" />
171
+    <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
172
+    <property name="nodejs_npm_path_reset_for_default_project" value="true" />
173
+    <property name="settings.editor.selected.configurable" value="vcs.Git" />
174
+  </component>
175
+  <component name="RunDashboard">
176
+    <option name="ruleStates">
177
+      <list>
178
+        <RuleState>
179
+          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
180
+        </RuleState>
181
+        <RuleState>
182
+          <option name="name" value="StatusDashboardGroupingRule" />
183
+        </RuleState>
184
+      </list>
185
+    </option>
186
+  </component>
187
+  <component name="RunManager">
188
+    <configuration name="AccountApp" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
189
+      <option name="MAIN_CLASS_NAME" value="AccountApp" />
190
+      <module name="JavaAccount" />
191
+      <method v="2">
192
+        <option name="Make" enabled="true" />
193
+      </method>
194
+    </configuration>
195
+    <recent_temporary>
196
+      <list>
197
+        <item itemvalue="Application.AccountApp" />
198
+      </list>
199
+    </recent_temporary>
200
+  </component>
201
+  <component name="SvnConfiguration">
202
+    <configuration />
203
+  </component>
204
+  <component name="TaskManager">
205
+    <task active="true" id="Default" summary="Default task">
206
+      <changelist id="e64e38b0-f02f-47eb-b501-c4b668788f03" name="Default Changelist" comment="" />
207
+      <created>1542247537764</created>
208
+      <option name="number" value="Default" />
209
+      <option name="presentableId" value="Default" />
210
+      <updated>1542247537764</updated>
211
+      <workItem from="1542247543291" duration="846000" />
212
+    </task>
213
+    <servers />
214
+  </component>
215
+  <component name="TimeTrackingManager">
216
+    <option name="totallyTimeSpent" value="846000" />
217
+  </component>
218
+  <component name="ToolWindowManager">
219
+    <frame x="0" y="23" width="1280" height="709" extended-state="0" />
220
+    <editor active="true" />
221
+    <layout>
222
+      <window_info id="Favorites" side_tool="true" />
223
+      <window_info id="Designer" />
224
+      <window_info id="UI Designer" />
225
+      <window_info id="Learn" />
226
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24959612" />
227
+      <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
228
+      <window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
229
+      <window_info anchor="bottom" id="Terminal" visible="true" weight="0.32996634" />
230
+      <window_info anchor="bottom" id="Event Log" side_tool="true" />
231
+      <window_info anchor="bottom" id="Messages" weight="0.32996634" />
232
+      <window_info anchor="bottom" id="Message" order="0" />
233
+      <window_info anchor="bottom" id="Find" order="1" />
234
+      <window_info anchor="bottom" id="Run" order="2" weight="0.32996634" />
235
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
236
+      <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
237
+      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
238
+      <window_info anchor="bottom" id="TODO" order="6" />
239
+      <window_info anchor="right" id="Palette" />
240
+      <window_info anchor="right" id="Palette&#9;" />
241
+      <window_info anchor="right" id="Maven Projects" />
242
+      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
243
+      <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
244
+      <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
245
+    </layout>
246
+  </component>
247
+  <component name="TypeScriptGeneratedFilesManager">
248
+    <option name="version" value="1" />
249
+  </component>
250
+  <component name="VcsContentAnnotationSettings">
251
+    <option name="myLimit" value="2678400000" />
252
+  </component>
253
+  <component name="editorHistoryManager">
254
+    <entry file="file://$PROJECT_DIR$/../1ZCW-ORM-SimpleAccount/ttd/src/main/java/Account.java">
255
+      <provider selected="true" editor-type-id="text-editor">
256
+        <state>
257
+          <folding>
258
+            <element signature="imports" expanded="true" />
259
+          </folding>
260
+        </state>
261
+      </provider>
262
+    </entry>
263
+    <entry file="file://$PROJECT_DIR$/pom.xml">
264
+      <provider selected="true" editor-type-id="text-editor">
265
+        <state relative-caret-position="450">
266
+          <caret line="30" column="10" selection-start-line="30" selection-start-column="10" selection-end-line="30" selection-end-column="10" />
267
+        </state>
268
+      </provider>
269
+    </entry>
270
+    <entry file="file://$PROJECT_DIR$/src/main/java/AccountApp.java">
271
+      <provider selected="true" editor-type-id="text-editor">
272
+        <state relative-caret-position="360">
273
+          <caret line="24" column="47" selection-start-line="24" selection-start-column="47" selection-end-line="24" selection-end-column="47" />
274
+          <folding>
275
+            <element signature="imports" expanded="true" />
276
+          </folding>
277
+        </state>
278
+      </provider>
279
+    </entry>
280
+    <entry file="file://$PROJECT_DIR$/src/main/java/Account.java">
281
+      <provider selected="true" editor-type-id="text-editor">
282
+        <state relative-caret-position="30">
283
+          <caret line="2" column="44" lean-forward="true" selection-start-line="2" selection-start-column="44" selection-end-line="2" selection-end-column="44" />
284
+          <folding>
285
+            <element signature="imports" expanded="true" />
286
+            <element signature="e#668#669#0" expanded="true" />
287
+            <element signature="e#700#701#0" expanded="true" />
288
+            <element signature="e#844#845#0" expanded="true" />
289
+            <element signature="e#869#870#0" expanded="true" />
290
+            <element signature="e#900#901#0" expanded="true" />
291
+            <element signature="e#927#928#0" expanded="true" />
292
+            <element signature="e#967#968#0" expanded="true" />
293
+            <element signature="e#999#1000#0" expanded="true" />
294
+            <element signature="e#1034#1035#0" expanded="true" />
295
+            <element signature="e#1065#1066#0" expanded="true" />
296
+            <element signature="e#1113#1114#0" expanded="true" />
297
+            <element signature="e#1153#1154#0" expanded="true" />
298
+            <element signature="e#1196#1197#0" expanded="true" />
299
+            <element signature="e#1234#1235#0" expanded="true" />
300
+          </folding>
301
+        </state>
302
+      </provider>
303
+    </entry>
304
+  </component>
305
+  <component name="masterDetails">
306
+    <states>
307
+      <state key="ProjectJDKs.UI">
308
+        <settings>
309
+          <last-edited>1.8</last-edited>
310
+          <splitter-proportions>
311
+            <option name="proportions">
312
+              <list>
313
+                <option value="0.2" />
314
+              </list>
315
+            </option>
316
+          </splitter-proportions>
317
+        </settings>
318
+      </state>
319
+    </states>
320
+  </component>
321
+</project>

+ 2
- 0
JavaAccount/JavaAccount.iml 查看文件

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

+ 31
- 0
JavaAccount/pom.xml 查看文件

@@ -0,0 +1,31 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0"
3
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
+    <modelVersion>4.0.0</modelVersion>
6
+
7
+    <groupId>com.zipcode.wilmington</groupId>
8
+    <artifactId>java account</artifactId>
9
+    <version>1.0-SNAPSHOT</version>
10
+   <dependencies >
11
+    <dependency>
12
+        <groupId>com.j256.ormlite</groupId>
13
+        <artifactId>ormlite-core</artifactId>
14
+        <version>4.48</version>
15
+    </dependency>
16
+
17
+    <!-- https://mvnrepository.com/artifact/com.j256.ormlite/ormlite-jdbc -->
18
+    <dependency>
19
+        <groupId>com.j256.ormlite</groupId>
20
+        <artifactId>ormlite-jdbc</artifactId>
21
+        <version>4.48</version>
22
+    </dependency>
23
+
24
+    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
25
+    <dependency>
26
+        <groupId>mysql</groupId>
27
+        <artifactId>mysql-connector-java</artifactId>
28
+        <version>8.0.12</version>
29
+    </dependency>
30
+   </dependencies>
31
+</project>

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

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

+ 65
- 0
JavaAccount/src/main/java/AccountApp.java 查看文件

@@ -0,0 +1,65 @@
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
+public class AccountApp {
7
+
8
+    // we are using a MySQl database
9
+    private final static String DATABASE_URL = "jdbc:mysql://localhost:3306/orm_lab?useUnicode=true";
10
+
11
+    private Dao<Account, Integer> accountDao;
12
+
13
+    public static void main(String[] args) throws Exception {
14
+        // turn our static method into an instance of Main
15
+        new AccountApp().doMain(args);
16
+    }
17
+
18
+    private void doMain(String[] args) throws Exception {
19
+        ConnectionSource connectionSource = null;
20
+        try {
21
+            // create our data-source for the database
22
+            connectionSource = new JdbcConnectionSource(DATABASE_URL, "root", "Fun1234@");
23
+            // setup our  DAOs
24
+            setupDao(connectionSource);
25
+            // read, write and delete some data
26
+            processData();
27
+
28
+            System.out.println("\n\nIt seems to have worked\n\n");
29
+        } finally {
30
+            // destroy the data source which should close underlying connections
31
+            if (connectionSource != null) {
32
+                connectionSource.close();
33
+            }
34
+        }
35
+    }
36
+
37
+    /**
38
+     * Read and write some example data.
39
+     */
40
+    private void processData() throws Exception {
41
+        // create an instance of Account
42
+        String name = "Jim Coakley";
43
+        Account account = new Account(name);
44
+
45
+        // persist the account object to the database
46
+        accountDao.create(account);
47
+        int id = account.getId();
48
+        System.out.println(id);
49
+        // assign a password
50
+        account.setPassword("_secret");
51
+        // update the database after changing the object
52
+        accountDao.update(account);
53
+        // delete the account
54
+        //accountDao.deleteById(id);
55
+    }
56
+
57
+    /**
58
+     * Setup our  DAOs
59
+     */
60
+    private void setupDao(ConnectionSource connectionSource) throws Exception {
61
+
62
+        accountDao = DaoManager.createDao(connectionSource, Account.class);
63
+
64
+    }
65
+}

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


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