fluid-api/src/main/java/com/fluidbpm/program/api/util/sql/impl/SQLFormFieldUtil.java
public Field getFormFieldValueFor(
			FormFieldMapping formFieldMappingParam,
			Long formContainerIdParam,
			boolean includeTableFieldFormRecordInfoParam
	) {
		if(formFieldMappingParam == null) {
			return null;
		}

		//First attempt to fetch from the cache...
		if(this.getCacheUtil() != null) {
			CacheUtil.CachedFieldValue cachedFieldValue =
					this.getCacheUtil().getCachedFieldValueFrom(
						formFieldMappingParam.formDefinitionId,
						formContainerIdParam,
						formFieldMappingParam.formFieldId);

			if(cachedFieldValue != null)
			{
				Field field = cachedFieldValue.getCachedFieldValueAsField();
				if(field != null)
				{
					field.setFieldName(formFieldMappingParam.name);
					return field;
				}
			}
		}

		//Now use a database lookup...
		Field returnVal = null;
		PreparedStatement preparedStatement = null, preparedStatementForTblInfo = null;
		ResultSet resultSet = null,resultSetForTblInfo = null;
		try {
			ISyntax syntax = SyntaxFactory.getInstance().getFieldValueSyntaxFor(
					this.getSQLTypeFromConnection(),
					formFieldMappingParam);

			if(syntax != null) {
				preparedStatement = this.getConnection().prepareStatement(
						syntax.getPreparedStatement());

				preparedStatement.setLong(1, formFieldMappingParam.formDefinitionId);
				preparedStatement.setLong(2, formFieldMappingParam.formFieldId);
				preparedStatement.setLong(3, formContainerIdParam);

				resultSet = preparedStatement.executeQuery();
			}

			switch (formFieldMappingParam.dataType.intValue()) {
				//Text...
				case UtilGlobal.FieldTypeId._1_TEXT:
				if(resultSet.next()) {
					returnVal = new Field(
							formFieldMappingParam.name,
							resultSet.getString(1),
							Field.Type.Text);
				}
				break;
				//True False...
				case UtilGlobal.FieldTypeId._2_TRUE_FALSE:
				if(resultSet.next()) {
					returnVal = new Field(
							formFieldMappingParam.name,
							resultSet.getBoolean(1),
							Field.Type.TrueFalse);
				}
				break;
				//Paragraph Text...
				case UtilGlobal.FieldTypeId._3_PARAGRAPH_TEXT:
				if(resultSet.next()) {
					returnVal = new Field(
							formFieldMappingParam.name,
							resultSet.getString(1),
							Field.Type.ParagraphText);
				}
				break;
				//Multiple Choice...
				case UtilGlobal.FieldTypeId._4_MULTI_CHOICE:
					MultiChoice multiChoice = new MultiChoice();

					List<String> selectedValues = new ArrayList();
					while(resultSet.next()) {
						selectedValues.add(resultSet.getString(1));
					}

					multiChoice.setSelectedMultiChoices(selectedValues);
					if(!selectedValues.isEmpty()) {
						returnVal = new Field(
								formFieldMappingParam.name,
								multiChoice);
					}
				break;
				//Date Time...
				case UtilGlobal.FieldTypeId._5_DATE_TIME:
					if(resultSet.next()) {
						returnVal = new Field(
								formFieldMappingParam.name,
								resultSet.getDate(1),
								Field.Type.DateTime);
					}
				break;
				//Decimal...
				case UtilGlobal.FieldTypeId._6_DECIMAL:
					if(resultSet.next()) {
						returnVal = new Field(
								formFieldMappingParam.name,
								resultSet.getDouble(1),
								Field.Type.Decimal);
					}
				break;
				//Table Field...
				case UtilGlobal.FieldTypeId._7_TABLE_FIELD:
					List<Long> formContainerIds = new ArrayList();
					while(resultSet.next()) {
						formContainerIds.add(resultSet.getLong(1));
					}

					//Break if empty...
					if(formContainerIds.isEmpty()) {
						break;
					}

					TableField tableField = new TableField();

					final List<Form> formRecords = new ArrayList();

					//Populate all the ids for forms...
					formContainerIds.forEach(formContId -> {
						formRecords.add(new Form(formContId));
					});

					//Retrieve the info for the table record...
					if(includeTableFieldFormRecordInfoParam) {

						ISyntax syntaxForFormContInfo = SyntaxFactory.getInstance().getSyntaxFor(
								this.getSQLTypeFromConnection(),
								ISyntax.ProcedureMapping.Form.GetFormContainerInfo);

						preparedStatementForTblInfo = this.getConnection().prepareStatement(
								syntaxForFormContInfo.getPreparedStatement());

						for(Form formRecordToSetInfoOn : formRecords) {

							preparedStatementForTblInfo.setLong(
									1, formRecordToSetInfoOn.getId());

							resultSetForTblInfo = preparedStatementForTblInfo.executeQuery();
							if(resultSetForTblInfo.next()) {

								Long formTypeId = resultSetForTblInfo.getLong(
										SQLFormUtil.SQLColumnIndex._02_FORM_TYPE);

								formRecordToSetInfoOn.setFormTypeId(formTypeId);
								formRecordToSetInfoOn.setFormType(
										this.sqlFormDefinitionUtil == null ? null :
												this.sqlFormDefinitionUtil.getFormDefinitionIdAndTitle().get(formTypeId)
								);

								formRecordToSetInfoOn.setTitle(resultSetForTblInfo.getString(
										SQLFormUtil.SQLColumnIndex._03_TITLE));

								Date created = resultSetForTblInfo.getDate(SQLFormUtil.SQLColumnIndex._04_CREATED);
								Date lastUpdated = resultSetForTblInfo.getDate(SQLFormUtil.SQLColumnIndex._05_LAST_UPDATED);

								//Created...
								if(created != null)
								{
									formRecordToSetInfoOn.setDateCreated(new Date(created.getTime()));
								}

								//Last Updated...
								if(lastUpdated != null)
								{
									formRecordToSetInfoOn.setDateLastUpdated(new Date(lastUpdated.getTime()));
								}
							}
						}
					}

					tableField.setTableRecords(formRecords);

					returnVal = new Field(
							formFieldMappingParam.name,
							tableField,
							Field.Type.Table);
					//TODO __8__ encrypted field...
				break;
				//Label...
				case UtilGlobal.FieldTypeId._9_LABEL:
					returnVal = new Field(
							formFieldMappingParam.name,
							formFieldMappingParam.description,
							Field.Type.Label);
					break;
				default:
					throw new SQLException("Unable to map '"+
							formContainerIdParam.intValue() +"', to Form Field value.");
			}

			return returnVal;
		} catch (SQLException sqlError) {
			throw new FluidSQLException(sqlError);
		} finally {
			this.closeStatement(preparedStatement);
			this.closeStatement(preparedStatementForTblInfo);
		}
	}
public Field getFormFieldValueFor(
			FormFieldMapping formFieldMappingParam,
			Long formContainerIdParam,
			boolean includeTableFieldFormRecordInfoParam
	) {
		if(formFieldMappingParam == null) {
			return null;
		}

		//First attempt to fetch from the cache...
		if(this.getCacheUtil() != null) {
			CacheUtil.CachedFieldValue cachedFieldValue =
					this.getCacheUtil().getCachedFieldValueFrom(
						formFieldMappingParam.formDefinitionId,
						formContainerIdParam,
						formFieldMappingParam.formFieldId);

			if(cachedFieldValue != null)
			{
				Field field = cachedFieldValue.getCachedFieldValueAsField();
				if(field != null)
				{
					field.setFieldName(formFieldMappingParam.name);
					return field;
				}
			}
		}

		//Now use a database lookup...
		Field returnVal = null;
		PreparedStatement preparedStatement = null, preparedStatementForTblInfo = null;
		ResultSet resultSet = null,resultSetForTblInfo = null;
		try {
			ISyntax syntax = SyntaxFactory.getInstance().getFieldValueSyntaxFor(
					this.getSQLTypeFromConnection(),
					formFieldMappingParam);

			if(syntax != null) {
				preparedStatement = this.getConnection().prepareStatement(
						syntax.getPreparedStatement());

				preparedStatement.setLong(1, formFieldMappingParam.formDefinitionId);
				preparedStatement.setLong(2, formFieldMappingParam.formFieldId);
				preparedStatement.setLong(3, formContainerIdParam);

				resultSet = preparedStatement.executeQuery();
			}

			switch (formFieldMappingParam.dataType.intValue()) {
				//Text...
				case UtilGlobal.FieldTypeId._1_TEXT:
				if(resultSet.next()) {
					returnVal = new Field(
							formFieldMappingParam.name,
							resultSet.getString(1),
							Field.Type.Text);
				}
				break;
				//True False...
				case UtilGlobal.FieldTypeId._2_TRUE_FALSE:
				if(resultSet.next()) {
					returnVal = new Field(
							formFieldMappingParam.name,
							resultSet.getBoolean(1),
							Field.Type.TrueFalse);
				}
				break;
				//Paragraph Text...
				case UtilGlobal.FieldTypeId._3_PARAGRAPH_TEXT:
				if(resultSet.next()) {
					returnVal = new Field(
							formFieldMappingParam.name,
							resultSet.getString(1),
							Field.Type.ParagraphText);
				}
				break;
				//Multiple Choice...
				case UtilGlobal.FieldTypeId._4_MULTI_CHOICE:
					MultiChoice multiChoice = new MultiChoice();

					List<String> selectedValues = new ArrayList();
					while(resultSet.next()) {
						selectedValues.add(resultSet.getString(1));
					}

					multiChoice.setSelectedMultiChoices(selectedValues);
					if(!selectedValues.isEmpty()) {
						returnVal = new Field(
								formFieldMappingParam.name,
								multiChoice);
					}
				break;
				//Date Time...
				case UtilGlobal.FieldTypeId._5_DATE_TIME:
					if(resultSet.next()) {
						returnVal = new Field(
								formFieldMappingParam.name,
								resultSet.getDate(1),
								Field.Type.DateTime);
					}
				break;
				//Decimal...
				case UtilGlobal.FieldTypeId._6_DECIMAL:
					if(resultSet.next()) {
						returnVal = new Field(
								formFieldMappingParam.name,
								resultSet.getDouble(1),
								Field.Type.Decimal);
					}
				break;
				//Table Field...
				case UtilGlobal.FieldTypeId._7_TABLE_FIELD:
					List<Long> formContainerIds = new ArrayList();
					while(resultSet.next()) {
						formContainerIds.add(resultSet.getLong(1));
					}

					//Break if empty...
					if(formContainerIds.isEmpty()) {
						break;
					}

					TableField tableField = new TableField();

					final List<Form> formRecords = new ArrayList();

					//Populate all the ids for forms...
					formContainerIds.forEach(formContId -> {
						formRecords.add(new Form(formContId));
					});

					//Retrieve the info for the table record...
					if(includeTableFieldFormRecordInfoParam) {

						ISyntax syntaxForFormContInfo = SyntaxFactory.getInstance().getSyntaxFor(
								this.getSQLTypeFromConnection(),
								ISyntax.ProcedureMapping.Form.GetFormContainerInfo);

						preparedStatementForTblInfo = this.getConnection().prepareStatement(
								syntaxForFormContInfo.getPreparedStatement());

						for(Form formRecordToSetInfoOn : formRecords) {

							preparedStatementForTblInfo.setLong(
									1, formRecordToSetInfoOn.getId());

							resultSetForTblInfo = preparedStatementForTblInfo.executeQuery();
							if(resultSetForTblInfo.next()) {

								Long formTypeId = resultSetForTblInfo.getLong(
										SQLFormUtil.SQLColumnIndex._02_FORM_TYPE);

								formRecordToSetInfoOn.setFormTypeId(formTypeId);
								formRecordToSetInfoOn.setFormType(
										this.sqlFormDefinitionUtil == null ? null :
												this.sqlFormDefinitionUtil.getFormDefinitionIdAndTitle().get(formTypeId)
								);

								formRecordToSetInfoOn.setTitle(resultSetForTblInfo.getString(
										SQLFormUtil.SQLColumnIndex._03_TITLE));

								Date created = resultSetForTblInfo.getDate(SQLFormUtil.SQLColumnIndex._04_CREATED);
								Date lastUpdated = resultSetForTblInfo.getDate(SQLFormUtil.SQLColumnIndex._05_LAST_UPDATED);

								//Created...
								if(created != null)
								{
									formRecordToSetInfoOn.setDateCreated(new Date(created.getTime()));
								}

								//Last Updated...
								if(lastUpdated != null)
								{
									formRecordToSetInfoOn.setDateLastUpdated(new Date(lastUpdated.getTime()));
								}
							}
						}
					}

					tableField.setTableRecords(formRecords);

					returnVal = new Field(
							formFieldMappingParam.name,
							tableField,
							Field.Type.Table);
					//TODO __8__ encrypted field...
				break;
				//Label...
				case UtilGlobal.FieldTypeId._9_LABEL:
					returnVal = new Field(
							formFieldMappingParam.name,
							formFieldMappingParam.description,
							Field.Type.Label);
					break;
				default:
					throw new SQLException("Unable to map '"+
							formContainerIdParam.intValue() +"', to Form Field value.");
			}

			return returnVal;
		} catch (SQLException sqlError) {
			throw new FluidSQLException(sqlError);
		} finally {
			this.closeStatement(preparedStatement);
			this.closeStatement(preparedStatementForTblInfo);
		}
	}
public Field getFormFieldValueFor ( FormFieldMapping formFieldMappingParam , Long formContainerIdParam , boolean includeTableFieldFormRecordInfoParam ) { if ( formFieldMappingParam == null ) { return null ; } //First attempt to fetch from the cache... if ( this . getCacheUtil ( ) != null ) { CacheUtil . CachedFieldValue cachedFieldValue = this . getCacheUtil ( ) . getCachedFieldValueFrom ( formFieldMappingParam . formDefinitionId , formContainerIdParam , formFieldMappingParam . formFieldId ) ; if ( cachedFieldValue != null ) { Field field = cachedFieldValue . getCachedFieldValueAsField ( ) ; if ( field != null ) { field . setFieldName ( formFieldMappingParam . name ) ; return field ; } } } //Now use a database lookup... Field returnVal = null ; PreparedStatement preparedStatement = null , preparedStatementForTblInfo = null ; ResultSet resultSet = null , resultSetForTblInfo = null ; try { ISyntax syntax = SyntaxFactory . getInstance ( ) . getFieldValueSyntaxFor ( this . getSQLTypeFromConnection ( ) , formFieldMappingParam ) ; if ( syntax != null ) { preparedStatement = this . getConnection ( ) . prepareStatement ( syntax . getPreparedStatement ( ) ) ; preparedStatement . setLong ( 1 , formFieldMappingParam . formDefinitionId ) ; preparedStatement . setLong ( 2 , formFieldMappingParam . formFieldId ) ; preparedStatement . setLong ( 3 , formContainerIdParam ) ; resultSet = preparedStatement . executeQuery ( ) ; } switch ( formFieldMappingParam . dataType . intValue ( ) ) { //Text... case UtilGlobal . FieldTypeId . _1_TEXT : if ( resultSet . next ( ) ) { returnVal = new Field ( formFieldMappingParam . name , resultSet . getString ( 1 ) , Field . Type . Text ) ; } break ; //True False... case UtilGlobal . FieldTypeId . _2_TRUE_FALSE : if ( resultSet . next ( ) ) { returnVal = new Field ( formFieldMappingParam . name , resultSet . getBoolean ( 1 ) , Field . Type . TrueFalse ) ; } break ; //Paragraph Text... case UtilGlobal . FieldTypeId . _3_PARAGRAPH_TEXT : if ( resultSet . next ( ) ) { returnVal = new Field ( formFieldMappingParam . name , resultSet . getString ( 1 ) , Field . Type . ParagraphText ) ; } break ; //Multiple Choice... case UtilGlobal . FieldTypeId . _4_MULTI_CHOICE : MultiChoice multiChoice = new MultiChoice ( ) ; List < String > selectedValues = new ArrayList ( ) ; while ( resultSet . next ( ) ) { selectedValues . add ( resultSet . getString ( 1 ) ) ; } multiChoice . setSelectedMultiChoices ( selectedValues ) ; if ( ! selectedValues . isEmpty ( ) ) { returnVal = new Field ( formFieldMappingParam . name , multiChoice ) ; } break ; //Date Time... case UtilGlobal . FieldTypeId . _5_DATE_TIME : if ( resultSet . next ( ) ) { returnVal = new Field ( formFieldMappingParam . name , resultSet . getDate ( 1 ) , Field . Type . DateTime ) ; } break ; //Decimal... case UtilGlobal . FieldTypeId . _6_DECIMAL : if ( resultSet . next ( ) ) { returnVal = new Field ( formFieldMappingParam . name , resultSet . getDouble ( 1 ) , Field . Type . Decimal ) ; } break ; //Table Field... case UtilGlobal . FieldTypeId . _7_TABLE_FIELD : List < Long > formContainerIds = new ArrayList ( ) ; while ( resultSet . next ( ) ) { formContainerIds . add ( resultSet . getLong ( 1 ) ) ; } //Break if empty... if ( formContainerIds . isEmpty ( ) ) { break ; } TableField tableField = new TableField ( ) ; final List < Form > formRecords = new ArrayList ( ) ; //Populate all the ids for forms... formContainerIds . forEach ( formContId -> { formRecords . add ( new Form ( formContId ) ) ; } ) ; //Retrieve the info for the table record... if ( includeTableFieldFormRecordInfoParam ) { ISyntax syntaxForFormContInfo = SyntaxFactory . getInstance ( ) . getSyntaxFor ( this . getSQLTypeFromConnection ( ) , ISyntax . ProcedureMapping . Form . GetFormContainerInfo ) ; preparedStatementForTblInfo = this . getConnection ( ) . prepareStatement ( syntaxForFormContInfo . getPreparedStatement ( ) ) ; for ( Form formRecordToSetInfoOn : formRecords ) { preparedStatementForTblInfo . setLong ( 1 , formRecordToSetInfoOn . getId ( ) ) ; resultSetForTblInfo = preparedStatementForTblInfo . executeQuery ( ) ; if ( resultSetForTblInfo . next ( ) ) { Long formTypeId = resultSetForTblInfo . getLong ( SQLFormUtil . SQLColumnIndex . _02_FORM_TYPE ) ; formRecordToSetInfoOn . setFormTypeId ( formTypeId ) ; formRecordToSetInfoOn . setFormType ( this . sqlFormDefinitionUtil == null ? null : this . sqlFormDefinitionUtil . getFormDefinitionIdAndTitle ( ) . get ( formTypeId ) ) ; formRecordToSetInfoOn . setTitle ( resultSetForTblInfo . getString ( SQLFormUtil . SQLColumnIndex . _03_TITLE ) ) ; Date created = resultSetForTblInfo . getDate ( SQLFormUtil . SQLColumnIndex . _04_CREATED ) ; Date lastUpdated = resultSetForTblInfo . getDate ( SQLFormUtil . SQLColumnIndex . _05_LAST_UPDATED ) ; //Created... if ( created != null ) { formRecordToSetInfoOn . setDateCreated ( new Date ( created . getTime ( ) ) ) ; } //Last Updated... if ( lastUpdated != null ) { formRecordToSetInfoOn . setDateLastUpdated ( new Date ( lastUpdated . getTime ( ) ) ) ; } } } } tableField . setTableRecords ( formRecords ) ; returnVal = new Field ( formFieldMappingParam . name , tableField , Field . Type . Table ) ; //TODO __8__ encrypted field... break ; //Label... case UtilGlobal . FieldTypeId . _9_LABEL : returnVal = new Field ( formFieldMappingParam . name , formFieldMappingParam . description , Field . Type . Label ) ; break ; default : throw new SQLException ( "Unable to map '" + formContainerIdParam . intValue ( ) + "', to Form Field value." ) ; } return returnVal ; } catch ( SQLException sqlError ) { throw new FluidSQLException ( sqlError ) ; } finally { this . closeStatement ( preparedStatement ) ; this . closeStatement ( preparedStatementForTblInfo ) ; } }
Retrieves the Form Field value for Electronic Form {@code formContainerIdParam}.

@param formFieldMappingParam The mapping to use.
@param formContainerIdParam The Electronic Form Id.
@param includeTableFieldFormRecordInfoParam Does table record form data need to be included.

@return Populated {@code Field} value.
Retrieves the Form Field value for Electronic Form { @code formContainerIdParam } .