1
1
package com .aerospike .mapper .example ;
2
2
3
- import java .util .Date ;
4
- import java .util .concurrent .TimeUnit ;
3
+ import static org .junit .Assert .assertEquals ;
5
4
6
5
import org .junit .Test ;
7
6
12
11
import com .aerospike .client .policy .Policy ;
13
12
import com .aerospike .client .policy .Replica ;
14
13
import com .aerospike .client .policy .WritePolicy ;
15
- import com .aerospike .mapper .example .model .Account ;
16
14
import com .aerospike .mapper .example .model .Address ;
17
15
import com .aerospike .mapper .example .model .Branch ;
18
16
import com .aerospike .mapper .example .model .Checkbook ;
19
17
import com .aerospike .mapper .example .model .Customer ;
18
+ import com .aerospike .mapper .example .model .Property ;
20
19
import com .aerospike .mapper .example .model .Transaction ;
20
+ import com .aerospike .mapper .example .model .accounts .Account ;
21
+ import com .aerospike .mapper .example .model .accounts .LoanAccount ;
22
+ import com .aerospike .mapper .example .model .accounts .PortfolioAccount ;
21
23
import com .aerospike .mapper .tools .AeroMapper ;
24
+ import com .fasterxml .jackson .core .JsonProcessingException ;
25
+ import com .fasterxml .jackson .databind .ObjectMapper ;
26
+ import com .fasterxml .jackson .databind .ObjectWriter ;
22
27
23
- public class Application {
28
+ public class Application extends ApplicationBase {
24
29
25
30
@ Test
26
- public void run () {
31
+ public void run () throws JsonProcessingException {
27
32
Policy readPolicy = new Policy ();
28
33
readPolicy .maxRetries = 4 ;
29
34
readPolicy .replica = Replica .SEQUENCE ;
@@ -46,56 +51,89 @@ public void run() {
46
51
47
52
AeroMapper mapper = new AeroMapper .Builder (client )
48
53
.withWritePolicy (writePolicy ).forAll ()
49
- .withReadPolicy (txnReadPolicy ).forAll ()
54
+ .withReadPolicy (readPolicy ).forAll ()
50
55
.withReadPolicy (txnReadPolicy ).forClasses (Transaction .class )
51
56
.build ();
52
57
53
- Address mailingAddress = new Address ("773 Elm St" , "Apt 2" , "Grand Junction" , new char [] { 'C' , 'O' } , "83451" );
54
- Address billingAddress = new Address ("123 Main St" , null , "Denver" , new char [] { 'C' , 'O' } , "80001" );
55
- Address alternateAddress = new Address ("1 Park Road" , null , "Miami" , new char [] { 'F' , 'L' } , "98531" );
58
+ Address mailingAddress = new Address ("773 Elm St" , "Apt 2" , "Grand Junction" , "CO" , "83451" );
59
+ Address billingAddress = new Address ("123 Main St" , null , "Denver" , "CO" , "80001" );
60
+ Address alternateAddress = new Address ("1 Park Road" , null , "Miami" , "FL" , "98531" );
56
61
57
- Customer customer = new Customer ("cust1" , "Bob" , "Smith" );
58
- customer .setDateOfBirth (new Date (new Date ().getTime () - TimeUnit .MILLISECONDS .convert (30 *365 , TimeUnit .DAYS )));
59
- customer .setPhone ("(555)555-1234" );
62
+ Customer customer = createAndPopulateCustomer ();
60
63
customer .setMailingAddress (mailingAddress );
61
64
62
- Account testAccount = new Account ("ACC-1234" , customer .getCustomerId (), "Test Account" );
63
- testAccount .setBalance (100000 );
64
- testAccount .setCard (true );
65
- testAccount .setBillingAddress (billingAddress );
66
- testAccount .getAlternateAddresses ().add (mailingAddress );
67
- testAccount .getAlternateAddresses ().add (alternateAddress );
68
- testAccount .setRouting ("123456789" );
69
- testAccount .setPaperless (true );
70
- testAccount .setOverdraftProtection (false );
71
- testAccount .setOnlineUserName ("beesmith" );
72
- testAccount .setLastLogin (new Date ());
65
+ /* Create a checking account for this customer */
66
+ Account checkingAccount = createAndPopulateChecking (customer .getCustomerId ());
67
+ checkingAccount .setBillingAddress (billingAddress );
68
+ checkingAccount .getAlternateAddresses ().add (mailingAddress );
69
+ checkingAccount .getAlternateAddresses ().add (alternateAddress );
73
70
74
- Branch issuingBranch = new Branch ("Br123" , new Address ("77 Park Road" , null , "Miami" , new char [] {'F' , 'L' }, "98531" ), "Miami Central" );
75
- Checkbook checkbook = new Checkbook (testAccount .getAccountId (), 1 , 100 , new Date ());
76
- checkbook .setIssuer (issuingBranch );
77
- checkbook .setRecalled (false );
78
- testAccount .getCheckbooks ().put (1 , checkbook );
71
+ Branch issuingBranch = new Branch ("Br123" , new Address ("77 Park Road" , null , "Miami" , "FL" , "98531" ), "Miami Central" );
72
+ Checkbook checkbook = createAndPopulateCheckbook1 (checkingAccount .getAccountId (), issuingBranch );
73
+ checkingAccount .getCheckbooks ().put (1 , checkbook );
79
74
80
- Branch otherIssuingBranch = new Branch ("Br567" , new Address ("129 Bump Drive" , null , "New York" , new char [] {'N' , 'Y' }, "77777" ), "New York City Office" );
81
- Checkbook checkbook2 = new Checkbook (testAccount .getAccountId (), 101 , 600 , new Date ());
82
- checkbook2 .setIssuer (otherIssuingBranch );
83
- checkbook2 .setRecalled (false );
84
- testAccount .getCheckbooks ().put (2 , checkbook2 );
75
+ Branch otherIssuingBranch = new Branch ("Br567" , new Address ("129 Bump Drive" , null , "New York" , "NY" , "77777" ), "New York City Office" );
76
+ Checkbook checkbook2 = createAndPopulateCheckbook2 (checkingAccount .getAccountId (), otherIssuingBranch );
77
+ checkingAccount .getCheckbooks ().put (2 , checkbook2 );
85
78
86
- customer .getAccounts ().add (testAccount );
79
+ mapper .save (checkingAccount );
80
+ customer .getAccounts ().add (checkingAccount );
81
+
82
+ /* Create a savings account for this customer */
83
+ Account savingsAccount = createAndPopulateSavingsAccount (customer .getCustomerId ());
84
+ savingsAccount .setBillingAddress (billingAddress );
85
+ savingsAccount .getAlternateAddresses ().add (mailingAddress );
86
+
87
+ mapper .save (savingsAccount );
88
+ customer .getAccounts ().add (savingsAccount );
89
+
90
+ /* Create a porfolio account for this customer */
91
+ Property property1 = createAndPopulateProperty1 ();
92
+ Property property2 = createAndPopulateProperty2 ();
93
+ Property property3 = createAndPopulateProperty3 ();
94
+ mapper .save (property1 );
95
+ mapper .save (property2 );
96
+ mapper .save (property3 );
97
+
98
+ PortfolioAccount portfolioAccount = createAndPopulatePortfolioAccount (customer .getCustomerId ());
99
+ portfolioAccount .setBillingAddress (billingAddress );
100
+ portfolioAccount .getAlternateAddresses ().add (mailingAddress );
101
+ portfolioAccount .addPropertyToPortfolio (property1 , 0.0239f );
102
+ portfolioAccount .addPropertyToPortfolio (property2 , 0.0299f );
103
+ portfolioAccount .addPropertyToPortfolio (property3 , 0.0319f );
104
+
105
+ mapper .save (portfolioAccount );
106
+ customer .getAccounts ().add (portfolioAccount );
107
+
108
+ /* Create a loan account for this customer */
87
109
110
+ LoanAccount loanAccount = createAndPopulateLoanAccount (customer .getCustomerId ());
111
+ loanAccount .setBillingAddress (billingAddress );
112
+ loanAccount .getAlternateAddresses ().add (mailingAddress );
113
+ customer .getAccounts ().add (loanAccount );
114
+
115
+ Property securityProperty = createAndPopulateProperty4 ();
116
+ loanAccount .setSecurityProperty (securityProperty );
117
+
118
+ mapper .save (securityProperty );
119
+ mapper .save (loanAccount );
120
+
88
121
mapper .save (issuingBranch );
89
122
mapper .save (otherIssuingBranch );
90
- mapper .save (testAccount );
91
123
mapper .save (customer );
92
124
mapper .save (checkbook );
93
125
mapper .save (checkbook2 );
94
126
127
+ Customer readCustomer = null ;
95
128
for (int i = 0 ; i < 100 ; i ++) {
96
- long now =System .nanoTime ();
97
- Customer readCustomer = mapper .read (Customer .class , customer .getCustomerId ());
98
- System .out .println (( System .nanoTime () - now )/1000 );
129
+ long now = System .nanoTime ();
130
+ readCustomer = mapper .read (Customer .class , customer .getCustomerId ());
131
+ System .out .println (String . format ( "Customer graph read time: %.3fms" , ( System .nanoTime () - now )/1000000f ) );
99
132
}
133
+ ObjectWriter objectWriter = new ObjectMapper ().writerWithDefaultPrettyPrinter ();
134
+ String readString = objectWriter .writeValueAsString (readCustomer );
135
+ System .out .println (readString );
136
+ String originalObject = objectWriter .writeValueAsString (customer );
137
+ assertEquals (originalObject , readString );
100
138
}
101
139
}
0 commit comments