Revision 27:1a2f464f8c1c

View differences:

src/main/java/my/com/upass/MinimalUPassControllerV2.java
8 8

  
9 9
import my.com.upass.dao.ConfigurationDAO;
10 10
import my.com.upass.dao.MinimalDAOFactory;
11
import my.com.upass.pojo.AppAccessBean;
11
import my.com.upass.maybank.entities.UserProfile;
12 12
import my.com.upass.pojo.ConfigurationBean;
13 13
import my.com.upass.pojo.MinimalUserBean;
14
import my.com.upass.pojo.UserAppAccess;
15 14
import my.com.upass.services.AppAccessMgtService;
16 15
import my.com.upass.services.AppAccessMgtService.MultipleAppAccessesFound;
17 16
import my.com.upass.services.CreateUserService;
18 17
import my.com.upass.services.ModifyUserService;
19 18
import my.com.upass.services.VerifyStaticPasswordService;
20
import net.penril.generic.hibernate.HibernateUtils;
21 19

  
22
import org.apache.commons.lang.NotImplementedException;
23 20
import org.apache.log4j.Logger;
24 21
import org.hibernate.Session;
25
import org.hibernate.criterion.Restrictions;
26 22

  
27 23
public class MinimalUPassControllerV2 {
28 24

  
......
144 140
		return rc;
145 141
	}
146 142

  
147
	public int addUser(String appAccessId, String hashedSecretKey, MinimalUserBean user) {
143
	public int addUser(String appAccessId, String hashedSecretKey, MinimalUserBean user, Session txSession) {
148 144

  
149 145
		final String userAlias = user.getUserAlias();
150 146
		final String doubleHashedPassword = user.getPcipherText();
......
154 150
			return MinimalConstants.ERR_PASSWORD_SAMEAS_USERALIAS;
155 151
		}
156 152
		int rc = verifyStaticPasswordService.verifyStaticPassword(
157
				appAccessId, hashedSecretKey, true, MinimalConstants.UTYPE_STATE_USER);
153
				appAccessId, hashedSecretKey, true, MinimalConstants.UTYPE_STATE_USER, txSession);
158 154

  
159 155
		if (rc != MinimalConstants.ERR_SUCCESS) {
160 156
			return rc;
161 157
		}
162

  
163 158
		Integer appId = null;
164 159
		try {
165
			appId = appAccessMgtService.getAppIdForAdmin(appAccessId);
160
			appId = appAccessMgtService.getAppIdForAdmin(appAccessId, txSession);
166 161

  
167 162
			if (appId == null)
168 163
				rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
......
170 165
			else {
171 166
				user.setUserType(MinimalConstants.UTYPE_STATE_USER);
172 167
				user.setPstate(MinimalConstants.UID_STATE_ACTIVE);
173
				rc = createUserService.addUser(user, appId.intValue());
168
				rc = createUserService.addUser(user, appId.intValue(), txSession);
174 169
			}
175 170

  
176 171
		} catch (MultipleAppAccessesFound e) {
177 172
			rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
178 173
			e.printStackTrace();
179 174
		}
180
		logger.info("UA_AddUser - user alias: [" + userAlias + "] Return: " + rc);
175
		logger.info("addUser - user alias: [" + userAlias + "] Return: " + rc);
181 176
		return rc;
182 177
	}
183 178

  
......
252 247

  
253 248
		return rc;
254 249
	}
250

  
251
	public int updateProfileShallowly(String appAccessId, String hashedSecretKey, UserProfile profile, Session txSession) {
252

  
253
		MinimalUserBean user = profile.getMinUser();
254
		final String userAlias = user.getUserAlias();
255
		final String doubleHashedPassword = user.getPcipherText();
256

  
257
		// // check if password is similar to user alias
258
		// if (userAlias.equalsIgnoreCase(doubleHashedPassword)) {
259
		// return MinimalConstants.ERR_PASSWORD_SAMEAS_USERALIAS;
260
		// }
261

  
262
		int rc = verifyStaticPasswordService.verifyStaticPassword(
263
				appAccessId, hashedSecretKey, true,
264
				MinimalConstants.UTYPE_STATE_USER);
265

  
266
		if (rc != MinimalConstants.ERR_SUCCESS)
267
			return rc;
268

  
269
		Integer appId = null;
270
		try {
271
			appId = appAccessMgtService.getAppIdForAdmin(appAccessId, txSession);
272

  
273
			final Object appIdObj = AppAccessMgtService.profileToAppMap.get(profile.getClass());
274
			final int appIdForProfile = ((Integer) appIdObj).intValue();
275

  
276
			if (appId == null || appId.intValue() != appIdForProfile)
277
				rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
278

  
279
			else {
280
				rc = modifyUserService.updateProfileShallowly(profile, txSession);
281
			}
282
		} catch (MultipleAppAccessesFound e) {
283
			rc = MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
284
			e.printStackTrace();
285
		}
286
		logger.info("updateProfileShallowly - user alias: [" + userAlias + "] Return: " + rc);
287
		return rc;
288
	}
255 289
}
src/main/java/my/com/upass/dao/MinimalHibernateDAOFactory.java
4 4
import my.com.upass.dao.hibernate.UserDAOHibernate;
5 5
import net.penril.generic.hibernate.GenericDAOHibernate;
6 6

  
7

  
8 7
public class MinimalHibernateDAOFactory extends MinimalDAOFactory {
9 8

  
10
	private GenericDAOHibernate instantiateDAO(Class daoClass) 
11
	{
12
		try 
13
		{
14
			GenericDAOHibernate dao = (GenericDAOHibernate)daoClass.newInstance();
15
			return dao;
16
		} 
17
		catch (Exception ex) 
18
		{
19
			throw new RuntimeException( "Can not instantiate DAO: " + daoClass, ex);
9
	private GenericDAOHibernate instantiateDAO(Class daoClass) {
10
		try {
11
			return (GenericDAOHibernate) daoClass.newInstance();
12

  
13
		} catch (Exception ex) {
14
			throw new RuntimeException("Can not instantiate DAO: " + daoClass, ex);
20 15
		}
21 16
	}
22
	
23
	public UserDAO getUserDAO ()
24
	{
25
		return (UserDAO) instantiateDAO (UserDAOHibernate.class);
17

  
18
	public UserDAO getUserDAO() {
19
		return (UserDAO) instantiateDAO(UserDAOHibernate.class);
26 20
	}
27 21

  
28
	public ConfigurationDAO getConfigurationDAO ()
29
	{
30
		return (ConfigurationDAO) instantiateDAO (ConfigurationDAOHibernate.class);
22
	public ConfigurationDAO getConfigurationDAO() {
23
		return (ConfigurationDAO) instantiateDAO(ConfigurationDAOHibernate.class);
31 24
	}
32

  
33 25
}
src/main/java/my/com/upass/dao/UserDAO.java
13 13

  
14 14
import java.util.List;
15 15

  
16
import my.com.upass.maybank.entities.UserProfile;
16 17
import my.com.upass.pojo.MinimalUserBean;
17 18
import my.com.upass.pojo.MinimalUserBeanBackup;
18 19
import my.com.upass.pojo.UserAppAccess;
19 20
import net.penril.generic.hibernate.GenericDAO;
20 21

  
22
import org.hibernate.Session;
23

  
21 24
/**
22 25
 * PROGRAMMER: Danniell
23 26
 * CHANGE-NO:
......
33 36
 */
34 37
public interface UserDAO extends GenericDAO {
35 38

  
36
	MinimalUserBean getUserFromStore(String userAlias, int sqlMode);
39
	void deleteTbAmUser(Integer tUserId, final Session txSession) throws Exception;
37 40

  
38
	MinimalUserBean getUserFromStore(String userAlias);
41
	boolean deleteUser(MinimalUserBean userBean, final Session txSession) throws Exception;
39 42

  
40
	boolean updateUserToStore(MinimalUserBean MinimalUserBean);
43
	MinimalUserBean getTbAmUserByUserAlias(String userAlias, final Session txSession) throws Exception;
41 44

  
42
	boolean insertUserToStore(MinimalUserBean MinimalUserBean);
45
	MinimalUserBean getTbAmUserByUserId(Long userId, final Session txSession) throws Exception;
43 46

  
44
	boolean deleteUser(MinimalUserBean MinimalUserBean);
47
	MinimalUserBeanBackup getUserBackupFromStore(String userAlias, final Session txSession);
45 48

  
46
	boolean insertUserToBackupStore(MinimalUserBeanBackup MinimalUserBean);
49
	MinimalUserBean getUserFromStore(String userAlias, int sqlMode, final Session txSession);
47 50

  
48
	MinimalUserBeanBackup getUserBackupFromStore(String userAlias);
51
	MinimalUserBean getUserFromStore(String userAlias, final Session txSession);
49 52

  
50
	MinimalUserBean getTbAmUserByUserAlias(String userAlias) throws Exception;
53
	boolean insertUserToBackupStore(MinimalUserBeanBackup userBean, final Session txSession) throws Exception;
51 54

  
52
	MinimalUserBean getTbAmUserByUserId(Long tUserId) throws Exception;
53

  
54
	void deleteTbAmUser(Integer tUserId) throws Exception;
55

  
56
	/**
57
	 * @param appAccessId
58
	 * @return a list of {@link UserAppAccess} objects
59
	 * @throws Exception
60
	 */
61
	List listUserAppAccesses(String appAccessId) throws Exception;
55
	boolean insertUserToStore(MinimalUserBean userBean, final Session txSession) throws Exception;
62 56

  
63 57
	/**
64 58
	 * @param appAccessId
......
66 60
	 * @return a list of {@link UserAppAccess} objects
67 61
	 * @throws Exception
68 62
	 */
69
	List listUserAppAccesses(String appAccessId, char accessType) throws Exception;
63
	List listUserAppAccesses(String appAccessId, char accessType, final Session txSession) throws Exception;
64

  
65
	/**
66
	 * @param appAccessId
67
	 * @return a list of {@link UserAppAccess} objects
68
	 * @throws Exception
69
	 */
70
	List listUserAppAccesses(String appAccessId, final Session txSession) throws Exception;
71

  
72
	boolean updateProfileShallowly(UserProfile profile, final Session txSession) throws Exception;
73

  
74
	boolean updateUserToStore(MinimalUserBean MinimalUserBean, final Session txSession) throws Exception;
70 75
}
src/main/java/my/com/upass/dao/hibernate/UserDAOHibernate.java
15 15

  
16 16
import my.com.upass.MinimalConstants;
17 17
import my.com.upass.dao.UserDAO;
18
import my.com.upass.maybank.entities.UserProfile;
18 19
import my.com.upass.pojo.MinimalUserBean;
19 20
import my.com.upass.pojo.MinimalUserBeanBackup;
20 21
import my.com.upass.pojo.UserAppAccess;
21 22
import net.penril.generic.hibernate.GenericDAOHibernate;
22
import net.penril.generic.hibernate.HibernateUtils;
23 23

  
24 24
import org.apache.log4j.Logger;
25 25
import org.hibernate.Criteria;
26 26
import org.hibernate.FetchMode;
27
import org.hibernate.HibernateException;
28 27
import org.hibernate.Query;
29 28
import org.hibernate.Session;
30 29
import org.hibernate.criterion.Restrictions;
......
50 49
	/**
51 50
	 * @see my.com.upass.dao.UserDAO#getUserFromStore(java.lang.String, int)
52 51
	 */
53
	public MinimalUserBean getUserFromStore(String userAlias, int sqlMode) {
52
	public MinimalUserBean getUserFromStore(String userAlias, int sqlMode, final Session txSession) {
54 53

  
55 54
		MinimalUserBean profile = null;
56
		Criteria criteria;
57 55
		Session session = null;
58 56
		try {
59
			session = getSession();
60
			criteria = session.createCriteria(MinimalUserBean.class);
57
			session = txSession != null ? txSession : getSession();
58

  
59
			Criteria criteria = session.createCriteria(MinimalUserBean.class);
61 60
			criteria.add(Restrictions.eq("userAlias", userAlias));
62 61

  
63 62
			switch (sqlMode) {
......
77 76
			logger.error(e, e);
78 77

  
79 78
		} finally {
80
			if (session != null && session.isConnected()) {
81
				session.close();
82
			}
79
			if (txSession == null)
80
				closeSessionIfAny(session);
83 81
		}
84 82
		return profile;
85 83
	}
86 84

  
87 85
	/**
88
	 * @see my.com.upass.dao.UserDAO#getUserFromStore(java.lang.String)
86
	 * @see my.com.upass.dao.UserDAO#getUserFromStore(String, Session)
89 87
	 */
90
	public MinimalUserBean getUserFromStore(String userAlias) {
91
		return getUserFromStore(userAlias, MinimalConstants.MODE_QUSERBEAN);
88
	public MinimalUserBean getUserFromStore(String userAlias, final Session txSession) {
89
		return getUserFromStore(userAlias, MinimalConstants.MODE_QUSERBEAN, txSession);
92 90
	}
93 91

  
94 92
	/**
93
	 * @throws Exception
95 94
	 * @see my.com.upass.dao.UserDAO#updateUserToStore(my.com.upass.pojo.MinimalUserBean)
96 95
	 */
97
	public boolean updateUserToStore(MinimalUserBean userBean) {
96
	public boolean updateUserToStore(MinimalUserBean userBean, final Session txSession) throws Exception {
98 97
		boolean isUpdated = false;
99 98
		Session session = null;
100 99
		try {
101
			session = getSession();
102
			session.beginTransaction();
100
			session = txSession != null ? txSession : getSession();
101
			if (txSession == null)
102
				session.beginTransaction();
103

  
103 104
			session.update(userBean);
104
			session.getTransaction().commit();
105

  
106
			if (txSession == null)
107
				session.getTransaction().commit();
108

  
105 109
			isUpdated = true;
106 110

  
107 111
		} catch (Exception e) {
108
			logger.error(e, e);
109
			if (e instanceof HibernateException) {
110
				if (session != null) {
111
					session.getTransaction().rollback();
112
				}
113
			}
112
			if (txSession == null) {
113
				logger.error(e, e);
114
				rollbackTransactionIfAny(session);
115

  
116
			} else
117
				throw e;
118

  
114 119
		} finally {
115
			if (session != null && session.isConnected()) {
116
				session.close();
117
			}
120
			if (txSession == null)
121
				closeSessionIfAny(session);
118 122
		}
119 123
		return isUpdated;
120 124
	}
121 125

  
122 126
	/**
127
	 * @throws Exception
123 128
	 * @see my.com.upass.dao.UserDAO#insertUserToStore(my.com.upass.pojo.MinimalUserBean)
124 129
	 */
125
	public boolean insertUserToStore(MinimalUserBean userBean) {
130
	public boolean insertUserToStore(MinimalUserBean userBean, final Session txSession) throws Exception {
126 131
		boolean isCreated = false;
127 132
		Session session = null;
128 133
		try {
129
			session = getSession();
130
			session.beginTransaction();
134
			session = txSession != null ? txSession : getSession();
135
			if (txSession == null)
136
				session.beginTransaction();
137

  
131 138
			session.save(userBean);
132
			session.getTransaction().commit();
133 139
			isCreated = true;
134 140

  
141
			if (txSession == null)
142
				session.getTransaction().commit();
143

  
135 144
		} catch (Exception e) {
136
			if (e instanceof HibernateException) {
137
				if (session != null) {
138
					session.getTransaction().rollback();
139
				}
140
			}
141
			logger.error(e, e);
145
			if (txSession == null) {
146
				rollbackTransactionIfAny(session);
147
				logger.error(e, e);
148

  
149
			} else
150
				throw e;
142 151

  
143 152
		} finally {
144
			if (session != null && session.isConnected()) {
145
				session.close();
146
			}
153
			if (txSession == null)
154
				closeSessionIfAny(session);
147 155
		}
148 156
		return isCreated;
149 157
	}
150 158

  
151 159
	/**
160
	 * @throws Exception
152 161
	 * @see my.com.upass.dao.UserDAO#updateUserToStore(my.com.upass.pojo.MinimalUserBean)
153 162
	 */
154
	public boolean deleteUser(MinimalUserBean userBean) {
163
	public boolean deleteUser(MinimalUserBean userBean, final Session txSession) throws Exception {
155 164
		boolean isUpdated = false;
156 165
		Session session = null;
157 166
		try {
158
			session = getSession();
159
			session.beginTransaction();
167
			session = txSession != null ? txSession : getSession();
168
			if (txSession == null)
169
				session.beginTransaction();
170

  
160 171
			session.delete(userBean);
161
			session.getTransaction().commit();
172

  
173
			if (txSession == null)
174
				session.getTransaction().commit();
175

  
162 176
			isUpdated = true;
163 177

  
164 178
		} catch (Exception e) {
165
			if (e instanceof HibernateException) {
166
				if (session != null) {
167
					session.getTransaction().rollback();
168
				}
169
			}
170
			logger.error(e, e);
179
			if (txSession == null) {
180
				rollbackTransactionIfAny(session);
181
				logger.error(e, e);
182

  
183
			} else
184
				throw e;
171 185

  
172 186
		} finally {
173
			if (session != null && session.isConnected()) {
174
				session.close();
175
			}
187
			if (txSession == null)
188
				closeSessionIfAny(session);
176 189
		}
177 190
		return isUpdated;
178 191
	}
179 192

  
180 193
	/**
194
	 * @throws Exception
181 195
	 * @see my.com.upass.dao.UserDAO#insertUserToStore(my.com.upass.pojo.MinimalUserBean)
182 196
	 */
183
	public boolean insertUserToBackupStore(MinimalUserBeanBackup userBean) {
197
	public boolean insertUserToBackupStore(MinimalUserBeanBackup userBean, final Session txSession) throws Exception {
184 198
		boolean isCreated = false;
185 199
		Session session = null;
186 200
		try {
187
			session = getSession();
188
			session.beginTransaction();
201
			session = txSession != null ? txSession : getSession();
202
			if (txSession == null)
203
				session.beginTransaction();
204

  
189 205
			session.save(userBean);
190
			session.getTransaction().commit();
206

  
207
			if (txSession == null)
208
				session.getTransaction().commit();
209

  
191 210
			isCreated = true;
192 211

  
193 212
		} catch (Exception e) {
194
			if (e instanceof HibernateException) {
195
				if (session != null) {
196
					session.getTransaction().rollback();
197
				}
198
			}
199
			logger.error(e, e);
213
			if (txSession == null) {
214
				rollbackTransactionIfAny(session);
215
				logger.error(e, e);
216

  
217
			} else
218
				throw e;
200 219

  
201 220
		} finally {
202
			if (session != null && session.isConnected()) {
203
				session.close();
204
			}
221
			if (txSession == null)
222
				closeSessionIfAny(session);
205 223
		}
206 224
		return isCreated;
207 225
	}
208 226

  
209
	public MinimalUserBeanBackup getUserBackupFromStore(String userAlias) {
227
	public MinimalUserBeanBackup getUserBackupFromStore(String userAlias, final Session txSession) {
210 228

  
211 229
		MinimalUserBeanBackup profile = null;
212 230
		Criteria criteria;
213 231
		Session session = null;
214 232
		try {
215
			session = getSession();
233
			session = txSession != null ? txSession : getSession();
234

  
216 235
			criteria = session.createCriteria(MinimalUserBeanBackup.class);
217 236
			criteria.add(Restrictions.eq("userAlias", userAlias));
218 237

  
......
222 241
			logger.error(e, e);
223 242

  
224 243
		} finally {
225
			if (session != null && session.isConnected()) {
226
				session.close();
227
			}
244
			if (txSession == null)
245
				closeSessionIfAny(session);
228 246
		}
229 247
		return profile;
230 248
	}
231 249

  
232
	public MinimalUserBean getTbAmUserByUserAlias(String userAlias) throws Exception {
250
	public MinimalUserBean getTbAmUserByUserAlias(String userAlias, final Session txSession) throws Exception {
233 251

  
234 252
		MinimalUserBean TbAmUser;
253
		Session session = null;
235 254
		try {
236
			getSession().beginTransaction();
255
			session = txSession != null ? txSession : getSession();
237 256

  
238
			Criteria m_oCriteria = getSession().createCriteria(MinimalUserBean.class);
257
			Criteria m_oCriteria = session.createCriteria(MinimalUserBean.class);
239 258
			m_oCriteria.add(Restrictions.eq("userAlias", userAlias));
240 259
			TbAmUser = (MinimalUserBean) m_oCriteria.uniqueResult();
241 260

  
242
			getSession().getTransaction().commit();
243

  
244
		} catch (Exception e) {
245
			if (e instanceof HibernateException) {
246
				getSession().getTransaction().rollback();
247
			}
248
			throw e;
249

  
250 261
		} finally {
251
			getSession().close();
262
			if (txSession == null)
263
				closeSessionIfAny(session);
252 264
		}
253 265
		return TbAmUser;
254 266
	}
255 267

  
256
	public MinimalUserBean getTbAmUserByUserId(Long tUserId) throws Exception {
268
	public MinimalUserBean getTbAmUserByUserId(Long tUserId, final Session txSession) throws Exception {
257 269
		MinimalUserBean TbAmUser;
270
		Session session = null;
258 271
		try {
259
			getSession().beginTransaction();
272
			session = txSession != null ? txSession : getSession();
260 273

  
261
			Criteria m_oCriteria = getSession().createCriteria(MinimalUserBean.class);
274
			Criteria m_oCriteria = session.createCriteria(MinimalUserBean.class);
262 275
			m_oCriteria.add(Restrictions.eq("userID", tUserId));
263 276
			TbAmUser = (MinimalUserBean) m_oCriteria.uniqueResult();
264 277

  
265
			getSession().getTransaction().commit();
266

  
267
		} catch (Exception e) {
268
			if (e instanceof HibernateException) {
269
				getSession().getTransaction().rollback();
270
			}
271
			throw e;
272

  
273 278
		} finally {
274
			getSession().close();
279
			if (txSession == null)
280
				closeSessionIfAny(session);
275 281
		}
276 282
		return TbAmUser;
277 283
	}
278 284

  
279
	public void deleteTbAmUser(Integer tUserId) throws Exception {
285
	public void deleteTbAmUser(Integer tUserId, final Session txSession) throws Exception {
280 286
		// ID ID = tUserId;
281 287
		Long ID = Long.valueOf(String.valueOf(tUserId));
282 288
		MinimalUserBean tbAmUser;
289
		Session session = null;
283 290
		try {
284
			getSession().beginTransaction();
285
			Criteria m_oCriteria = getSession()
286
					.createCriteria(MinimalUserBean.class);
291
			session = txSession != null ? txSession : getSession();
292

  
293
			if (txSession == null)
294
				session.beginTransaction();
295

  
296
			Criteria m_oCriteria = session.createCriteria(MinimalUserBean.class);
287 297
			m_oCriteria.add(Restrictions.eq("userId", ID));
288 298
			tbAmUser = (MinimalUserBean) m_oCriteria.uniqueResult();
289 299

  
290 300
			makeTransient(tbAmUser);
291
			getSession().getTransaction().commit();
292
			getSession().close();
301

  
302
			if (txSession == null)
303
				session.getTransaction().commit();
293 304

  
294 305
		} catch (Exception e) {
295
			getSession().getTransaction().rollback();
306
			if (txSession == null)
307
				rollbackTransactionIfAny(session);
296 308
			throw e;
297 309

  
298 310
		} finally {
299
			getSession().close();
311
			if (txSession == null)
312
				closeSessionIfAny(session);
300 313
		}
301 314
	}
302 315

  
303
	public List listUserAppAccesses(String appAccessId) throws Exception {
316
	public List listUserAppAccesses(String appAccessId, final Session txSession) throws Exception {
304 317
		List accesses = null;
305 318
		Session session = null;
306 319
		try {
307
			session = getSession();
320
			session = txSession != null ? txSession : getSession();
321

  
308 322
			Query query = session.createQuery(
309 323
					"FROM UserAppAccess aa WHERE aa.user.userAlias = :userAlias");
310 324
			accesses = query.setString("userAlias", appAccessId).list();
311 325

  
312 326
		} finally {
313
			if (session != null)
314
				session.close();
327
			if (txSession == null)
328
				closeSessionIfAny(session);
315 329
		}
316 330
		return accesses;
317 331
	}
......
324 338
	 *            {@link UserAppAccess#TYPE_ADMIN} <br>
325 339
	 *            {@link UserAppAccess#TYPE_USER}
326 340
	 */
327
	public List listUserAppAccesses(String appAccessId, char accessType) throws Exception {
341
	public List listUserAppAccesses(String appAccessId, char accessType, final Session txSession)
342
			throws Exception {
343

  
328 344
		List accesses = null;
329 345
		Session session = null;
330 346
		try {
331
			session = getSession();
347
			session = txSession != null ? txSession : getSession();
348

  
332 349
			Query query = session.createQuery(
333 350
					"FROM UserAppAccess aa "
334 351
							+ "WHERE aa.user.userAlias = :userAlias "
......
340 357
					.list();
341 358

  
342 359
		} finally {
343
			if (session != null)
344
				session.close();
360
			if (txSession == null)
361
				closeSessionIfAny(session);
345 362
		}
346 363
		return accesses;
347 364
	}
365

  
366
	public boolean updateProfileShallowly(UserProfile profile, Session txSession) throws Exception {
367
		boolean isUpdated = false;
368
		Session session = null;
369
		try {
370
			session = txSession != null ? txSession : getSession();
371
			if (txSession == null)
372
				session.beginTransaction();
373

  
374
			final Long profileKey = new Long(profile.getMinUser().getUserID());
375
			UserProfile existingProfile = (UserProfile) session.get(profile.getClass(), profileKey);
376

  
377
			if (existingProfile != null)
378
				session.merge(profile);
379
			else
380
				session.save(profile);
381

  
382
			if (txSession == null)
383
				session.getTransaction().commit();
384

  
385
			isUpdated = true;
386

  
387
		} catch (Exception e) {
388
			if (txSession == null) {
389
				logger.error(e, e);
390
				rollbackTransactionIfAny(session);
391

  
392
			} else
393
				throw e;
394

  
395
		} finally {
396
			if (txSession == null)
397
				closeSessionIfAny(session);
398
		}
399
		return isUpdated;
400
	}
348 401
}
src/main/java/my/com/upass/maybank/MinimalMaybankFacadeImpl.java
1 1
package my.com.upass.maybank;
2 2

  
3
import my.com.upass.MinimalConstants;
3 4
import my.com.upass.MinimalUPassControllerV2;
4 5
import my.com.upass.maybank.entities.M2uUser;
6
import net.penril.generic.hibernate.GenericDAOHibernate;
7
import net.penril.generic.hibernate.HibernateUtils;
5 8

  
6 9
import org.apache.commons.lang.NotImplementedException;
10
import org.hibernate.Session;
7 11

  
8 12
public class MinimalMaybankFacadeImpl implements MinimalMaybankFacade {
9 13

  
......
26 30
			String appAccessId, String hashedSecretKey,
27 31
			String username, String hashedPassword, String pan1, String pan2) {
28 32

  
29
		M2uUser m2uUser = new M2uUser();
30
		m2uUser.getMinUser().setUsername(username);
31
		m2uUser.getMinUser().setHashedPassword(hashedPassword);
32
		m2uUser.setPan1(pan1);
33
		m2uUser.setPan2(pan2);
34
		final int rc = minUpcV2.addUser(appAccessId, hashedSecretKey, m2uUser.getMinUser());
35
		// TODO: update user profile data as well
33
		int rc = MinimalConstants.ERR_UNKNOWN;
34
		Session session = null;
35
		try {
36
			session = HibernateUtils.currentSession();
37
			session.beginTransaction();
38

  
39
			M2uUser m2uUser = new M2uUser();
40
			m2uUser.getMinUser().setUsername(username);
41
			m2uUser.getMinUser().setHashedPassword(hashedPassword);
42
			m2uUser.setPan1(pan1);
43
			m2uUser.setPan2(pan2);
44
			
45
			rc = minUpcV2.addUser(appAccessId, hashedSecretKey, m2uUser.getMinUser(), session);
46
			
47
			if (rc == MinimalConstants.ERR_SUCCESS) {
48
				rc = minUpcV2.updateProfileShallowly(appAccessId, hashedSecretKey, m2uUser, session);
49
				session.getTransaction().commit();
50

  
51
			} else
52
				GenericDAOHibernate.rollbackTransactionIfAny(session);
53

  
54
		} catch (Exception e) {
55
			GenericDAOHibernate.rollbackTransactionIfAny(session);
56

  
57
		} finally {
58
			GenericDAOHibernate.closeSessionIfAny(session);
59
		}
36 60
		return rc;
37 61
	}
38 62

  
src/main/java/my/com/upass/maybank/entities/IbccAdminUser.java
1
package my.com.upass.maybank.entities;
2

  
3
import java.io.Serializable;
4

  
5
import my.com.upass.pojo.MinimalUserBean;
6

  
7
public class IbccAdminUser implements Serializable {
8

  
9
	private static final long serialVersionUID = 1L;
10

  
11
	private long userId;
12
	private MinimalUserBean minUser;
13

  
14
	//
15

  
16
	public MinimalUserBean getMinUser() {
17
		return minUser;
18
	}
19

  
20
	public void setMinUser(MinimalUserBean maybankUser) {
21
		this.minUser = maybankUser;
22
	}
23

  
24
	public long getUserId() {
25
		return userId;
26
	}
27

  
28
	public void setUserId(long userId) {
29
		this.userId = userId;
30
	}
31
}
src/main/java/my/com/upass/maybank/entities/IbccPublicUser.java
1
package my.com.upass.maybank.entities;
2

  
3
import java.io.Serializable;
4

  
5
import my.com.upass.pojo.MinimalUserBean;
6

  
7
public class IbccPublicUser implements Serializable {
8

  
9
	private static final long serialVersionUID = 1L;
10

  
11
	private long userId;
12
	private MinimalUserBean minUser;
13
	private String panCc;
14

  
15
	//
16

  
17
	public String getPanCc() {
18
		return panCc;
19
	}
20

  
21
	public void setPanCc(String panCc) {
22
		this.panCc = panCc;
23
	}
24

  
25
	public MinimalUserBean getMinUser() {
26
		return minUser;
27
	}
28

  
29
	public void setMinUser(MinimalUserBean maybankUser) {
30
		this.minUser = maybankUser;
31
	}
32

  
33
	public long getUserId() {
34
		return userId;
35
	}
36

  
37
	public void setUserId(long userId) {
38
		this.userId = userId;
39
	}
40
}
src/main/java/my/com/upass/maybank/entities/IbccUser.java
1
package my.com.upass.maybank.entities;
2

  
3
import my.com.upass.pojo.MinimalUserBean;
4

  
5
public class IbccUser implements UserProfile {
6

  
7
	private static final long serialVersionUID = 1L;
8

  
9
	private long userId;
10
	private MinimalUserBean minUser;
11
	private String panCc;
12

  
13
	//
14

  
15
	public String getPanCc() {
16
		return panCc;
17
	}
18

  
19
	public void setPanCc(String panCc) {
20
		this.panCc = panCc;
21
	}
22

  
23
	public MinimalUserBean getMinUser() {
24
		return minUser;
25
	}
26

  
27
	public void setMinUser(MinimalUserBean maybankUser) {
28
		this.minUser = maybankUser;
29
	}
30

  
31
	public long getUserId() {
32
		return userId;
33
	}
34

  
35
	public void setUserId(long userId) {
36
		this.userId = userId;
37
	}
38
}
src/main/java/my/com/upass/maybank/entities/Im2uUser.java
1 1
package my.com.upass.maybank.entities;
2 2

  
3
import java.io.Serializable;
4

  
5 3
import my.com.upass.pojo.MinimalUserBean;
6 4

  
7
public class Im2uUser implements Serializable {
5
public class Im2uUser implements UserProfile {
8 6

  
9 7
	private static final long serialVersionUID = 1L;
10 8

  
src/main/java/my/com/upass/maybank/entities/M2uUser.java
1 1
package my.com.upass.maybank.entities;
2 2

  
3
import java.io.Serializable;
4

  
5 3
import my.com.upass.pojo.MinimalUserBean;
6 4

  
7
public class M2uUser implements Serializable {
5
public class M2uUser implements UserProfile {
8 6

  
9 7
	private static final long serialVersionUID = 1L;
10 8

  
src/main/java/my/com/upass/maybank/entities/StockUser.java
1 1
package my.com.upass.maybank.entities;
2 2

  
3
import java.io.Serializable;
3
import my.com.upass.pojo.MinimalUserBean;
4 4

  
5
public class StockUser implements Serializable {
5
public class StockUser implements UserProfile {
6 6

  
7 7
	private static final long serialVersionUID = 1L;
8 8

  
......
14 14
	private String highNetWorthAttr;
15 15
	private String custType;
16 16
	private String activeAttr;
17
	
17

  
18 18
	//
19 19

  
20 20
	public String getPalAccountNo() {
......
80 80
	public void setActiveAttr(String activeAttr) {
81 81
		this.activeAttr = activeAttr;
82 82
	}
83

  
84
	public MinimalUserBean getMinUser() {
85
		return m2uUser.getMinUser();
86
	}
83 87
}
src/main/java/my/com/upass/maybank/entities/TicketingUser.java
1 1
package my.com.upass.maybank.entities;
2 2

  
3
import java.io.Serializable;
4

  
5 3
import my.com.upass.pojo.MinimalUserBean;
6 4

  
7
public class TicketingUser implements Serializable {
5
public class TicketingUser implements UserProfile {
8 6

  
9 7
	private static final long serialVersionUID = 1L;
10 8
	
src/main/java/my/com/upass/maybank/entities/UserProfile.java
1
package my.com.upass.maybank.entities;
2

  
3
import java.io.Serializable;
4

  
5
import my.com.upass.pojo.ClientApp;
6
import my.com.upass.pojo.MinimalUserBean;
7

  
8
public interface UserProfile extends Serializable {
9

  
10
	MinimalUserBean getMinUser();
11

  
12
}
src/main/java/my/com/upass/pojo/ClientApp.java
2 2

  
3 3
import java.io.Serializable;
4 4

  
5
public class ClientApp implements Serializable{
5
public class ClientApp implements Serializable {
6 6

  
7 7
	private static final long serialVersionUID = -6869309046805393100L;
8

  
9
	public static final Integer APP_ID_M2U = new Integer(1);
10
	public static final Integer APP_ID_ONLINE_STOCK = new Integer(2);
11
	public static final Integer APP_ID_ONLINE_TICKETING = new Integer(3);
12
	public static final Integer APP_ID_CCPP = new Integer(4);
13
	public static final Integer APP_ID_IM2U = new Integer(5);
14

  
8 15
	private int appId;
9 16
	private String appName;
10 17

  
11
	public ClientApp() { }
18
	//
19

  
20
	public ClientApp() {
21
	}
12 22

  
13 23
	public int getAppId() {
14 24
		return appId;
src/main/java/my/com/upass/services/AppAccessMgtService.java
11 11

  
12 12
package my.com.upass.services;
13 13

  
14
import java.util.HashMap;
14 15
import java.util.List;
16
import java.util.Map;
15 17

  
16 18
import my.com.upass.dao.MinimalDAOFactory;
17 19
import my.com.upass.dao.UserDAO;
20
import my.com.upass.maybank.entities.IbccUser;
21
import my.com.upass.maybank.entities.Im2uUser;
22
import my.com.upass.maybank.entities.M2uUser;
23
import my.com.upass.maybank.entities.StockUser;
24
import my.com.upass.maybank.entities.TicketingUser;
25
import my.com.upass.pojo.ClientApp;
18 26
import my.com.upass.pojo.UserAppAccess;
19 27

  
28
import org.hibernate.Session;
29

  
20 30
/**
21 31
 * PROGRAMMER: Hadi
22 32
 * CHANGE-NO:
......
29 39

  
30 40
public class AppAccessMgtService {
31 41

  
32
	public Integer getAppIdForAdmin(String appAccessId) throws MultipleAppAccessesFound {
42
	public static final Map appToProfileMap = createAppToProfileMap();
43
	public static final Map profileToAppMap = createProfileToAppMap();
44

  
45
	//
46

  
47
	private static Map createAppToProfileMap() {
48
		Map map = new HashMap(5);
49
		map.put(ClientApp.APP_ID_M2U, M2uUser.class);
50
		map.put(ClientApp.APP_ID_ONLINE_STOCK, StockUser.class);
51
		map.put(ClientApp.APP_ID_ONLINE_TICKETING, TicketingUser.class);
52
		map.put(ClientApp.APP_ID_CCPP, IbccUser.class);
53
		map.put(ClientApp.APP_ID_IM2U, Im2uUser.class);
54
		return map;
55
	}
56

  
57
	private static Map createProfileToAppMap() {
58
		Map map = new HashMap(5);
59
		map.put(M2uUser.class, ClientApp.APP_ID_M2U);
60
		map.put(StockUser.class, ClientApp.APP_ID_ONLINE_STOCK);
61
		map.put(TicketingUser.class, ClientApp.APP_ID_ONLINE_TICKETING);
62
		map.put(IbccUser.class, ClientApp.APP_ID_CCPP);
63
		map.put(Im2uUser.class, ClientApp.APP_ID_IM2U);
64
		return map;
65
	}
66

  
67
	public Integer getAppIdForAdmin(String appAccessId, Session txSession) throws MultipleAppAccessesFound {
33 68

  
34 69
		Integer appId = null;
35 70
		UserDAO userDao;
36 71
		try {
37 72
			userDao = MinimalDAOFactory.minimalInstance().getUserDAO();
38
			List accessList = userDao.listUserAppAccesses(appAccessId, UserAppAccess.TYPE_ADMIN);
73
			List accessList = userDao.listUserAppAccesses(appAccessId, UserAppAccess.TYPE_ADMIN, txSession);
39 74

  
40 75
			if (accessList.size() > 1)
41 76
				throw new MultipleAppAccessesFound();
......
53 88
	//
54 89

  
55 90
	public class MultipleAppAccessesFound extends Exception {
56

  
91
		private static final long serialVersionUID = 1L;
57 92
	}
58 93
}
src/main/java/my/com/upass/services/CreateUserService.java
21 21
import my.com.upass.pojo.MinimalUserBean;
22 22
import my.com.upass.spassword.PasswordController;
23 23

  
24
import org.hibernate.Session;
25

  
24 26
/**
25 27
 * PROGRAMMER: Danniell
26 28
 * CHANGE-NO:
......
44 46

  
45 47
	public int addUser(
46 48
			String userAlias, int userType, String userDesc,
47
			String userPassword, int userState, int applicationId) {
49
			String userPassword, int userState, int applicationId, Session txSession) {
48 50

  
49 51
		int rc = MinimalConstants.ERR_SYSTEM_NOT_READY;
50 52

  
......
55 57
		try {
56 58
			userDao = MinimalDAOFactory.minimalInstance().getUserDAO();
57 59

  
58
			MinimalUserBean ub = userDao.getUserFromStore(userAlias);
60
			MinimalUserBean ub = userDao.getUserFromStore(userAlias, txSession);
59 61

  
60 62
			if (ub == null) {
61 63
				long nextVal = userDao.getNextSequenceNumber("SEQ_USER_ID_SEQ_VALUE_SEQ");
......
94 96
				// tac.setUpassUser (ub);
95 97
				// ub.setTacbean (tac);
96 98

  
97
				if (userDao.insertUserToStore(ub)) {
99
				if (userDao.insertUserToStore(ub, txSession)) {
98 100
					rc = MinimalConstants.ERR_SUCCESS;
99 101

  
100 102
				} else {
......
109 111
		return rc;
110 112
	}
111 113

  
112
	public int addUser(MinimalUserBean user, int appId) {
113
		return addUser(user.getUserAlias(), user.getUserType(), user.getDescription(),
114
				user.getPcipherText(), user.getPstate(), appId);
114
	public int addUser(
115
			String userAlias, int userType, String userDesc,
116
			String userPassword, int userState, int applicationId) {
117

  
118
		return addUser(userAlias, userType, userDesc, userPassword, userState, applicationId, null);
119
	}
120

  
121
	public int addUser(MinimalUserBean user, int appId, Session txSession) {
122
		return addUser(
123
				user.getUserAlias(), user.getUserType(), user.getDescription(),
124
				user.getPcipherText(), user.getPstate(), appId, txSession);
115 125
	}
116 126
}
src/main/java/my/com/upass/services/ModifyUserService.java
16 16
import my.com.upass.dao.MinimalDAOFactory;
17 17
import my.com.upass.dao.UserDAO;
18 18
import my.com.upass.factory.MinimalUPassFactory;
19
import my.com.upass.maybank.entities.UserProfile;
19 20
import my.com.upass.pojo.MinimalUserBean;
20 21
import my.com.upass.spassword.PasswordController;
21 22

  
23
import org.hibernate.Session;
24

  
22 25
/**
23 26
 * PROGRAMMER: Danniell
24 27
 * CHANGE-NO:
......
54 57

  
55 58
		try {
56 59
			userDao = MinimalDAOFactory.minimalInstance().getUserDAO();
57
			MinimalUserBean ub = userDao.getUserFromStore(userAlias);
60
			MinimalUserBean ub = userDao.getUserFromStore(userAlias, null);
58 61

  
59 62
			if (ub == null) {
60 63
				return MinimalConstants.ERR_USERALIAS_NOT_FOUND;
......
81 84
			ub.setUserType(userType);
82 85
			ub.setUstate(userState);
83 86

  
84
			if (userDao.updateUserToStore(ub)) {
87
			if (userDao.updateUserToStore(ub, null)) {
88
				rc = MinimalConstants.ERR_SUCCESS;
89

  
90
			} else {
91
				rc = MinimalConstants.ERR_UNKNOWN;
92
			}
93
		} catch (Exception e) {
94
			e.printStackTrace();
95
		}
96
		return rc;
97
	}
98

  
99
	public int updateProfileShallowly(UserProfile profile, Session txSession) {
100

  
101
		int rc = MinimalConstants.ERR_SYSTEM_NOT_READY;
102

  
103
		if (profile == null || profile.getMinUser() == null || profile.getMinUser().getUserAlias() == null) {
104
			return MinimalConstants.ERR_INVALID_INPUT;
105
		}
106
		String userAlias = profile.getMinUser().getUserAlias();
107
		try {
108
			final MinimalDAOFactory daoFactory = MinimalDAOFactory.minimalInstance();
109
			final UserDAO userDao = daoFactory.getUserDAO();
110
			MinimalUserBean ub = userDao.getUserFromStore(userAlias, txSession);
111

  
112
			if (ub == null) {
113
				return MinimalConstants.ERR_USERALIAS_NOT_FOUND;
114
			}
115
			profile.getMinUser().setUserID(ub.getUserID());
116
			if (userDao.updateProfileShallowly(profile, txSession)) {
85 117
				rc = MinimalConstants.ERR_SUCCESS;
86 118

  
87 119
			} else {
src/main/java/my/com/upass/services/VerifyStaticPasswordService.java
24 24
import my.com.upass.pojo.MinimalUserBean;
25 25
import my.com.upass.spassword.PasswordController;
26 26

  
27
import org.hibernate.Session;
28

  
27 29
/**
28 30
 * PROGRAMMER: Danniell
29 31
 * CHANGE-NO:
......
45 47
		this.upc = upc;
46 48
	}
47 49

  
50
	public int verifyStaticPassword(
51
			String userAlias, String password,
52
			boolean chkUserType, int userType, Session txSession) {
53

  
54
		return verifyUserCredetial(userAlias, password, chkUserType, userType, false, txSession);
55
	}
56

  
48 57
	/**
49 58
	 * Verify password validity only
50 59
	 * 
......
58 67
			String userAlias, String password,
59 68
			boolean chkUserType, int userType) {
60 69

  
61
		return verifyUserCredetial(userAlias, password, chkUserType, userType, false);
70
		return verifyUserCredetial(userAlias, password, chkUserType, userType, false, null);
62 71
	}
63 72

  
64 73
	/**
......
74 83
			String userAlias, String password,
75 84
			boolean chkUserType, int userType) {
76 85

  
77
		return verifyUserCredetial(userAlias, password, chkUserType, userType, true);
86
		return verifyUserCredetial(userAlias, password, chkUserType, userType, true, null);
78 87
	}
79 88

  
80 89
	/**
......
89 98
	 */
90 99
	public int verifyUserCredetial(
91 100
			String userAlias, String password,
92
			boolean chkUserType, int userType, boolean dormantCheck) {
101
			boolean chkUserType, int userType,
102
			boolean dormantCheck, Session txSession) {
93 103

  
94 104
		int rc = MinimalConstants.ERR_SYSTEM_NOT_READY;
95 105

  
......
99 109

  
100 110
		try {
101 111
			UserDAO userDao = MinimalDAOFactory.minimalInstance().getUserDAO();
102
			MinimalUserBean userBean = userDao.getUserFromStore(userAlias);
112
			MinimalUserBean userBean = userDao.getUserFromStore(userAlias, txSession);
103 113

  
104 114
			if (userBean == null) {
105 115
				return MinimalConstants.ERR_USERALIAS_NOT_FOUND;
......
169 179
				}
170 180
			}
171 181
			// update database
172
			boolean lrc = userDao.updateUserToStore(userBean);
182
			boolean lrc = userDao.updateUserToStore(userBean, txSession);
173 183

  
174 184
			if (!lrc) {
175 185
				rc = MinimalConstants.ERR_SYSTEM_NOT_READY;
src/main/java/net/penril/generic/hibernate/GenericDAO.java
26 26
/**
27 27
 * Represents Base Data Access Object
28 28
 */
29
public interface GenericDAO
30
{
29
public interface GenericDAO {
30

  
31 31
	Object findById(Serializable id, boolean lock) throws Exception;
32
	
33
	List findAll()throws Exception;
34
	
35
	List findByExample(Object exampleInstance, String[] excludeProperty)throws Exception;
36
	
37
	Object makePersistent(Object entity)throws Exception;
38
	
39
	void makeTransient(Object entity)throws Exception;
40
	
41
	void flush()throws Exception;
42
	
43
	void clear()throws Exception;
44
	
32

  
33
	List findAll() throws Exception;
34

  
35
	List findByExample(Object exampleInstance, String[] excludeProperty) throws Exception;
36

  
37
	Object makePersistent(Object entity) throws Exception;
38

  
39
	void makeTransient(Object entity) throws Exception;
40

  
41
	void flush() throws Exception;
42

  
43
	void clear() throws Exception;
44

  
45 45
	long getNextSequenceNumber(String sequenceName) throws Exception;
46
	
46

  
47 47
	long getCurrentSequenceNumber(String sequenceName) throws Exception;
48
	
48

  
49 49
	Class getEntityClass();
50 50
}
src/main/java/net/penril/generic/hibernate/GenericDAOHibernate.java
25 25
import org.hibernate.criterion.Criterion;
26 26
import org.hibernate.criterion.Example;
27 27

  
28
public abstract class GenericDAOHibernate implements GenericDAO 
28
public abstract class GenericDAOHibernate implements GenericDAO
29 29
{
30 30
	private Class persistentClass;
31 31
	private Session session;
32
	
33
	public GenericDAOHibernate() 
32

  
33
	public GenericDAOHibernate()
34 34
	{
35 35
		this.persistentClass = getEntityClass();
36 36
	}
37
	
38
	public void setSession(Session s) 
37

  
38
	public void setSession(Session s)
39 39
	{
40 40
		this.session = s;
41 41
	}
42
	
42

  
43 43
	/**
44 44
	 * 
45 45
	 * Will override the current session
46
	 *
47
	 * @param hibernateCfgPath The Hibernate configuration file path
46
	 * 
47
	 * @param hibernateCfgPath
48
	 *            The Hibernate configuration file path
48 49
	 */
49
	public void setSession(String hibernateCfgPath) 
50
	public void setSession(String hibernateCfgPath)
50 51
	{
51
		HibernateUtils.overrideSession (hibernateCfgPath);
52
		this.session = HibernateUtils.currentSession ();
52
		HibernateUtils.overrideSession(hibernateCfgPath);
53
		this.session = HibernateUtils.currentSession();
53 54
	}
54
	
55
	protected Session getSession() throws Exception 
55

  
56
	protected Session getSession() throws Exception
56 57
	{
57
		if (session == null || session.isOpen () == false)
58
		if (session == null || session.isOpen() == false)
58 59
		{
59 60
			try
60 61
			{
61 62
				session = HibernateUtils.currentSession();
62
			}
63
			catch(Exception e)
63
			} catch (Exception e)
64 64
			{
65 65
				throw e;
66 66
			}
67 67
		}
68 68
		return session;
69 69
	}
70
	
71
	public Class getPersistentClass() 
70

  
71
	public Class getPersistentClass()
72 72
	{
73 73
		return persistentClass;
74 74
	}
75 75

  
76
	public void clear() throws Exception 
76
	public void clear() throws Exception
77 77
	{
78
		getSession ().clear ();
78
		getSession().clear();
79 79
	}
80 80

  
81
	public List findAll() throws Exception 
81
	public List findAll() throws Exception
82 82
	{
83 83
		return findByCriteria(null);
84 84
	}
85 85

  
86
	protected List findByCriteria (Criterion[] criterion) throws Exception
86
	protected List findByCriteria(Criterion[] criterion) throws Exception
87 87
	{
88 88
		Criteria crit = getSession().createCriteria(getPersistentClass());
89
		if(criterion != null)
89
		if (criterion != null)
90 90
		{
91
			for(int i=0; i<criterion.length; i++){
91
			for (int i = 0; i < criterion.length; i++) {
92 92
				crit.add(criterion[0]);
93 93
			}
94 94
		}
95 95
		return crit.list();
96 96
	}
97 97

  
98
	public List findByExample(Object exampleInstance, String[] excludeProperty) throws Exception 
98
	public List findByExample(Object exampleInstance, String[] excludeProperty) throws Exception
99 99
	{
100 100
		Criteria crit = getSession().createCriteria(getPersistentClass());
101 101
		Example example = Example.create(exampleInstance);
102
		
103
		for(int i=0; i<excludeProperty.length; i++){
102

  
103
		for (int i = 0; i < excludeProperty.length; i++) {
104 104
			example.excludeProperty(excludeProperty[0]);
105 105
		}
106
		
106

  
107 107
		crit.add(example);
108 108
		return crit.list();
109 109
	}
110 110

  
111
	public Object findById(Serializable id, boolean lock) throws  Exception 
111
	public Object findById(Serializable id, boolean lock) throws Exception
112 112
	{
113 113
		Object entity;
114 114
		if (lock)
......
122 122
		return entity;
123 123
	}
124 124

  
125
	public void flush() throws  Exception 
125
	public void flush() throws Exception
126 126
	{
127
		getSession ().flush ();
127
		getSession().flush();
128 128
	}
129 129

  
130
	public Object makePersistent(Object entity) throws  Exception 
130
	public Object makePersistent(Object entity) throws Exception
131 131
	{
132 132
		getSession().saveOrUpdate(entity);
133 133
		return entity;
134 134
	}
135 135

  
136
	public void makeTransient(Object entity) throws  Exception 
136
	public void makeTransient(Object entity) throws Exception
137 137
	{
138 138
		getSession().delete(entity);
139 139
	}
140
	
140

  
141 141
	public long getNextSequenceNumber(String sequenceName) throws Exception {
142 142
		BigDecimal nextValue = new BigDecimal(0);
143 143

  
......
160 160
				// TODO: Don't forget to remove the following line!
161 161
				System.out
162 162
						.println("########## Simulating sequences in SQL Server.");
163
				
163

  
164 164
				tx = hSession.beginTransaction();
165 165
				CallableStatement cstmt = conn.prepareCall(//
166 166
						"{call nextval_" + sequenceName + "(?)}");
......
220 220
		System.out.println("########## Current sequence value: " + longValue);
221 221
		return longValue;
222 222
	}
223

  
224
	// Some Utility Methods
225

  
226
	public static void closeSessionIfAny(Session session) {
227
		if (session != null && session.isOpen())
228
			session.close();
229
	}
230

  
231
	public static void rollbackTransactionIfAny(Session session) {
232
		if (session != null && session.isOpen()) {
233
			Transaction tx = session.getTransaction();
234
			if (tx != null && tx.isActive())
235
				tx.rollback();
236
		}
237
	}
223 238
}
src/main/resources/com/ib/hibernate/configuration/hibernate.cfg.xml
44 44
		 
45 45
		<mapping resource="my/com/upass/hibernate/ClientApp.hbm.xml" />
46 46
		<mapping resource="my/com/upass/hibernate/UserAppAccess.hbm.xml" />
47
		<mapping resource="my/com/upass/maybank/entities/hibernate/IbccAdminUser.hbm.xml" />
48
		<mapping resource="my/com/upass/maybank/entities/hibernate/IbccPublicUser.hbm.xml" />
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff