0001 //
0002 // This file is generated by MetaBoss Ver 1.4.0001 at Thu Dec 15 22:36:56 EST 2005
0003 // MetaBoss is Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
0004 // Content of this file is Copyright 2000-2005 © Softaris Pty. Ltd. All Rights Reserved.
0005 // This content is licensed under Open Source Gnu Public License (GPL)
0006 // Full terms and conditions of GPL can be found found at www.gnu.org
0007 //
0008 package com.almamater.crs.domains.courses.storage.mysqlimpl;
0009
0010 import java.util.Set;
0011 import java.util.ArrayList;
0012 import org.apache.commons.logging.Log;
0013 import org.apache.commons.logging.LogFactory;
0014 import com.metaboss.enterprise.datatypes.DataTypeValidationException;
0015 import com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForEmptyInstanceException;
0016 import com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForConcealedInstanceException;
0017 import com.metaboss.enterprise.ps.STCollectionDetails;
0018 import com.metaboss.enterprise.ps.STOrderingDetails;
0019 import com.metaboss.enterprise.ps.PSException;
0020 import com.metaboss.enterprise.ps.PSUnexpectedProgramConditionException;
0021 import com.metaboss.enterprise.ps.PSIllegalArgumentException;
0022 import com.metaboss.enterprise.ps.PSAttributeConstraintViolationException;
0023 import com.metaboss.enterprise.ps.PSAssociationConstraintViolationException;
0024 import com.metaboss.enterprise.ps.PSDataSourceOperationInvocationException;
0025 import com.metaboss.enterprise.ps.PSUpdateDataIntegrityViolationException;
0026 import com.metaboss.enterprise.ps.impl.PSObjectImpl;
0027
0028 public class PSStudentImpl extends PSObjectImpl implements com.almamater.crs.domains.courses.storage.PSStudent{
0029 private static final Log sLogger = LogFactory.getLog(PSStudentImpl.class);
0030 private Object mInstanceIdSemaphore = new Object();
0031 private long mSessionId = 0;
0032 private long mInstanceCount = 0;
0033
0034 /** Constructor. Initialises session Id with the seed value */
0035 public PSStudentImpl() throws PSException
0036 {
0037 mSessionId = Util.getNextAvailableSessionId("e_STUDENT");
0038 if (sLogger.isDebugEnabled())
0039 sLogger.debug("Will generate StudentInstanceId values in format '([a-z0-9]+)-" + Long.toString(mSessionId,Character.MAX_RADIX) + "-rq'");
0040 }
0041
0042 /** Returns next avaialble unique instance id for the new Student record */
0043 public com.almamater.crs.types.system.courses.StudentInstanceId getNextAvailableInstanceId() throws PSException
0044 {
0045 try
0046 {
0047 synchronized(mInstanceIdSemaphore)
0048 {
0049 return com.almamater.crs.types.system.courses.StudentInstanceId.createFromString(Long.toString(mInstanceCount++, Character.MAX_RADIX) + "-" + Long.toString(mSessionId,Character.MAX_RADIX) + "-rq");
0050 }
0051 }
0052 catch(DataTypeValidationException e)
0053 {
0054 throw new PSUnexpectedProgramConditionException("Internally generated instance id has not passed datatype validation", e);
0055 }
0056 }
0057
0058 // Inserts one or more new Student records into the database
0059 public void insert( com.almamater.crs.domains.courses.storage.STStudentRecord[] pNewStudentRecords) throws PSException
0060 {
0061 if (pNewStudentRecords == null)
0062 throw new PSIllegalArgumentException("pNewStudentRecords is not expected to be undefined for insert() operation.");
0063 java.sql.Connection lDatabaseConnection = Util.getConnection();
0064 try
0065 {
0066 insertStudentRecords(lDatabaseConnection, pNewStudentRecords);
0067 }
0068 finally
0069 {
0070 if (lDatabaseConnection != null)
0071 Util.closeConnection(lDatabaseConnection);
0072 }
0073 }
0074
0075 // Updates one or more existing Student records in the database
0076 public void update( com.almamater.crs.domains.courses.storage.STStudentRecord[] pModifiedStudentRecords) throws PSException
0077 {
0078 java.sql.Connection lDatabaseConnection = Util.getConnection();
0079 try
0080 {
0081 updateStudentRecords(lDatabaseConnection, pModifiedStudentRecords);
0082 }
0083 finally
0084 {
0085 if (lDatabaseConnection != null)
0086 Util.closeConnection(lDatabaseConnection);
0087 }
0088 }
0089
0090 // Deletes one or more existing Student records from the database
0091 public void delete( com.almamater.crs.types.system.courses.StudentInstanceId[] pInstanceIdsToDelete) throws PSException
0092 {
0093 java.sql.Connection lDatabaseConnection = Util.getConnection();
0094 try
0095 {
0096 deleteStudentRecords(lDatabaseConnection, pInstanceIdsToDelete);
0097 }
0098 finally
0099 {
0100 if (lDatabaseConnection != null)
0101 Util.closeConnection(lDatabaseConnection);
0102 }
0103 }
0104
0105 // Returns count of entities matching supplied selector matrix.
0106 public com.almamater.types.core.CollectionSize getRecordsCollectionSize( STCollectionDetails[] pCollectionsDetails) throws PSException
0107 {
0108 try
0109 {
0110 java.sql.Connection lDatabaseConnection = Util.getConnection();
0111 try
0112 {
0113 QueryContext lQueryContext = new QueryContext(QueryContext.QueryType.QUERYTYPE_COUNTRECORDS,"e_STUDENT");
0114 Selectors.SqlStatementParts lGeneratedSqlStatementParts = Selectors.getSqlStatementParts(Util.suppressSortingInstruction(pCollectionsDetails),lQueryContext);
0115 StringBuffer lStatementText = new StringBuffer();
0116 lStatementText.append("SELECT COUNT(");
0117 if (lGeneratedSqlStatementParts.needsDistinct())
0118 lStatementText.append("DISTINCT ");
0119 lStatementText.append("rq.recordid");
0120 lStatementText.append(") FROM ");
0121 lStatementText.append(lGeneratedSqlStatementParts.mFromClause);
0122 if (lGeneratedSqlStatementParts.mWhereClause != null && lGeneratedSqlStatementParts.mWhereClause.length() > 0)
0123 {
0124 lStatementText.append(" WHERE ");
0125 lStatementText.append(lGeneratedSqlStatementParts.mWhereClause);
0126 }
0127 if (lGeneratedSqlStatementParts.mOrderByClause != null && lGeneratedSqlStatementParts.mOrderByClause.length() > 0)
0128 {
0129 lStatementText.append(" ORDER BY ");
0130 lStatementText.append(lGeneratedSqlStatementParts.mOrderByClause);
0131 }
0132 if (lGeneratedSqlStatementParts.mLimitClause != null && lGeneratedSqlStatementParts.mLimitClause.length() > 0)
0133 {
0134 lStatementText.append(" LIMIT ");
0135 lStatementText.append(lGeneratedSqlStatementParts.mLimitClause);
0136 }
0137 String lStatementString = lStatementText.toString();
0138 if (sLogger.isDebugEnabled())
0139 sLogger.debug("About to execute SQL statement: " + lStatementString + ";");
0140 java.sql.PreparedStatement lGetCountStatement = lDatabaseConnection.prepareStatement(lStatementString);
0141 try
0142 {
0143 Selectors.populatePreparedStatement(pCollectionsDetails,lGetCountStatement,1);
0144 java.sql.ResultSet lResultSet = lGetCountStatement.executeQuery();
0145 if (lResultSet.next())
0146 {
0147 long lCollectionSize = lResultSet.getLong(1);
0148 if (!lResultSet.wasNull())
0149 return TypesConvertor.createCollectionSizeFromSqlValue(lCollectionSize);
0150 }
0151 return com.almamater.types.core.CollectionSize.createEmpty();
0152 }
0153 finally
0154 {
0155 if (lGetCountStatement != null)
0156 lGetCountStatement.close();
0157 }
0158 }
0159 finally
0160 {
0161 if (lDatabaseConnection != null)
0162 Util.closeConnection(lDatabaseConnection);
0163 }
0164 }
0165 catch(java.sql.SQLException e)
0166 {
0167 throw new PSDataSourceOperationInvocationException("Error in getRecordsCollectionSize(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
0168 }
0169 }
0170
0171 // Returns all entities matching supplied selector matrix.
0172 public com.almamater.crs.domains.courses.storage.STStudentRecord[] getAllRecords( STCollectionDetails[] pCollectionsDetails) throws PSException
0173 {
0174 try
0175 {
0176 java.sql.Connection lDatabaseConnection = Util.getConnection();
0177 try
0178 {
0179 QueryContext lQueryContext = new QueryContext(QueryContext.QueryType.QUERYTYPE_GETALLRECORDS,"e_STUDENT");
0180 Selectors.SqlStatementParts lGeneratedSqlStatementParts = Selectors.getSqlStatementParts(pCollectionsDetails,lQueryContext);
0181 StringBuffer lStatementText = new StringBuffer();
0182 lStatementText.append("SELECT ");
0183 if (lGeneratedSqlStatementParts.needsDistinct())
0184 lStatementText.append("DISTINCT ");
0185 lStatementText.append(lGeneratedSqlStatementParts.getWhatClause());
0186 if (lGeneratedSqlStatementParts.mFromClause != null && lGeneratedSqlStatementParts.mFromClause.length() > 0)
0187 {
0188 lStatementText.append(" FROM ");
0189 lStatementText.append(lGeneratedSqlStatementParts.mFromClause);
0190 }
0191 if (lGeneratedSqlStatementParts.mWhereClause != null && lGeneratedSqlStatementParts.mWhereClause.length() > 0)
0192 {
0193 lStatementText.append(" WHERE ");
0194 lStatementText.append(lGeneratedSqlStatementParts.mWhereClause);
0195 }
0196 if (lGeneratedSqlStatementParts.mOrderByClause != null && lGeneratedSqlStatementParts.mOrderByClause.length() > 0)
0197 {
0198 lStatementText.append(" ORDER BY ");
0199 lStatementText.append(lGeneratedSqlStatementParts.mOrderByClause);
0200 }
0201 if (lGeneratedSqlStatementParts.mLimitClause != null && lGeneratedSqlStatementParts.mLimitClause.length() > 0)
0202 {
0203 lStatementText.append(" LIMIT ");
0204 lStatementText.append(lGeneratedSqlStatementParts.mLimitClause);
0205 }
0206 String lStatementString = lStatementText.toString();
0207 if (sLogger.isDebugEnabled())
0208 sLogger.debug("About to execute SQL statement: " + lStatementString + ";");
0209 java.sql.PreparedStatement lGetAllRecordsStatement = lDatabaseConnection.prepareStatement(lStatementString);
0210 try
0211 {
0212 Selectors.populatePreparedStatement(pCollectionsDetails,lGetAllRecordsStatement,1);
0213 java.sql.ResultSet lResultSet = lGetAllRecordsStatement.executeQuery();
0214 try
0215 {
0216 ArrayList lReturnedRecords = new ArrayList();
0217 while(lResultSet.next())
0218 lReturnedRecords.add(unpackRecordFromResultSet(lResultSet));
0219 return (com.almamater.crs.domains.courses.storage.STStudentRecord[])lReturnedRecords.toArray( new com.almamater.crs.domains.courses.storage.STStudentRecord[lReturnedRecords.size()]);
0220 }
0221 finally
0222 {
0223 if (lResultSet != null)
0224 lResultSet.close();
0225 }
0226 }
0227 finally
0228 {
0229 if (lGetAllRecordsStatement != null)
0230 lGetAllRecordsStatement.close();
0231 }
0232 }
0233 finally
0234 {
0235 if (lDatabaseConnection != null)
0236 Util.closeConnection(lDatabaseConnection);
0237 }
0238 }
0239 catch(java.sql.SQLException e)
0240 {
0241 throw new PSDataSourceOperationInvocationException("Error on getAllRecords(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
0242 }
0243 }
0244
0245 // Returns instance ids of all entities matching supplied selector matrix.
0246 public com.almamater.crs.types.system.courses.StudentInstanceId[] getAllInstanceIds( STCollectionDetails[] pCollectionsDetails) throws PSException
0247 {
0248 try
0249 {
0250 java.sql.Connection lDatabaseConnection = Util.getConnection();
0251 try
0252 {
0253 QueryContext lQueryContext = new QueryContext(QueryContext.QueryType.QUERYTYPE_GETALLRECORDIDS,"e_STUDENT");
0254 Selectors.SqlStatementParts lGeneratedSqlStatementParts = Selectors.getSqlStatementParts(pCollectionsDetails,lQueryContext);
0255 StringBuffer lStatementText = new StringBuffer();
0256 lStatementText.append("SELECT ");
0257 if (lGeneratedSqlStatementParts.needsDistinct())
0258 lStatementText.append("DISTINCT ");
0259 lStatementText.append(lGeneratedSqlStatementParts.getWhatClause());
0260 lStatementText.append(" FROM ");
0261 lStatementText.append(lGeneratedSqlStatementParts.mFromClause);
0262 if (lGeneratedSqlStatementParts.mWhereClause != null && lGeneratedSqlStatementParts.mWhereClause.length() > 0)
0263 {
0264 lStatementText.append(" WHERE ");
0265 lStatementText.append(lGeneratedSqlStatementParts.mWhereClause);
0266 }
0267 if (lGeneratedSqlStatementParts.mOrderByClause != null && lGeneratedSqlStatementParts.mOrderByClause.length() > 0)
0268 {
0269 lStatementText.append(" ORDER BY ");
0270 lStatementText.append(lGeneratedSqlStatementParts.mOrderByClause);
0271 }
0272 if (lGeneratedSqlStatementParts.mLimitClause != null && lGeneratedSqlStatementParts.mLimitClause.length() > 0)
0273 {
0274 lStatementText.append(" LIMIT ");
0275 lStatementText.append(lGeneratedSqlStatementParts.mLimitClause);
0276 }
0277 String lStatementString = lStatementText.toString();
0278 if (sLogger.isDebugEnabled())
0279 sLogger.debug("About to execute SQL statement: " + lStatementString + ";");
0280 java.sql.PreparedStatement lGetAllInstanceIdsStatement = lDatabaseConnection.prepareStatement(lStatementString);
0281 try
0282 {
0283 Selectors.populatePreparedStatement(pCollectionsDetails,lGetAllInstanceIdsStatement,1);
0284 java.sql.ResultSet lResultSet = lGetAllInstanceIdsStatement.executeQuery();
0285 try
0286 {
0287 ArrayList lReturnedIds = new ArrayList();
0288 while(lResultSet.next())
0289 lReturnedIds.add( lResultSet.getString(1));
0290 return (com.almamater.crs.types.system.courses.StudentInstanceId[])lReturnedIds.toArray( new com.almamater.crs.types.system.courses.StudentInstanceId[lReturnedIds.size()]);
0291 }
0292 finally
0293 {
0294 if (lResultSet != null)
0295 lResultSet.close();
0296 }
0297 }
0298 finally
0299 {
0300 if (lGetAllInstanceIdsStatement != null)
0301 lGetAllInstanceIdsStatement.close();
0302 }
0303 }
0304 finally
0305 {
0306 if (lDatabaseConnection != null)
0307 Util.closeConnection(lDatabaseConnection);
0308 }
0309 }
0310 catch(java.sql.SQLException e)
0311 {
0312 throw new PSDataSourceOperationInvocationException("Error on getAllRecords(com.almamater.crs.domains.courses.storage.STStudentRecord)", e); }
0313 }
0314
0315 // Retrieves Student record by its instance id
0316 public com.almamater.crs.domains.courses.storage.STStudentRecord getByInstanceId( com.almamater.crs.types.system.courses.StudentInstanceId pInstanceId, STCollectionDetails[] pCollectionsDetails) throws PSException
0317 {
0318 if (pInstanceId == null)
0319 throw new PSException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be null for getByInstanceId() operation.");
0320 if (pInstanceId.isEmpty())
0321 throw new PSException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be empty for getByInstanceId() operation.");
0322 if (pInstanceId.isConcealed())
0323 throw new PSException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be concealed for getByInstanceId() operation.");
0324 try
0325 {
0326 java.sql.Connection lDatabaseConnection = Util.getConnection();
0327 try
0328 {
0329 QueryContext lQueryContext = new QueryContext(QueryContext.QueryType.QUERYTYPE_GETSINGLERECORD,"e_STUDENT");
0330 Selectors.SqlStatementParts lGeneratedSqlStatementParts = Selectors.getSqlStatementParts(pCollectionsDetails,lQueryContext);
0331 StringBuffer lStatementText = new StringBuffer();
0332 lStatementText.append("SELECT rq.recordid,rq.versionid,rq.STUDENT_NO,rq.FIRST_NAME,rq.SECOND_NAME,rq.FAMILY_NAME,rq.DATE_OF_BIRTH FROM ");
0333 lStatementText.append(lGeneratedSqlStatementParts.mFromClause);
0334 lStatementText.append(" WHERE rq.recordid = ?");
0335 if (lGeneratedSqlStatementParts.mWhereClause != null && lGeneratedSqlStatementParts.mWhereClause.length() > 0)
0336 {
0337 // If there is a where clause - there are possibly some arguments too
0338 lStatementText.append(" AND ");
0339 lStatementText.append(lGeneratedSqlStatementParts.mWhereClause);
0340 }
0341 String lStatementString = lStatementText.toString();
0342 if (sLogger.isDebugEnabled())
0343 sLogger.debug("About to execute SQL statement: " + lStatementString + ";");
0344 java.sql.PreparedStatement lGetByInstanceIdStatement = lDatabaseConnection.prepareStatement(lStatementString);
0345 try
0346 {
0347 lGetByInstanceIdStatement.setString( 1, TypesConvertor.getSqlValueFromStudentInstanceId(pInstanceId));
0348 Selectors.populatePreparedStatement(pCollectionsDetails,lGetByInstanceIdStatement,2);
0349 java.sql.ResultSet lResultSet = lGetByInstanceIdStatement.executeQuery();
0350 try
0351 {
0352 if(lResultSet.next())
0353 return unpackRecordFromResultSet(lResultSet);
0354 return null;
0355 }
0356 finally
0357 {
0358 if (lResultSet != null)
0359 lResultSet.close();
0360 }
0361 }
0362 finally
0363 {
0364 if (lGetByInstanceIdStatement != null)
0365 lGetByInstanceIdStatement.close();
0366 }
0367 }
0368 finally
0369 {
0370 if (lDatabaseConnection != null)
0371 Util.closeConnection(lDatabaseConnection);
0372 }
0373 }
0374 catch(DataTypeInvalidOperationForEmptyInstanceException e)
0375 {
0376 throw new PSUnexpectedProgramConditionException("Should not occur as generated code checks for empty instance",e);
0377 }
0378 catch(DataTypeInvalidOperationForConcealedInstanceException e)
0379 {
0380 throw new PSUnexpectedProgramConditionException("Should not occur as generated code checks for concealed instance",e);
0381 }
0382 catch(java.sql.SQLException e)
0383 {
0384 throw new PSDataSourceOperationInvocationException("Error on getByInstanceId(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
0385 }
0386 }
0387
0388 // Retrieves Student record by primary key
0389 public com.almamater.crs.domains.courses.storage.STStudentRecord getByPrimaryKey( com.almamater.types.core.StudentNumber pStudentStudentNo, STCollectionDetails[] pCollectionsDetails) throws PSException
0390 {
0391 if (pStudentStudentNo == null)
0392 throw new PSException("Parameter pStudentStudentNo is not expected to be null for getByPrimaryKey() operation.");
0393 if (pStudentStudentNo.isEmpty())
0394 throw new PSException("Parameter pStudentStudentNo is not expected to be empty for getByInstanceId() operation.");
0395 if (pStudentStudentNo.isConcealed())
0396 throw new PSException("Parameter pStudentStudentNo is not expected to be concealed for getByInstanceId() operation.");
0397 try
0398 {
0399 java.sql.Connection lDatabaseConnection = Util.getConnection();
0400 try
0401 {
0402 StringBuffer lPrimaryKeyWhereText = new StringBuffer();
0403 QueryContext lQueryContext = new QueryContext(QueryContext.QueryType.QUERYTYPE_GETSINGLERECORD,"e_STUDENT");
0404 lPrimaryKeyWhereText.append(lQueryContext.getCurrentToTableAlias());
0405 lPrimaryKeyWhereText.append(".STUDENT_NO = ? ");
0406 Selectors.SqlStatementParts lGeneratedSqlStatementParts = Selectors.getSqlStatementParts(pCollectionsDetails, lQueryContext);
0407 StringBuffer lStatementText = new StringBuffer();
0408 lStatementText.append("SELECT rq.recordid,rq.versionid,rq.STUDENT_NO,rq.FIRST_NAME,rq.SECOND_NAME,rq.FAMILY_NAME,rq.DATE_OF_BIRTH FROM ");
0409 lStatementText.append(lGeneratedSqlStatementParts.mFromClause);
0410 lStatementText.append(" WHERE ");
0411 lStatementText.append(lPrimaryKeyWhereText.toString());
0412 if (lGeneratedSqlStatementParts.mWhereClause != null && lGeneratedSqlStatementParts.mWhereClause.length() > 0)
0413 {
0414 // If there is a where clause - there are possibly some arguments too
0415 lStatementText.append(" AND ");
0416 lStatementText.append(lGeneratedSqlStatementParts.mWhereClause);
0417 }
0418 String lStatementString = lStatementText.toString();
0419 if (sLogger.isDebugEnabled())
0420 sLogger.debug("About to execute SQL statement: " + lStatementString + ";");
0421 java.sql.PreparedStatement lGetByPrimaryKeyStatement = lDatabaseConnection.prepareStatement(lStatementString);
0422 try
0423 {
0424 lGetByPrimaryKeyStatement.setInt( 1, TypesConvertor.getSqlValueFromStudentNumber(pStudentStudentNo));
0425 Selectors.populatePreparedStatement(pCollectionsDetails,lGetByPrimaryKeyStatement,2);
0426 java.sql.ResultSet lResultSet = lGetByPrimaryKeyStatement.executeQuery();
0427 try
0428 {
0429 if(lResultSet.next())
0430 return unpackRecordFromResultSet(lResultSet);
0431 return null;
0432 }
0433 finally
0434 {
0435 if (lResultSet != null)
0436 lResultSet.close();
0437 }
0438 }
0439 finally
0440 {
0441 if (lGetByPrimaryKeyStatement != null)
0442 lGetByPrimaryKeyStatement.close();
0443 }
0444 }
0445 finally
0446 {
0447 if (lDatabaseConnection != null)
0448 Util.closeConnection(lDatabaseConnection);
0449 }
0450 }
0451 catch(DataTypeInvalidOperationForEmptyInstanceException e)
0452 {
0453 throw new PSUnexpectedProgramConditionException("Should not occur as generated code checks for empty instance",e);
0454 }
0455 catch(DataTypeInvalidOperationForConcealedInstanceException e)
0456 {
0457 throw new PSUnexpectedProgramConditionException("Should not occur as generated code checks for concealed instance",e);
0458 }
0459 catch(java.sql.SQLException e)
0460 {
0461 throw new PSDataSourceOperationInvocationException("Error on getByPrimaryKey(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
0462 }
0463 }
0464
0465 private static final String sTextOfInsertCoursesStatement = "INSERT INTO a_STUDENT_ENROLLS_INTO_COURSE ( r_COURSE, r_ATTENDEE) VALUES ( ?, ?)";
0466
0467 /* Inserts one or more new StudentEnrollsIntoCourse association records into the database */
0468 public void insertCourses( com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation[] pNewCourses) throws PSException
0469 {
0470 try
0471 {
0472 java.sql.Connection lDatabaseConnection = Util.getConnection();
0473 try
0474 {
0475 if (sLogger.isDebugEnabled())
0476 sLogger.debug("About to execute SQL statement: " + sTextOfInsertCoursesStatement + ";");
0477 java.sql.PreparedStatement lStatement = lDatabaseConnection.prepareStatement(sTextOfInsertCoursesStatement);
0478 try
0479 {
0480 for (int i = 0; i < pNewCourses.length; i++)
0481 {
0482 com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation lNewAssociationRecord = pNewCourses[i];
0483 if (lNewAssociationRecord.CourseInstanceId == null)
0484 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.CourseInstanceId is not expected to be undefined for insertCourses() operation.");
0485 if (lNewAssociationRecord.CourseInstanceId.isEmpty())
0486 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.CourseInstanceId is not expected to be empty for insertCourses() operation.");
0487 if (lNewAssociationRecord.CourseInstanceId.isConcealed())
0488 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.CourseInstanceId is not expected to be concealed for insertCourses() operation.");
0489 if (sLogger.isDebugEnabled())
0490 sLogger.debug("Parameter 1 value: " + lNewAssociationRecord.CourseInstanceId);
0491 lStatement.setString( 1, TypesConvertor.getSqlValueFromCourseInstanceId(lNewAssociationRecord.CourseInstanceId));
0492 if (lNewAssociationRecord.AttendeeInstanceId == null)
0493 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.AttendeeInstanceId is not expected to be undefined for insertCourses() operation.");
0494 if (lNewAssociationRecord.AttendeeInstanceId.isEmpty())
0495 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.AttendeeInstanceId is not expected to be empty for insertCourses() operation.");
0496 if (lNewAssociationRecord.AttendeeInstanceId.isConcealed())
0497 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.AttendeeInstanceId is not expected to be concealed for insertCourses() operation.");
0498 if (sLogger.isDebugEnabled())
0499 sLogger.debug("Parameter 2 value: " + lNewAssociationRecord.AttendeeInstanceId);
0500 lStatement.setString( 2, TypesConvertor.getSqlValueFromStudentInstanceId(lNewAssociationRecord.AttendeeInstanceId));
0501 lStatement.addBatch();
0502 }
0503 lStatement.executeBatch();
0504 lStatement.close();
0505 lStatement = null;
0506 }
0507 finally
0508 {
0509 if (lStatement != null)
0510 lStatement.close();
0511 }
0512 }
0513 finally
0514 {
0515 if (lDatabaseConnection != null)
0516 Util.closeConnection(lDatabaseConnection);
0517 }
0518 }
0519 catch(DataTypeInvalidOperationForEmptyInstanceException e)
0520 {
0521 throw new PSUnexpectedProgramConditionException("Should not occur as generated code must check for empty instance",e);
0522 }
0523 catch(DataTypeInvalidOperationForConcealedInstanceException e)
0524 {
0525 throw new PSUnexpectedProgramConditionException("Should not occur as generated code must check for concealed instance",e);
0526 }
0527 catch(java.sql.SQLException e)
0528 {
0529 throw new PSDataSourceOperationInvocationException("Error on insert(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
0530 }
0531 }
0532
0533
0534 private static final String sTextOfDeleteCoursesStatement = "DELETE FROM a_STUDENT_ENROLLS_INTO_COURSE WHERE r_COURSE = ? AND r_ATTENDEE = ?";
0535
0536 /* Removes one or more existing StudentEnrollsIntoCourse association records from the database */
0537 public void removeCourses( com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation[] pOldCourses) throws PSException
0538 {
0539 try
0540 {
0541 java.sql.Connection lDatabaseConnection = Util.getConnection();
0542 try
0543 {
0544 if (sLogger.isDebugEnabled())
0545 sLogger.debug("About to execute SQL statement: " + sTextOfDeleteCoursesStatement + ";");
0546 java.sql.PreparedStatement lStatement = lDatabaseConnection.prepareStatement(sTextOfDeleteCoursesStatement);
0547 try
0548 {
0549 for (int i = 0; i < pOldCourses.length; i++)
0550 {
0551 com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation lOldAssociationRecord = pOldCourses[i];
0552 if (lOldAssociationRecord.CourseInstanceId == null)
0553 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.CourseInstanceId is not expected to be undefined for insertCourses() operation.");
0554 if (lOldAssociationRecord.CourseInstanceId.isEmpty())
0555 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.CourseInstanceId is not expected to be empty for insertCourses() operation.");
0556 if (lOldAssociationRecord.CourseInstanceId.isConcealed())
0557 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.CourseInstanceId is not expected to be concealed for insertCourses() operation.");
0558 if (sLogger.isDebugEnabled())
0559 sLogger.debug("Parameter 1 value: " + lOldAssociationRecord.CourseInstanceId);
0560 lStatement.setString( 1, TypesConvertor.getSqlValueFromCourseInstanceId(lOldAssociationRecord.CourseInstanceId));
0561 if (lOldAssociationRecord.AttendeeInstanceId == null)
0562 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.AttendeeInstanceId is not expected to be undefined for insertCourses() operation.");
0563 if (lOldAssociationRecord.AttendeeInstanceId.isEmpty())
0564 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.AttendeeInstanceId is not expected to be empty for insertCourses() operation.");
0565 if (lOldAssociationRecord.AttendeeInstanceId.isConcealed())
0566 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation.AttendeeInstanceId is not expected to be concealed for insertCourses() operation.");
0567 if (sLogger.isDebugEnabled())
0568 sLogger.debug("Parameter 2 value: " + lOldAssociationRecord.AttendeeInstanceId);
0569 lStatement.setString( 2, TypesConvertor.getSqlValueFromStudentInstanceId(lOldAssociationRecord.AttendeeInstanceId));
0570 lStatement.addBatch();
0571 }
0572 lStatement.executeBatch();
0573 lStatement.close();
0574 lStatement = null;
0575 }
0576 finally
0577 {
0578 if (lStatement != null)
0579 lStatement.close();
0580 }
0581 }
0582 finally
0583 {
0584 if (lDatabaseConnection != null)
0585 Util.closeConnection(lDatabaseConnection);
0586 }
0587 }
0588 catch(DataTypeInvalidOperationForEmptyInstanceException e)
0589 {
0590 throw new PSUnexpectedProgramConditionException("Should not occur as generated code must check for empty instance",e);
0591 }
0592 catch(DataTypeInvalidOperationForConcealedInstanceException e)
0593 {
0594 throw new PSUnexpectedProgramConditionException("Should not occur as generated code must check for concealed instance",e);
0595 }
0596 catch(java.sql.SQLException e)
0597 {
0598 throw new PSDataSourceOperationInvocationException("Error on insert(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
0599 }
0600 }
0601
0602 // Helper. Retrieves single Student record from the supplied ResultSet
0603 private com.almamater.crs.domains.courses.storage.STStudentRecord unpackRecordFromResultSet( java.sql.ResultSet pResultSet) throws PSException
0604 {
0605 try
0606 {
0607 com.almamater.crs.domains.courses.storage.STStudentRecord lRecord = new com.almamater.crs.domains.courses.storage.STStudentRecord();
0608 int lParameterIndex = 1;
0609 java.lang.String lInstanceId = pResultSet.getString(lParameterIndex++);
0610 if (!pResultSet.wasNull())
0611 lRecord.InstanceId = TypesConvertor.createStudentInstanceIdFromSqlValue(lInstanceId);
0612 else
0613 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be null in database.");
0614 long lVersionId = pResultSet.getLong(lParameterIndex++);
0615 if (!pResultSet.wasNull())
0616 lRecord.VersionId = TypesConvertor.createStudentVersionIdFromSqlValue(lVersionId);
0617 else
0618 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.VersionId is not expected to be null in database.");
0619 int lStudentNo = pResultSet.getInt(lParameterIndex++);
0620 if (!pResultSet.wasNull())
0621 lRecord.StudentNo = TypesConvertor.createStudentNumberFromSqlValue( lStudentNo);
0622 else
0623 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.StudentNo is not expected to be null in database.");
0624 java.lang.String lFirstName = pResultSet.getString(lParameterIndex++);
0625 if (!pResultSet.wasNull())
0626 lRecord.FirstName = TypesConvertor.createPersonNameFromSqlValue( lFirstName);
0627 else
0628 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FirstName is not expected to be null in database.");
0629 java.lang.String lSecondName = pResultSet.getString(lParameterIndex++);
0630 if (!pResultSet.wasNull())
0631 lRecord.SecondName = TypesConvertor.createPersonNameFromSqlValue( lSecondName);
0632 else
0633 lRecord.SecondName = com.almamater.types.core.PersonName.createEmpty();
0634 java.lang.String lFamilyName = pResultSet.getString(lParameterIndex++);
0635 if (!pResultSet.wasNull())
0636 lRecord.FamilyName = TypesConvertor.createPersonNameFromSqlValue( lFamilyName);
0637 else
0638 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FamilyName is not expected to be null in database.");
0639 java.sql.Date lDateOfBirth = pResultSet.getDate(lParameterIndex++);
0640 if (!pResultSet.wasNull())
0641 lRecord.DateOfBirth = TypesConvertor.createDateFieldFromSqlValue( lDateOfBirth);
0642 else
0643 lRecord.DateOfBirth = com.almamater.types.core.DateField.createEmpty();
0644 return lRecord;
0645 }
0646 catch(java.sql.SQLException e)
0647 {
0648 throw new PSDataSourceOperationInvocationException("Error unpacking the com.almamater.crs.domains.courses.storage.STStudentRecord from the java.sql.ResultSet", e);
0649 }
0650 }
0651
0652 // Inserts one or more new Student records into the database
0653 private void insertStudentRecords( java.sql.Connection pConnection, com.almamater.crs.domains.courses.storage.STStudentRecord[] pNewRecords) throws PSException
0654 {
0655 try
0656 {
0657 java.sql.PreparedStatement lCurrentStatement = null;
0658 String lCurrentTextOfInsertStatement = null;
0659 try
0660 {
0661 StringBuffer lProposedTextOfInsert = new StringBuffer();
0662 StringBuffer lProposedTextOfValues = new StringBuffer();
0663 for (int i = 0; i < pNewRecords.length; i++)
0664 {
0665 lProposedTextOfInsert.setLength(0);
0666 lProposedTextOfInsert.append("INSERT INTO e_STUDENT (");
0667 lProposedTextOfValues.setLength(0);
0668 lProposedTextOfValues.append(") VALUES (");
0669 com.almamater.crs.domains.courses.storage.STStudentRecord lNewRecord = pNewRecords[i];
0670 if (lNewRecord.InstanceId == null)
0671 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be undefined for insert() operation.");
0672 if (lNewRecord.InstanceId.isEmpty())
0673 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be empty for insert() operation.");
0674 if (lNewRecord.InstanceId.isConcealed())
0675 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be concealed for insert() operation.");
0676 lProposedTextOfInsert.append("recordid");
0677 lProposedTextOfValues.append("?");
0678 // VersionId is mandatory and must be the initial version
0679 if (lNewRecord.VersionId == null)
0680 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.VersionId is not expected to be undefined for insert() operation.");
0681 if (lNewRecord.VersionId.isEmpty())
0682 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.VersionId is not expected to be empty for insert() operation.");
0683 if (lNewRecord.VersionId.isConcealed())
0684 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.VersionId is not expected to be concealed for insert() operation.");
0685 if (!lNewRecord.VersionId.isInitial())
0686 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.VersionId expected to be '" + com.almamater.crs.types.system.courses.StudentVersionId.createInitial() + "' for insert() operation. Version id '" + lNewRecord.VersionId + "' is not valid for insert() operation.");
0687 lProposedTextOfInsert.append(",versionid");
0688 lProposedTextOfValues.append(",?");
0689 // StudentNo is mandatory
0690 if (lNewRecord.StudentNo == null)
0691 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.StudentNo is not expected to be undefined for insert() operation.");
0692 if (lNewRecord.StudentNo.isEmpty())
0693 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.StudentNo is not expected to be empty for insert() operation.");
0694 if (lNewRecord.StudentNo.isConcealed())
0695 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.StudentNo is not expected to be concealed for insert() operation.");
0696 lProposedTextOfInsert.append(",STUDENT_NO");
0697 lProposedTextOfValues.append(",?");
0698 // FirstName is mandatory
0699 if (lNewRecord.FirstName == null)
0700 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FirstName is not expected to be undefined for insert() operation.");
0701 if (lNewRecord.FirstName.isEmpty())
0702 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FirstName is not expected to be empty for insert() operation.");
0703 if (lNewRecord.FirstName.isConcealed())
0704 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FirstName is not expected to be concealed for insert() operation.");
0705 lProposedTextOfInsert.append(",FIRST_NAME");
0706 lProposedTextOfValues.append(",?");
0707 // SecondName is optional
0708 if (lNewRecord.SecondName != null && lNewRecord.SecondName.isEmpty() == false)
0709 {
0710 if (lNewRecord.SecondName.isConcealed())
0711 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.SecondName is not expected to be concealed for insert() operation.");
0712 lProposedTextOfInsert.append(",SECOND_NAME");
0713 lProposedTextOfValues.append(",?");
0714 }
0715 // FamilyName is mandatory
0716 if (lNewRecord.FamilyName == null)
0717 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FamilyName is not expected to be undefined for insert() operation.");
0718 if (lNewRecord.FamilyName.isEmpty())
0719 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FamilyName is not expected to be empty for insert() operation.");
0720 if (lNewRecord.FamilyName.isConcealed())
0721 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FamilyName is not expected to be concealed for insert() operation.");
0722 lProposedTextOfInsert.append(",FAMILY_NAME");
0723 lProposedTextOfValues.append(",?");
0724 // DateOfBirth is optional
0725 if (lNewRecord.DateOfBirth != null && lNewRecord.DateOfBirth.isEmpty() == false)
0726 {
0727 if (lNewRecord.DateOfBirth.isConcealed())
0728 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.DateOfBirth is not expected to be concealed for insert() operation.");
0729 lProposedTextOfInsert.append(",DATE_OF_BIRTH");
0730 lProposedTextOfValues.append(",?");
0731 }
0732 String lProposedTextOfInsertStatement = lProposedTextOfInsert.toString() + lProposedTextOfValues.toString() + ")";
0733 if (lCurrentStatement != null)
0734 {
0735 if (!lCurrentTextOfInsertStatement.equals(lProposedTextOfInsertStatement))
0736 {
0737 lCurrentStatement.executeBatch();
0738 lCurrentStatement.close();
0739 lCurrentStatement = null;
0740 }
0741 }
0742 if (lCurrentStatement == null)
0743 {
0744 lCurrentTextOfInsertStatement = lProposedTextOfInsertStatement;
0745 if (sLogger.isDebugEnabled())
0746 sLogger.debug("About to execute SQL statement: " + lCurrentTextOfInsertStatement + ";");
0747 lCurrentStatement = pConnection.prepareStatement(lCurrentTextOfInsertStatement);
0748 }
0749 int lParameterIndex = 1;
0750 if (sLogger.isDebugEnabled())
0751 sLogger.debug("Parameter " + lParameterIndex + " value: " + lNewRecord.InstanceId);
0752 lCurrentStatement.setString( lParameterIndex++, TypesConvertor.getSqlValueFromStudentInstanceId(lNewRecord.InstanceId));
0753 if (sLogger.isDebugEnabled())
0754 sLogger.debug("Parameter " + lParameterIndex + " value: " + lNewRecord.VersionId);
0755 lCurrentStatement.setLong(lParameterIndex++, TypesConvertor.getSqlValueFromStudentVersionId(lNewRecord.VersionId));
0756 if (sLogger.isDebugEnabled())
0757 sLogger.debug("Parameter " + lParameterIndex + " value: " + com.metaboss.util.StringUtils.suggestTruncatedOutput(lNewRecord.StudentNo.toString(),30));
0758 lCurrentStatement.setInt(lParameterIndex++, TypesConvertor.getSqlValueFromStudentNumber(lNewRecord.StudentNo));
0759 if (sLogger.isDebugEnabled())
0760 sLogger.debug("Parameter " + lParameterIndex + " value: " + com.metaboss.util.StringUtils.suggestTruncatedOutput(lNewRecord.FirstName.toString(),30));
0761 lCurrentStatement.setString(lParameterIndex++, TypesConvertor.getSqlValueFromPersonName(lNewRecord.FirstName));
0762 if (lNewRecord.SecondName != null && lNewRecord.SecondName.isEmpty() == false)
0763 {
0764 if (sLogger.isDebugEnabled())
0765 sLogger.debug("Parameter " + lParameterIndex + " value: " + com.metaboss.util.StringUtils.suggestTruncatedOutput(lNewRecord.SecondName.toString(),30));
0766 lCurrentStatement.setString(lParameterIndex++, TypesConvertor.getSqlValueFromPersonName(lNewRecord.SecondName));
0767 }
0768 if (sLogger.isDebugEnabled())
0769 sLogger.debug("Parameter " + lParameterIndex + " value: " + com.metaboss.util.StringUtils.suggestTruncatedOutput(lNewRecord.FamilyName.toString(),30));
0770 lCurrentStatement.setString(lParameterIndex++, TypesConvertor.getSqlValueFromPersonName(lNewRecord.FamilyName));
0771 if (lNewRecord.DateOfBirth != null && lNewRecord.DateOfBirth.isEmpty() == false)
0772 {
0773 if (sLogger.isDebugEnabled())
0774 sLogger.debug("Parameter " + lParameterIndex + " value: " + com.metaboss.util.StringUtils.suggestTruncatedOutput(lNewRecord.DateOfBirth.toString(),30));
0775 lCurrentStatement.setDate(lParameterIndex++, TypesConvertor.getSqlValueFromDateField(lNewRecord.DateOfBirth));
0776 }
0777 lCurrentStatement.addBatch();
0778 }
0779 lCurrentStatement.executeBatch();
0780 lCurrentStatement.close();
0781 lCurrentStatement = null;
0782 }
0783 finally
0784 {
0785 if (lCurrentStatement != null)
0786 lCurrentStatement.close();
0787 }
0788 }
0789 catch(DataTypeInvalidOperationForEmptyInstanceException e)
0790 {
0791 throw new PSUnexpectedProgramConditionException("Should not occur as generated code must check for empty instance",e);
0792 }
0793 catch(DataTypeInvalidOperationForConcealedInstanceException e)
0794 {
0795 throw new PSUnexpectedProgramConditionException("Should not occur as generated code must check for concealed instance",e);
0796 }
0797 catch(java.sql.SQLException e)
0798 {
0799 String lMessage = e.getMessage();
0800 if (lMessage != null)
0801 {
0802 lMessage = lMessage.trim();
0803 if (lMessage.startsWith("INSERT on table 'E_STUDENT' caused a violation of foreign key constraint '"))
0804 throw new PSAssociationConstraintViolationException("Error on insert(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
0805 if (lMessage.startsWith("The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint"))
0806 throw new PSAttributeConstraintViolationException("Error on insert(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
0807 }
0808 throw new PSDataSourceOperationInvocationException("Error on insert(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
0809 }
0810 }
0811
0812 // Helper. Deletes one or more Student records from the database
0813 private static final String sTextOfStudentDeleteStatement = "DELETE FROM e_STUDENT WHERE recordid = ?";
0814 private void deleteStudentRecords( java.sql.Connection pConnection, com.almamater.crs.types.system.courses.StudentInstanceId[] pInstanceIdsToDelete) throws PSException
0815 {
0816 java.sql.PreparedStatement lDeleteStatement = null;
0817 try
0818 {
0819 if (sLogger.isDebugEnabled())
0820 sLogger.debug("About to execute SQL statement: " + sTextOfStudentDeleteStatement + ";");
0821 lDeleteStatement = pConnection.prepareStatement(sTextOfStudentDeleteStatement);
0822 try
0823 {
0824 lDeleteStatement.clearBatch();
0825 for (int i = 0; i < pInstanceIdsToDelete.length; i++)
0826 {
0827 com.almamater.crs.types.system.courses.StudentInstanceId lInstanceIdToDelete = pInstanceIdsToDelete[i];
0828 if (lInstanceIdToDelete == null)
0829 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be undefined for delete() operation.");
0830 if (lInstanceIdToDelete.isEmpty())
0831 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be empty for delete() operation.");
0832 if (lInstanceIdToDelete.isConcealed())
0833 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be concealed for delete() operation.");
0834 if (sLogger.isDebugEnabled())
0835 sLogger.debug("Parameter 1 value: " + lInstanceIdToDelete);
0836 lDeleteStatement.setString( 1, TypesConvertor.getSqlValueFromStudentInstanceId(lInstanceIdToDelete));
0837 lDeleteStatement.addBatch();
0838 }
0839 lDeleteStatement.executeBatch();
0840 }
0841 finally
0842 {
0843 if (lDeleteStatement != null)
0844 lDeleteStatement.close();
0845 }
0846 }
0847 catch(DataTypeInvalidOperationForEmptyInstanceException e)
0848 {
0849 throw new PSUnexpectedProgramConditionException("Should not occur as generated code must check for empty instance",e);
0850 }
0851 catch(DataTypeInvalidOperationForConcealedInstanceException e)
0852 {
0853 throw new PSUnexpectedProgramConditionException("Should not occur as generated code must check for concealed instance",e);
0854 }
0855 catch(java.sql.SQLException e)
0856 {
0857 throw new PSDataSourceOperationInvocationException("Error on delete(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
0858 }
0859 }
0860
0861 // Inserts one or more new Student records into the database
0862 private void updateStudentRecords( java.sql.Connection pConnection, com.almamater.crs.domains.courses.storage.STStudentRecord[] pModifiedRecords) throws PSException
0863 {
0864 try
0865 {
0866 java.sql.PreparedStatement lCurrentStatement = null;
0867 String lCurrentTextOfUpdateStatement = null;
0868 try
0869 {
0870 StringBuffer lProposedTextOfUpdate = new StringBuffer();
0871 for (int i = 0; i < pModifiedRecords.length; i++)
0872 {
0873 com.almamater.crs.domains.courses.storage.STStudentRecord lModifiedRecord = pModifiedRecords[i];
0874 // InstanceId is mandatory
0875 if (lModifiedRecord.InstanceId == null)
0876 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be undefined for update() operation.");
0877 if (lModifiedRecord.InstanceId.isEmpty())
0878 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be empty for update() operation.");
0879 if (lModifiedRecord.InstanceId.isConcealed())
0880 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.InstanceId is not expected to be concealed for update() operation.");
0881 // VersionId is mandatory
0882 if (lModifiedRecord.VersionId == null)
0883 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.VersionId is not expected to be undefined for update() operation.");
0884 if (lModifiedRecord.VersionId.isEmpty())
0885 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.VersionId is not expected to be empty for update() operation.");
0886 if (lModifiedRecord.VersionId.isConcealed())
0887 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.VersionId is not expected to be concealed for update() operation.");
0888 lProposedTextOfUpdate.setLength(0);
0889 lProposedTextOfUpdate.append("UPDATE e_STUDENT SET versionid = ?");
0890 if (lModifiedRecord.StudentNo != null)
0891 {
0892 if (lModifiedRecord.StudentNo.isConcealed())
0893 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.StudentNo is not expected to be concealed for update() operation.");
0894 // StudentNo is mandatory
0895 if (lModifiedRecord.StudentNo.isEmpty())
0896 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.StudentNo is not expected to be empty for update() operation.");
0897 lProposedTextOfUpdate.append(", STUDENT_NO = ?");
0898 }
0899 if (lModifiedRecord.FirstName != null)
0900 {
0901 if (lModifiedRecord.FirstName.isConcealed())
0902 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FirstName is not expected to be concealed for update() operation.");
0903 // FirstName is mandatory
0904 if (lModifiedRecord.FirstName.isEmpty())
0905 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FirstName is not expected to be empty for update() operation.");
0906 lProposedTextOfUpdate.append(", FIRST_NAME = ?");
0907 }
0908 if (lModifiedRecord.SecondName != null)
0909 {
0910 if (lModifiedRecord.SecondName.isConcealed())
0911 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.SecondName is not expected to be concealed for update() operation.");
0912 // SecondName is optional
0913 lProposedTextOfUpdate.append(", SECOND_NAME = ?");
0914 }
0915 if (lModifiedRecord.FamilyName != null)
0916 {
0917 if (lModifiedRecord.FamilyName.isConcealed())
0918 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FamilyName is not expected to be concealed for update() operation.");
0919 // FamilyName is mandatory
0920 if (lModifiedRecord.FamilyName.isEmpty())
0921 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.FamilyName is not expected to be empty for update() operation.");
0922 lProposedTextOfUpdate.append(", FAMILY_NAME = ?");
0923 }
0924 if (lModifiedRecord.DateOfBirth != null)
0925 {
0926 if (lModifiedRecord.DateOfBirth.isConcealed())
0927 throw new PSAttributeConstraintViolationException("com.almamater.crs.domains.courses.storage.STStudentRecord.DateOfBirth is not expected to be concealed for update() operation.");
0928 // DateOfBirth is optional
0929 lProposedTextOfUpdate.append(", DATE_OF_BIRTH = ?");
0930 }
0931 lProposedTextOfUpdate.append(" WHERE recordid = ? AND versionid = ?");
0932 // We have built the statement for this insertion. Compare with saved one and make a decision to continue current batch or not
0933 String lProposedTextOfUpdateStatement = lProposedTextOfUpdate.toString();
0934 if (lCurrentStatement != null)
0935 {
0936 if (!lCurrentTextOfUpdateStatement.equals(lProposedTextOfUpdateStatement))
0937 {
0938 lCurrentStatement.close();
0939 lCurrentStatement = null;
0940 }
0941 }
0942 if (lCurrentStatement == null)
0943 {
0944 lCurrentTextOfUpdateStatement = lProposedTextOfUpdateStatement;
0945 if (sLogger.isDebugEnabled())
0946 sLogger.debug("About to execute SQL statement: " + lCurrentTextOfUpdateStatement + ";");
0947 lCurrentStatement = pConnection.prepareStatement(lCurrentTextOfUpdateStatement);
0948 }
0949 int lParameterIndex = 1;
0950 if (sLogger.isDebugEnabled())
0951 sLogger.debug("Parameter " + lParameterIndex + " value: " + lModifiedRecord.VersionId);
0952 lCurrentStatement.setLong(lParameterIndex++, TypesConvertor.getSqlValueFromStudentVersionId(lModifiedRecord.VersionId));
0953 if (lModifiedRecord.StudentNo != null)
0954 {
0955 if (sLogger.isDebugEnabled())
0956 sLogger.debug("Parameter " + lParameterIndex + " value: " + com.metaboss.util.StringUtils.suggestTruncatedOutput(lModifiedRecord.StudentNo.toString(),30));
0957 lCurrentStatement.setInt(lParameterIndex++, TypesConvertor.getSqlValueFromStudentNumber(lModifiedRecord.StudentNo));
0958 }
0959 if (lModifiedRecord.FirstName != null)
0960 {
0961 if (sLogger.isDebugEnabled())
0962 sLogger.debug("Parameter " + lParameterIndex + " value: " + com.metaboss.util.StringUtils.suggestTruncatedOutput(lModifiedRecord.FirstName.toString(),30));
0963 lCurrentStatement.setString(lParameterIndex++, TypesConvertor.getSqlValueFromPersonName(lModifiedRecord.FirstName));
0964 }
0965 if (lModifiedRecord.SecondName != null)
0966 {
0967 if (lModifiedRecord.SecondName.isEmpty())
0968 {
0969 if (sLogger.isDebugEnabled())
0970 sLogger.debug("Parameter " + lParameterIndex + " is null");
0971 lCurrentStatement.setNull( lParameterIndex++, java.sql.Types.VARCHAR);
0972 }
0973 else
0974 {
0975 if (sLogger.isDebugEnabled())
0976 sLogger.debug("Parameter " + lParameterIndex + " value: " + com.metaboss.util.StringUtils.suggestTruncatedOutput(lModifiedRecord.SecondName.toString(),30));
0977 lCurrentStatement.setString(lParameterIndex++, TypesConvertor.getSqlValueFromPersonName(lModifiedRecord.SecondName));
0978 }
0979 }
0980 if (lModifiedRecord.FamilyName != null)
0981 {
0982 if (sLogger.isDebugEnabled())
0983 sLogger.debug("Parameter " + lParameterIndex + " value: " + com.metaboss.util.StringUtils.suggestTruncatedOutput(lModifiedRecord.FamilyName.toString(),30));
0984 lCurrentStatement.setString(lParameterIndex++, TypesConvertor.getSqlValueFromPersonName(lModifiedRecord.FamilyName));
0985 }
0986 if (lModifiedRecord.DateOfBirth != null)
0987 {
0988 if (lModifiedRecord.DateOfBirth.isEmpty())
0989 {
0990 if (sLogger.isDebugEnabled())
0991 sLogger.debug("Parameter " + lParameterIndex + " is null");
0992 lCurrentStatement.setNull( lParameterIndex++, java.sql.Types.DATE);
0993 }
0994 else
0995 {
0996 if (sLogger.isDebugEnabled())
0997 sLogger.debug("Parameter " + lParameterIndex + " value: " + com.metaboss.util.StringUtils.suggestTruncatedOutput(lModifiedRecord.DateOfBirth.toString(),30));
0998 lCurrentStatement.setDate(lParameterIndex++, TypesConvertor.getSqlValueFromDateField(lModifiedRecord.DateOfBirth));
0999 }
1000 }
1001 if (sLogger.isDebugEnabled())
1002 sLogger.debug("Parameter " + lParameterIndex + " value: " + lModifiedRecord.InstanceId);
1003 lCurrentStatement.setString( lParameterIndex++, TypesConvertor.getSqlValueFromStudentInstanceId(lModifiedRecord.InstanceId));
1004 com.almamater.crs.types.system.courses.StudentVersionId lPreviousVersionId = lModifiedRecord.VersionId.getPrevious();
1005 if (sLogger.isDebugEnabled())
1006 sLogger.debug("Parameter " + lParameterIndex + " value: " + lPreviousVersionId);
1007 lCurrentStatement.setLong(lParameterIndex++, TypesConvertor.getSqlValueFromStudentVersionId(lPreviousVersionId));
1008 int lRowCount = lCurrentStatement.executeUpdate();
1009 if (lRowCount != 1)
1010 throw new PSUpdateDataIntegrityViolationException("Unable to update Student record with Instance Id " + pModifiedRecords[i].InstanceId + ". Expected updated rows count: 1. Actual updated rows count: " + lRowCount);
1011 }
1012 lCurrentStatement.close();
1013 lCurrentStatement = null;
1014 }
1015 finally
1016 {
1017 if (lCurrentStatement != null)
1018 lCurrentStatement.close();
1019 }
1020 }
1021 catch(DataTypeInvalidOperationForEmptyInstanceException e)
1022 {
1023 throw new PSUnexpectedProgramConditionException("Should not occur as generated code must check for empty instance",e);
1024 }
1025 catch(DataTypeInvalidOperationForConcealedInstanceException e)
1026 {
1027 throw new PSUnexpectedProgramConditionException("Should not occur as generated code must check for concealed instance",e);
1028 }
1029 catch(java.sql.SQLException e)
1030 {
1031 String lMessage = e.getMessage();
1032 if (lMessage != null)
1033 {
1034 lMessage = lMessage.trim();
1035 if (lMessage.startsWith("UPDATE on table 'E_STUDENT' caused a violation of foreign key constraint '"))
1036 throw new PSAssociationConstraintViolationException("Error on update(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
1037 if (lMessage.startsWith("The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint"))
1038 throw new PSAttributeConstraintViolationException("Error on update(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
1039 }
1040 throw new PSDataSourceOperationInvocationException("Error on update(com.almamater.crs.domains.courses.storage.STStudentRecord)", e);
1041 }
1042 }
1043 }
|