Project

General

Profile

Programming Guide for Batch Program » History » Version 5

chin-yeh, 10/03/2011 10:37 AM

1 1 chin-yeh
{{toc}}
2
3
h1. Programming Guide for Batch Program
4 2 chin-yeh
5
> Refer to [[Programming Guide]] if integrating in other environment, e.g. web app
6
7
All of the APIs mentioned below will not invoke the DP web services at all. Instead it will insert record into [[Specification#DP_INTERFACE|interface table]] and then those records will be picked up by a specific batch program and send it to DP on daily basis.
8
9
The Javadoc of *dp-client*:
10
> http://192.168.2.13:50000/dp_client_apidocs/
11
12
The binary or source files of *dp-client*:
13
> [[wiki#SCM|SCM]]
14
15
Demo application of *dp-client*:
16
> There is no demo application for these APIs but these API usage is very similiar with the one that mentioned in [[Programming Guide]]
17
18
h2. Commit Sales
19
20 3 chin-yeh
This method is used to deduct DP balance. 
21 1 chin-yeh
22 3 chin-yeh
_This method *will only persist* the transaction details into database._
23
24 2 chin-yeh
_Method Signature:_
25
<pre>
26
<code class="JAVA">
27
public static int persistSalesCommit(java.sql.Connection dbConnection,
28
                                     java.lang.String transactionId,
29
                                     java.lang.String countryCode,
30
                                     java.lang.String memberId,
31
                                     java.util.Date trxDate,
32
                                     java.math.BigDecimal dpAmount,
33
                                     java.math.BigDecimal invoiceAmount)
34
                              throws java.sql.SQLException
35
</code>
36
</pre>
37
38
39
h3. Input Parameters
40
41
See "persistSalesCommit":http://192.168.2.13:50000/dp_client_apidocs/com/ecosway/dp_client/DPServicesUtils.html
42
43
h3. Output Parameters
44
45
The number of affected rows
46
47
h3. Code Snippets
48
49
<pre>
50
<code class="JAVA">
51
Connection dbConnection = DBConnectionFactory.createDbConnection("java:/DB2DS2");
52 5 chin-yeh
int affectedRows = 0;
53
54 2 chin-yeh
try {
55 5 chin-yeh
	affectedRows = DPServicesUtils.persistSalesCommit(dbConnection,
56 2 chin-yeh
				trxId, countryCode, shopperId,
57
				trxDate, dpAmount, invoiceAmount);
58
} catch (SQLException ex) {
59
	LOGGER.error("Error in persisting the event", ex);
60
} finally {		
61
	if (dbConnection != null) {
62
	   dbConnection.close();
63
	}
64
}
65
</code>
66
</pre>
67
68
h2. Sales Return / Cancel Sales
69
70
This method is used to adjust the DP balance.
71 1 chin-yeh
72 3 chin-yeh
_This method *will only persist* the transaction details into database._
73
74 2 chin-yeh
_Method Signature:_
75
<pre>
76
<code class="JAVA">
77
public static int persistSalesReturn(java.sql.Connection connection,
78
                                     java.lang.String transactionId,
79
                                     java.lang.String countryCode,
80
                                     java.lang.String memberId,
81
                                     java.util.Date trxDate,
82
                                     java.math.BigDecimal dpAmount,
83
                                     java.math.BigDecimal invoiceAmount)
84
                              throws java.sql.SQLException
85
</code>
86
</pre>
87
88
h3. Input Parameters
89
90
See "persistSalesReturn":http://192.168.2.13:50000/dp_client_apidocs/com/ecosway/dp_client/DPServicesUtils.html
91
92
h3. Output Parameters
93
94
The number of affected rows
95
96
h3. Code Snippets
97
98
<pre>
99 1 chin-yeh
<code class="JAVA">
100 2 chin-yeh
Connection dbConnection = DBConnectionFactory.createDbConnection("java:/DB2DS2");
101 1 chin-yeh
	
102 5 chin-yeh
int affectedRows = 0;
103 2 chin-yeh
104
try {
105 5 chin-yeh
	affectedRows = DPServicesUtils.persistSalesReturn(dbConnection, trxId, countryCode, 
106 2 chin-yeh
			shopperId,trxDate, dpAmount, invoiceAmount);	
107
108
} catch (SQLException ex) {
109
	LOGGER.error("Error in persisting the event", ex);
110
} finally {
111
	if (dbConnection != null) {
112
		dbConnection.close();
113
	}
114
}
115
</code>
116
</pre>
117
118
119
h2. VIP Upgrade to BO
120
121 1 chin-yeh
This method upgrades the VIP to BO. One must utilize all of the remaining DP balance in the limited period of time. The validity period is determined by DP.
122 3 chin-yeh
123
_This method *will only persist* the transaction details into database._
124 2 chin-yeh
125
_Method Signature:_
126
<pre>
127
<code class="JAVA">
128
public static int persistVipUpgrade(java.sql.Connection connection,
129
                                    java.lang.String trxId,
130
                                    java.lang.String countryCode,
131
                                    java.lang.String memberName,
132
                                    java.lang.String memberId,
133
                                    java.lang.String newMemberId,
134
                                    java.util.Date trxDate)
135
                             throws java.sql.SQLException
136
</code>
137
</pre>
138
139
h3. Input Parameters
140
141
See "persistVipUpgrade":http://192.168.2.13:50000/dp_client_apidocs/com/ecosway/dp_client/DPServicesUtils.html
142
143
h3. Output Parameters
144
145
The number of affected rows
146
147
h3. Code Snippets
148 1 chin-yeh
149 2 chin-yeh
<pre>
150 1 chin-yeh
<code class="JAVA">
151 2 chin-yeh
Connection dbConnection = DBConnectionFactory.createDbConnection("java:/DB2DS2");
152
	
153 5 chin-yeh
int affectedRows = 0;
154 2 chin-yeh
155
try {
156 5 chin-yeh
	affectedRows = DPServicesUtils.persistVipUpgrade(dbConnection, trxId, countryCode,
157 2 chin-yeh
			memberName, shopperId, newShopperId, trxDate);
158
159
} catch (SQLException ex) {
160
	LOGGER.error("Error in persisting the event", ex);
161
} finally {
162
	if (dbConnection != null) {
163
		dbConnection.close();
164
	}
165
}
166
</code>
167
</pre>
168 4 chin-yeh
169
170
h2. Exception Handling Strategies
171
172
The APIs would throw the following exceptions:
173
* *SQLException* - if there's any issue in persisting or updating the event
174
* *unchecked exception* - e.g. NullPointerException. This is more like a programming errors so do not catch it for whatever reasons.
175
** _note: catch the *Exception* will catch both checked & unchecked exception_
176
177
The above exceptions should never be ignored, at least, the full error stack trace should be logged.