Commit 5666e3b8 by Harsh Shah

Right question related BO change

parent ef027e12
...@@ -8,10 +8,14 @@ ...@@ -8,10 +8,14 @@
<column name="object_id" type="Long" nullable="false" length="11"/> <column name="object_id" type="Long" nullable="false" length="11"/>
<column name="object_last_updated_date" type="Date" nullable="false" length="22"/> <column name="object_last_updated_date" type="Date" nullable="false" length="22"/>
<column name="object_created_date" type="Date" nullable="false" length="22"/> <column name="object_created_date" type="Date" nullable="false" length="22"/>
<column name="left_quest" type="String" nullable="true" length="80"/> <column name="description" type="String" nullable="true" length="80"/>
<column name="is_right_quest" type="Boolean" nullable="true"/>
<column name="section_number" type="Long" length="11" nullable="true"/> <column name="section_number" type="Long" length="11" nullable="true"/>
<column name="right_quest_number" type="Long" length="11" nullable="true"/>
</NODE> </NODE>
<NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_quest_lin" indexName="idx_tl_quest_lin_section_number" isUnique="false"><column name="section_number"/></NODE> <NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_quest_lin" indexName="idx_tl_quest_lin_section_number" isUnique="false"><column name="section_number"/></NODE>
<NODE name="INDEX" factory="Participant" class="oneit.sql.transfer.DefineIndexOperation" tableName="tl_quest_lin" indexName="idx_tl_quest_lin_right_quest_number" isUnique="false"><column name="right_quest_number"/></NODE>
</NODE></OBJECTS> </NODE></OBJECTS>
\ No newline at end of file
...@@ -8,8 +8,10 @@ CREATE TABLE tl_quest_lin ( ...@@ -8,8 +8,10 @@ CREATE TABLE tl_quest_lin (
object_last_updated_date datetime DEFAULT getdate() NOT NULL , object_last_updated_date datetime DEFAULT getdate() NOT NULL ,
object_created_date datetime DEFAULT getdate() NOT NULL object_created_date datetime DEFAULT getdate() NOT NULL
, ,
left_quest varchar(80) NULL, description varchar(80) NULL,
section_number numeric(12) NULL is_right_quest char(1) NULL,
section_number numeric(12) NULL,
right_quest_number numeric(12) NULL
); );
...@@ -24,3 +26,6 @@ ALTER TABLE tl_quest_lin ADD ...@@ -24,3 +26,6 @@ ALTER TABLE tl_quest_lin ADD
CREATE INDEX idx_tl_quest_lin_section_number CREATE INDEX idx_tl_quest_lin_section_number
ON tl_quest_lin (section_number); ON tl_quest_lin (section_number);
CREATE INDEX idx_tl_quest_lin_right_quest_number
ON tl_quest_lin (right_quest_number);
...@@ -9,8 +9,10 @@ CREATE TABLE tl_quest_lin ( ...@@ -9,8 +9,10 @@ CREATE TABLE tl_quest_lin (
object_last_updated_date date DEFAULT SYSDATE NOT NULL , object_last_updated_date date DEFAULT SYSDATE NOT NULL ,
object_created_date date DEFAULT SYSDATE NOT NULL object_created_date date DEFAULT SYSDATE NOT NULL
, ,
left_quest varchar2(80) NULL, description varchar2(80) NULL,
section_number number(12) NULL is_right_quest char(1) NULL,
section_number number(12) NULL,
right_quest_number number(12) NULL
); );
...@@ -25,3 +27,6 @@ ALTER TABLE tl_quest_lin ADD ...@@ -25,3 +27,6 @@ ALTER TABLE tl_quest_lin ADD
CREATE INDEX idx_tl_quest_lin_section_number CREATE INDEX idx_tl_quest_lin_section_number
ON tl_quest_lin (section_number); ON tl_quest_lin (section_number);
CREATE INDEX idx_tl_quest_lin_right_quest_number
ON tl_quest_lin (right_quest_number);
...@@ -9,8 +9,10 @@ CREATE TABLE tl_quest_lin ( ...@@ -9,8 +9,10 @@ CREATE TABLE tl_quest_lin (
object_last_updated_date timestamp DEFAULT NOW() NOT NULL , object_last_updated_date timestamp DEFAULT NOW() NOT NULL ,
object_created_date timestamp DEFAULT NOW() NOT NULL object_created_date timestamp DEFAULT NOW() NOT NULL
, ,
left_quest varchar(80) NULL, description varchar(80) NULL,
section_number numeric(12) NULL is_right_quest char(1) NULL,
section_number numeric(12) NULL,
right_quest_number numeric(12) NULL
); );
...@@ -25,3 +27,6 @@ ALTER TABLE tl_quest_lin ADD ...@@ -25,3 +27,6 @@ ALTER TABLE tl_quest_lin ADD
CREATE INDEX idx_tl_quest_lin_section_number CREATE INDEX idx_tl_quest_lin_section_number
ON tl_quest_lin (section_number); ON tl_quest_lin (section_number);
CREATE INDEX idx_tl_quest_lin_right_quest_number
ON tl_quest_lin (right_quest_number);
...@@ -39,10 +39,15 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -39,10 +39,15 @@ public abstract class BaseQuestion extends BaseBusinessClass
// Static constants corresponding to field names // Static constants corresponding to field names
public static final String FIELD_Description = "Description"; public static final String FIELD_Description = "Description";
public static final String FIELD_IsRightQuestion = "IsRightQuestion";
public static final String SINGLEREFERENCE_Section = "Section"; public static final String SINGLEREFERENCE_Section = "Section";
public static final String BACKREF_Section = ""; public static final String BACKREF_Section = "";
public static final String SINGLEREFERENCE_RightQuestion = "RightQuestion";
public static final String BACKREF_RightQuestion = "";
public static final String MULTIPLEREFERENCE_Factors = "Factors"; public static final String MULTIPLEREFERENCE_Factors = "Factors";
public static final String BACKREF_Factors = ""; public static final String BACKREF_Factors = "";
public static final String MULTIPLEREFERENCE_LeftQuestions = "LeftQuestions";
public static final String BACKREF_LeftQuestions = "";
// Static constants corresponding to searches // Static constants corresponding to searches
public static final String SEARCH_All = "All"; public static final String SEARCH_All = "All";
...@@ -50,18 +55,22 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -50,18 +55,22 @@ public abstract class BaseQuestion extends BaseBusinessClass
// Static constants corresponding to attribute helpers // Static constants corresponding to attribute helpers
private static final DefaultAttributeHelper<Question> HELPER_Description = DefaultAttributeHelper.INSTANCE; private static final DefaultAttributeHelper<Question> HELPER_Description = DefaultAttributeHelper.INSTANCE;
private static final DefaultAttributeHelper<Question> HELPER_IsRightQuestion = DefaultAttributeHelper.INSTANCE;
// Private attributes corresponding to business object data // Private attributes corresponding to business object data
private String _Description; private String _Description;
private Boolean _IsRightQuestion;
// Private attributes corresponding to single references // Private attributes corresponding to single references
private SingleAssociation<Question, Section> _Section; private SingleAssociation<Question, Section> _Section;
private SingleAssociation<Question, Question> _RightQuestion;
// Private attributes corresponding to multiple references // Private attributes corresponding to multiple references
private MultipleAssociation<Question, FactorQuestionLink> _Factors; private MultipleAssociation<Question, FactorQuestionLink> _Factors;
private MultipleAssociation<Question, Question> _LeftQuestions;
// Map of maps of metadata // Map of maps of metadata
...@@ -69,6 +78,7 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -69,6 +78,7 @@ public abstract class BaseQuestion extends BaseBusinessClass
// Arrays of validators for each attribute // Arrays of validators for each attribute
private static final AttributeValidator[] FIELD_Description_Validators; private static final AttributeValidator[] FIELD_Description_Validators;
private static final AttributeValidator[] FIELD_IsRightQuestion_Validators;
// Arrays of behaviour decorators // Arrays of behaviour decorators
...@@ -80,13 +90,18 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -80,13 +90,18 @@ public abstract class BaseQuestion extends BaseBusinessClass
{ {
String tmp_Factors = FactorQuestionLink.BACKREF_Question; String tmp_Factors = FactorQuestionLink.BACKREF_Question;
String tmp_LeftQuestions = Question.BACKREF_RightQuestion;
String tmp_Section = Section.BACKREF_Questions; String tmp_Section = Section.BACKREF_Questions;
String tmp_RightQuestion = Question.BACKREF_LeftQuestions;
Map validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping")); Map validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));
setupAssocMetaData_Factors(); setupAssocMetaData_Factors();
setupAssocMetaData_LeftQuestions();
setupAssocMetaData_Section(); setupAssocMetaData_Section();
setupAssocMetaData_RightQuestion();
FIELD_Description_Validators = (AttributeValidator[])setupAttribMetaData_Description(validatorMapping).toArray (new AttributeValidator[0]); FIELD_Description_Validators = (AttributeValidator[])setupAttribMetaData_Description(validatorMapping).toArray (new AttributeValidator[0]);
FIELD_IsRightQuestion_Validators = (AttributeValidator[])setupAttribMetaData_IsRightQuestion(validatorMapping).toArray (new AttributeValidator[0]);
REFERENCE_Question.initialiseReference (); REFERENCE_Question.initialiseReference ();
...@@ -116,6 +131,20 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -116,6 +131,20 @@ public abstract class BaseQuestion extends BaseBusinessClass
// Meta Info setup // Meta Info setup
private static void setupAssocMetaData_LeftQuestions()
{
Map metaInfo = new HashMap ();
metaInfo.put ("backreferenceName", "RightQuestion");
metaInfo.put ("name", "LeftQuestions");
metaInfo.put ("type", "Question");
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Question.LeftQuestions:", metaInfo);
ATTRIBUTES_METADATA_Question.put (MULTIPLEREFERENCE_LeftQuestions, Collections.unmodifiableMap (metaInfo));
}
// Meta Info setup
private static void setupAssocMetaData_Section() private static void setupAssocMetaData_Section()
{ {
Map metaInfo = new HashMap (); Map metaInfo = new HashMap ();
...@@ -131,11 +160,26 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -131,11 +160,26 @@ public abstract class BaseQuestion extends BaseBusinessClass
// Meta Info setup // Meta Info setup
private static void setupAssocMetaData_RightQuestion()
{
Map metaInfo = new HashMap ();
metaInfo.put ("backreferenceName", "LeftQuestions");
metaInfo.put ("dbcol", "right_quest_number");
metaInfo.put ("name", "RightQuestion");
metaInfo.put ("type", "Question");
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Question.RightQuestion:", metaInfo);
ATTRIBUTES_METADATA_Question.put (SINGLEREFERENCE_RightQuestion, Collections.unmodifiableMap (metaInfo));
}
// Meta Info setup
private static List setupAttribMetaData_Description(Map validatorMapping) private static List setupAttribMetaData_Description(Map validatorMapping)
{ {
Map metaInfo = new HashMap (); Map metaInfo = new HashMap ();
metaInfo.put ("dbcol", "left_quest"); metaInfo.put ("dbcol", "description");
metaInfo.put ("length", "80"); metaInfo.put ("length", "80");
metaInfo.put ("name", "Description"); metaInfo.put ("name", "Description");
metaInfo.put ("type", "String"); metaInfo.put ("type", "String");
...@@ -149,6 +193,25 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -149,6 +193,25 @@ public abstract class BaseQuestion extends BaseBusinessClass
return validators; return validators;
} }
// Meta Info setup
private static List setupAttribMetaData_IsRightQuestion(Map validatorMapping)
{
Map metaInfo = new HashMap ();
metaInfo.put ("dbcol", "is_right_quest");
metaInfo.put ("defaultValue", "Boolean.FALSE");
metaInfo.put ("name", "IsRightQuestion");
metaInfo.put ("type", "Boolean");
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Question.IsRightQuestion:", metaInfo);
ATTRIBUTES_METADATA_Question.put (FIELD_IsRightQuestion, Collections.unmodifiableMap (metaInfo));
List validators = BaseBusinessClass.getAttribValidators(Question.class, "IsRightQuestion", metaInfo, validatorMapping);
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for Question.IsRightQuestion:", validators);
return validators;
}
// END OF STATIC METADATA DEFINITION // END OF STATIC METADATA DEFINITION
...@@ -177,6 +240,7 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -177,6 +240,7 @@ public abstract class BaseQuestion extends BaseBusinessClass
_Description = (String)(HELPER_Description.initialise (_Description)); _Description = (String)(HELPER_Description.initialise (_Description));
_IsRightQuestion = (Boolean)(Boolean.FALSE);
} }
...@@ -186,7 +250,9 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -186,7 +250,9 @@ public abstract class BaseQuestion extends BaseBusinessClass
super._initialiseAssociations (); super._initialiseAssociations ();
_Section = new SingleAssociation<Question, Section> (this, SINGLEREFERENCE_Section, Section.MULTIPLEREFERENCE_Questions, Section.REFERENCE_Section, "tl_quest_lin"); _Section = new SingleAssociation<Question, Section> (this, SINGLEREFERENCE_Section, Section.MULTIPLEREFERENCE_Questions, Section.REFERENCE_Section, "tl_quest_lin");
_RightQuestion = new SingleAssociation<Question, Question> (this, SINGLEREFERENCE_RightQuestion, Question.MULTIPLEREFERENCE_LeftQuestions, Question.REFERENCE_Question, "tl_quest_lin");
_Factors = new MultipleAssociation<Question, FactorQuestionLink> (this, MULTIPLEREFERENCE_Factors, FactorQuestionLink.SINGLEREFERENCE_Question, FactorQuestionLink.REFERENCE_FactorQuestionLink); _Factors = new MultipleAssociation<Question, FactorQuestionLink> (this, MULTIPLEREFERENCE_Factors, FactorQuestionLink.SINGLEREFERENCE_Question, FactorQuestionLink.REFERENCE_FactorQuestionLink);
_LeftQuestions = new MultipleAssociation<Question, Question> (this, MULTIPLEREFERENCE_LeftQuestions, Question.SINGLEREFERENCE_RightQuestion, Question.REFERENCE_Question);
} }
...@@ -197,7 +263,9 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -197,7 +263,9 @@ public abstract class BaseQuestion extends BaseBusinessClass
super.initialiseReference (); super.initialiseReference ();
_Section = new SingleAssociation<Question, Section> (this, SINGLEREFERENCE_Section, Section.MULTIPLEREFERENCE_Questions, Section.REFERENCE_Section, "tl_quest_lin"); _Section = new SingleAssociation<Question, Section> (this, SINGLEREFERENCE_Section, Section.MULTIPLEREFERENCE_Questions, Section.REFERENCE_Section, "tl_quest_lin");
_RightQuestion = new SingleAssociation<Question, Question> (this, SINGLEREFERENCE_RightQuestion, Question.MULTIPLEREFERENCE_LeftQuestions, Question.REFERENCE_Question, "tl_quest_lin");
_Factors = new MultipleAssociation<Question, FactorQuestionLink> (this, MULTIPLEREFERENCE_Factors, FactorQuestionLink.SINGLEREFERENCE_Question, FactorQuestionLink.REFERENCE_FactorQuestionLink); _Factors = new MultipleAssociation<Question, FactorQuestionLink> (this, MULTIPLEREFERENCE_Factors, FactorQuestionLink.SINGLEREFERENCE_Question, FactorQuestionLink.REFERENCE_FactorQuestionLink);
_LeftQuestions = new MultipleAssociation<Question, Question> (this, MULTIPLEREFERENCE_LeftQuestions, Question.SINGLEREFERENCE_RightQuestion, Question.REFERENCE_Question);
return this; return this;
...@@ -303,6 +371,104 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -303,6 +371,104 @@ public abstract class BaseQuestion extends BaseBusinessClass
} }
} }
/**
* Get the attribute IsRightQuestion
*/
public Boolean getIsRightQuestion ()
{
assertValid();
Boolean valToReturn = _IsRightQuestion;
for (QuestionBehaviourDecorator bhd : Question_BehaviourDecorators)
{
valToReturn = bhd.getIsRightQuestion ((Question)this, valToReturn);
}
return valToReturn;
}
/**
* Called prior to the attribute changing. Subclasses need not call super. If a field exception
* is thrown, the attribute change will fail. The new value is different to the old value.
*/
protected void preIsRightQuestionChange (Boolean newIsRightQuestion) throws FieldException
{
}
/**
* Called after the attribute changes.
* If a field exception is thrown, the value is still changed, however it
* may lead to the TX being rolled back
*/
protected void postIsRightQuestionChange () throws FieldException
{
}
public FieldWriteability getWriteability_IsRightQuestion ()
{
return getFieldWritabilityUtil (FieldWriteability.TRUE);
}
/**
* Set the attribute IsRightQuestion. Checks to ensure a new value
* has been supplied. If so, marks the field as altered and sets the attribute.
*/
public void setIsRightQuestion (Boolean newIsRightQuestion) throws FieldException
{
boolean oldAndNewIdentical = HELPER_IsRightQuestion.compare (_IsRightQuestion, newIsRightQuestion);
try
{
for (QuestionBehaviourDecorator bhd : Question_BehaviourDecorators)
{
newIsRightQuestion = bhd.setIsRightQuestion ((Question)this, newIsRightQuestion);
oldAndNewIdentical = HELPER_IsRightQuestion.compare (_IsRightQuestion, newIsRightQuestion);
}
if (FIELD_IsRightQuestion_Validators.length > 0)
{
Object newIsRightQuestionObj = HELPER_IsRightQuestion.toObject (newIsRightQuestion);
if (newIsRightQuestionObj != null)
{
int loopMax = FIELD_IsRightQuestion_Validators.length;
Map metadata = (Map)ATTRIBUTES_METADATA_Question.get (FIELD_IsRightQuestion);
for (int v = 0 ; v < loopMax ; ++v)
{
FIELD_IsRightQuestion_Validators[v].checkAttribute (this, FIELD_IsRightQuestion, metadata, newIsRightQuestionObj);
}
}
}
}
catch (FieldException e)
{
if (!oldAndNewIdentical)
{
e.setWouldModify ();
}
throw e;
}
if (!oldAndNewIdentical)
{
assertValid();
Debug.assertion (getWriteability_IsRightQuestion () != FieldWriteability.FALSE, "Field IsRightQuestion is not writeable");
preIsRightQuestionChange (newIsRightQuestion);
markFieldChange (FIELD_IsRightQuestion);
_IsRightQuestion = newIsRightQuestion;
postFieldChange (FIELD_IsRightQuestion);
postIsRightQuestionChange ();
}
}
/** /**
...@@ -315,6 +481,8 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -315,6 +481,8 @@ public abstract class BaseQuestion extends BaseBusinessClass
result.add("Section"); result.add("Section");
result.add("RightQuestion");
return result; return result;
} }
...@@ -329,6 +497,9 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -329,6 +497,9 @@ public abstract class BaseQuestion extends BaseBusinessClass
else if (assocName.equals (SINGLEREFERENCE_Section)) else if (assocName.equals (SINGLEREFERENCE_Section))
{ {
return _Section.getReferencedType (); return _Section.getReferencedType ();
}else if (assocName.equals (SINGLEREFERENCE_RightQuestion))
{
return _RightQuestion.getReferencedType ();
} }
else else
{ {
...@@ -346,6 +517,9 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -346,6 +517,9 @@ public abstract class BaseQuestion extends BaseBusinessClass
else if (assocName.equals (SINGLEREFERENCE_Section)) else if (assocName.equals (SINGLEREFERENCE_Section))
{ {
return Section.MULTIPLEREFERENCE_Questions ; return Section.MULTIPLEREFERENCE_Questions ;
}else if (assocName.equals (SINGLEREFERENCE_RightQuestion))
{
return Question.MULTIPLEREFERENCE_LeftQuestions ;
} }
else else
{ {
...@@ -363,6 +537,9 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -363,6 +537,9 @@ public abstract class BaseQuestion extends BaseBusinessClass
else if (assocName.equals (SINGLEREFERENCE_Section)) else if (assocName.equals (SINGLEREFERENCE_Section))
{ {
return getSection (); return getSection ();
}else if (assocName.equals (SINGLEREFERENCE_RightQuestion))
{
return getRightQuestion ();
} }
else else
{ {
...@@ -380,6 +557,9 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -380,6 +557,9 @@ public abstract class BaseQuestion extends BaseBusinessClass
else if (assocName.equals (SINGLEREFERENCE_Section)) else if (assocName.equals (SINGLEREFERENCE_Section))
{ {
return getSection (getType); return getSection (getType);
}else if (assocName.equals (SINGLEREFERENCE_RightQuestion))
{
return getRightQuestion (getType);
} }
else else
{ {
...@@ -397,6 +577,9 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -397,6 +577,9 @@ public abstract class BaseQuestion extends BaseBusinessClass
else if (assocName.equals (SINGLEREFERENCE_Section)) else if (assocName.equals (SINGLEREFERENCE_Section))
{ {
return getSectionID (); return getSectionID ();
}else if (assocName.equals (SINGLEREFERENCE_RightQuestion))
{
return getRightQuestionID ();
} }
else else
{ {
...@@ -414,6 +597,9 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -414,6 +597,9 @@ public abstract class BaseQuestion extends BaseBusinessClass
else if (assocName.equals (SINGLEREFERENCE_Section)) else if (assocName.equals (SINGLEREFERENCE_Section))
{ {
setSection ((Section)(newValue)); setSection ((Section)(newValue));
}else if (assocName.equals (SINGLEREFERENCE_RightQuestion))
{
setRightQuestion ((Question)(newValue));
} }
else else
{ {
...@@ -531,6 +717,113 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -531,6 +717,113 @@ public abstract class BaseQuestion extends BaseBusinessClass
} }
/** /**
* Get the reference RightQuestion
*/
public Question getRightQuestion () throws StorageException
{
assertValid();
try
{
return (Question)(_RightQuestion.get ());
}
catch (ClassCastException e)
{
LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in Question:", this.getObjectID (), ", was trying to get Question:", getRightQuestionID ());
LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _RightQuestion.get ().getClass ());
throw e;
}
}
/**
* Get the object id for the referenced object. Does not force a DB access.
*/
public Question getRightQuestion (Get getType) throws StorageException
{
assertValid();
return _RightQuestion.get(getType);
}
/**
* Get the object id for the referenced object. Does not force a DB access.
*/
public Long getRightQuestionID ()
{
assertValid();
if (_RightQuestion == null)
{
return null;
}
else
{
return _RightQuestion.getID ();
}
}
/**
* Called prior to the assoc changing. Subclasses need not call super. If a field exception
* is thrown, the attribute change will fail. The new value is different to the old value.
*/
protected void preRightQuestionChange (Question newRightQuestion) throws FieldException
{
}
/**
* Called after the assoc changes.
* If a field exception is thrown, the value is still changed, however it
* may lead to the TX being rolled back
*/
protected void postRightQuestionChange () throws FieldException
{
}
public FieldWriteability getWriteability_RightQuestion ()
{
return getFieldWritabilityUtil (FieldWriteability.TRUE);
}
/**
* Set the reference RightQuestion. Checks to ensure a new value
* has been supplied. If so, marks the reference as altered and sets it.
*/
public void setRightQuestion (Question newRightQuestion) throws StorageException, FieldException
{
if (_RightQuestion.wouldReferencedChange (newRightQuestion))
{
assertValid();
Debug.assertion (getWriteability_RightQuestion () != FieldWriteability.FALSE, "Assoc RightQuestion is not writeable");
preRightQuestionChange (newRightQuestion);
Question oldRightQuestion = getRightQuestion ();
if (oldRightQuestion != null)
{
// This is to stop validation from triggering when we are removed
_RightQuestion.set (null);
oldRightQuestion.removeFromLeftQuestions ((Question)(this));
}
_RightQuestion.set (newRightQuestion);
if (newRightQuestion != null)
{
newRightQuestion.addToLeftQuestions ((Question)(this));
}
postRightQuestionChange ();
}
}
/**
* A list of multi assoc names e.g. list of strings. * A list of multi assoc names e.g. list of strings.
*/ */
public List<String> getMultiAssocs() public List<String> getMultiAssocs()
...@@ -540,6 +833,8 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -540,6 +833,8 @@ public abstract class BaseQuestion extends BaseBusinessClass
result.add("Factors"); result.add("Factors");
result.add("LeftQuestions");
return result; return result;
} }
...@@ -556,6 +851,11 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -556,6 +851,11 @@ public abstract class BaseQuestion extends BaseBusinessClass
return FactorQuestionLink.REFERENCE_FactorQuestionLink ; return FactorQuestionLink.REFERENCE_FactorQuestionLink ;
} }
if (MULTIPLEREFERENCE_LeftQuestions.equals(attribName))
{
return Question.REFERENCE_Question ;
}
return super.getMultiAssocReferenceInstance(attribName); return super.getMultiAssocReferenceInstance(attribName);
} }
...@@ -569,6 +869,11 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -569,6 +869,11 @@ public abstract class BaseQuestion extends BaseBusinessClass
return FactorQuestionLink.SINGLEREFERENCE_Question ; return FactorQuestionLink.SINGLEREFERENCE_Question ;
} }
if (MULTIPLEREFERENCE_LeftQuestions.equals(attribName))
{
return Question.SINGLEREFERENCE_RightQuestion ;
}
return super.getMultiAssocBackReference(attribName); return super.getMultiAssocBackReference(attribName);
} }
...@@ -585,6 +890,11 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -585,6 +890,11 @@ public abstract class BaseQuestion extends BaseBusinessClass
return this.getFactorsCount(); return this.getFactorsCount();
} }
if (MULTIPLEREFERENCE_LeftQuestions.equals(attribName))
{
return this.getLeftQuestionsCount();
}
return super.getMultiAssocCount(attribName); return super.getMultiAssocCount(attribName);
} }
...@@ -601,6 +911,11 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -601,6 +911,11 @@ public abstract class BaseQuestion extends BaseBusinessClass
return this.getFactorsAt(index); return this.getFactorsAt(index);
} }
if (MULTIPLEREFERENCE_LeftQuestions.equals(attribName))
{
return this.getLeftQuestionsAt(index);
}
return super.getMultiAssocAt(attribName, index); return super.getMultiAssocAt(attribName, index);
} }
...@@ -619,6 +934,13 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -619,6 +934,13 @@ public abstract class BaseQuestion extends BaseBusinessClass
return; return;
} }
if (MULTIPLEREFERENCE_LeftQuestions.equals(attribName))
{
addToLeftQuestions((Question)newElement);
return;
}
super.addToMultiAssoc(attribName, newElement); super.addToMultiAssoc(attribName, newElement);
} }
...@@ -636,6 +958,13 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -636,6 +958,13 @@ public abstract class BaseQuestion extends BaseBusinessClass
return; return;
} }
if (MULTIPLEREFERENCE_LeftQuestions.equals(attribName))
{
removeFromLeftQuestions((Question)oldElement);
return;
}
super.removeFromMultiAssoc(attribName, oldElement); super.removeFromMultiAssoc(attribName, oldElement);
} }
...@@ -650,6 +979,12 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -650,6 +979,12 @@ public abstract class BaseQuestion extends BaseBusinessClass
return; return;
} }
if (MULTIPLEREFERENCE_LeftQuestions.equals(attribName))
{
_LeftQuestions.__loadAssociation (elements);
return;
}
super.__loadMultiAssoc(attribName, elements); super.__loadMultiAssoc(attribName, elements);
} }
...@@ -663,6 +998,11 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -663,6 +998,11 @@ public abstract class BaseQuestion extends BaseBusinessClass
return _Factors.isLoaded (); return _Factors.isLoaded ();
} }
if (MULTIPLEREFERENCE_LeftQuestions.equals(attribName))
{
return _LeftQuestions.isLoaded ();
}
return super.__isMultiAssocLoaded(attribName); return super.__isMultiAssocLoaded(attribName);
} }
...@@ -738,6 +1078,75 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -738,6 +1078,75 @@ public abstract class BaseQuestion extends BaseBusinessClass
return _Factors.getSet (); return _Factors.getSet ();
} }
public FieldWriteability getWriteability_LeftQuestions ()
{
return getFieldWritabilityUtil (FieldWriteability.TRUE);
}
public int getLeftQuestionsCount () throws StorageException
{
assertValid();
return _LeftQuestions.getReferencedObjectsCount ();
}
public void addToLeftQuestions (Question newElement) throws StorageException
{
if (_LeftQuestions.wouldAddChange (newElement))
{
assertValid();
Debug.assertion (getWriteability_LeftQuestions () != FieldWriteability.FALSE, "MultiAssoc LeftQuestions is not writeable (add)");
_LeftQuestions.appendElement (newElement);
try
{
if (newElement.getRightQuestion () != this)
{
newElement.setRightQuestion ((Question)(this));
}
}
catch (Exception e)
{
throw NestedException.wrap(e);
}
}
}
public void removeFromLeftQuestions (Question elementToRemove) throws StorageException
{
if (_LeftQuestions.wouldRemoveChange (elementToRemove))
{
assertValid();
Debug.assertion (getWriteability_LeftQuestions () != FieldWriteability.FALSE, "MultiAssoc LeftQuestions is not writeable (remove)");
_LeftQuestions.removeElement (elementToRemove);
try
{
if (elementToRemove.getRightQuestion () != null)
{
elementToRemove.setRightQuestion (null);
}
}
catch (Exception e)
{
throw NestedException.wrap(e);
}
}
}
public Question getLeftQuestionsAt (int index) throws StorageException
{
return (Question)(_LeftQuestions.getElementAt (index));
}
public SortedSet<Question> getLeftQuestionsSet () throws StorageException
{
return _LeftQuestions.getSet ();
}
public void onDelete () public void onDelete ()
...@@ -758,12 +1167,32 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -758,12 +1167,32 @@ public abstract class BaseQuestion extends BaseBusinessClass
} }
} }
// Ensure we are removed from any loaded multi-associations that aren't mandatory
if (_RightQuestion.isLoaded () || getTransaction ().isObjectLoaded (_RightQuestion.getReferencedType (), getRightQuestionID ()))
{
Question referenced = getRightQuestion ();
if (referenced != null)
{
// Stop the callback
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null LeftQuestions from ", getObjectID (), " to ", referenced.getObjectID ());
_RightQuestion.set (null);
referenced.removeFromLeftQuestions ((Question)this);
}
}
for(FactorQuestionLink referenced : CollectionUtils.reverse(getFactorsSet())) for(FactorQuestionLink referenced : CollectionUtils.reverse(getFactorsSet()))
{ {
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Question from ", getObjectID (), " to ", referenced.getObjectID ()); LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Question from ", getObjectID (), " to ", referenced.getObjectID ());
referenced.setQuestion(null); referenced.setQuestion(null);
} }
for(Question referenced : CollectionUtils.reverse(getLeftQuestionsSet()))
{
LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null RightQuestion from ", getObjectID (), " to ", referenced.getObjectID ());
referenced.setRightQuestion(null);
}
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -825,7 +1254,9 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -825,7 +1254,9 @@ public abstract class BaseQuestion extends BaseBusinessClass
tl_quest_linPSet.setAttrib (FIELD_ObjectID, myID); tl_quest_linPSet.setAttrib (FIELD_ObjectID, myID);
tl_quest_linPSet.setAttrib (FIELD_Description, HELPER_Description.toObject (_Description)); // tl_quest_linPSet.setAttrib (FIELD_Description, HELPER_Description.toObject (_Description)); //
tl_quest_linPSet.setAttrib (FIELD_IsRightQuestion, HELPER_IsRightQuestion.toObject (_IsRightQuestion)); //
_Section.getPersistentSets (allSets); _Section.getPersistentSets (allSets);
_RightQuestion.getPersistentSets (allSets);
} }
...@@ -841,7 +1272,9 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -841,7 +1272,9 @@ public abstract class BaseQuestion extends BaseBusinessClass
PersistentSet tl_quest_linPSet = allSets.getPersistentSet (objectID, "tl_quest_lin"); PersistentSet tl_quest_linPSet = allSets.getPersistentSet (objectID, "tl_quest_lin");
_Description = (String)(HELPER_Description.fromObject (_Description, tl_quest_linPSet.getAttrib (FIELD_Description))); // _Description = (String)(HELPER_Description.fromObject (_Description, tl_quest_linPSet.getAttrib (FIELD_Description))); //
_IsRightQuestion = (Boolean)(HELPER_IsRightQuestion.fromObject (_IsRightQuestion, tl_quest_linPSet.getAttrib (FIELD_IsRightQuestion))); //
_Section.setFromPersistentSets (objectID, allSets); _Section.setFromPersistentSets (objectID, allSets);
_RightQuestion.setFromPersistentSets (objectID, allSets);
} }
...@@ -866,6 +1299,15 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -866,6 +1299,15 @@ public abstract class BaseQuestion extends BaseBusinessClass
e.addException (ex); e.addException (ex);
} }
try
{
setIsRightQuestion (otherQuestion.getIsRightQuestion ());
}
catch (FieldException ex)
{
e.addException (ex);
}
} }
} }
...@@ -882,6 +1324,7 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -882,6 +1324,7 @@ public abstract class BaseQuestion extends BaseBusinessClass
BaseQuestion sourceQuestion = (BaseQuestion)(source); BaseQuestion sourceQuestion = (BaseQuestion)(source);
_Description = sourceQuestion._Description; _Description = sourceQuestion._Description;
_IsRightQuestion = sourceQuestion._IsRightQuestion;
} }
} }
...@@ -899,6 +1342,7 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -899,6 +1342,7 @@ public abstract class BaseQuestion extends BaseBusinessClass
BaseQuestion sourceQuestion = (BaseQuestion)(source); BaseQuestion sourceQuestion = (BaseQuestion)(source);
_Section.copyFrom (sourceQuestion._Section, linkToGhosts); _Section.copyFrom (sourceQuestion._Section, linkToGhosts);
_RightQuestion.copyFrom (sourceQuestion._RightQuestion, linkToGhosts);
} }
} }
...@@ -916,6 +1360,7 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -916,6 +1360,7 @@ public abstract class BaseQuestion extends BaseBusinessClass
BaseQuestion sourceQuestion = (BaseQuestion)(source); BaseQuestion sourceQuestion = (BaseQuestion)(source);
_Factors.copyFrom (sourceQuestion._Factors, linkToGhosts); _Factors.copyFrom (sourceQuestion._Factors, linkToGhosts);
_LeftQuestions.copyFrom (sourceQuestion._LeftQuestions, linkToGhosts);
} }
} }
...@@ -937,8 +1382,11 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -937,8 +1382,11 @@ public abstract class BaseQuestion extends BaseBusinessClass
super.readExternalData(vals); super.readExternalData(vals);
_Description = (String)(HELPER_Description.readExternal (_Description, vals.get(FIELD_Description))); // _Description = (String)(HELPER_Description.readExternal (_Description, vals.get(FIELD_Description))); //
_IsRightQuestion = (Boolean)(HELPER_IsRightQuestion.readExternal (_IsRightQuestion, vals.get(FIELD_IsRightQuestion))); //
_Section.readExternalData(vals.get(SINGLEREFERENCE_Section)); _Section.readExternalData(vals.get(SINGLEREFERENCE_Section));
_RightQuestion.readExternalData(vals.get(SINGLEREFERENCE_RightQuestion));
_Factors.readExternalData(vals.get(MULTIPLEREFERENCE_Factors)); _Factors.readExternalData(vals.get(MULTIPLEREFERENCE_Factors));
_LeftQuestions.readExternalData(vals.get(MULTIPLEREFERENCE_LeftQuestions));
} }
...@@ -951,8 +1399,11 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -951,8 +1399,11 @@ public abstract class BaseQuestion extends BaseBusinessClass
super.writeExternalData(vals); super.writeExternalData(vals);
vals.put (FIELD_Description, HELPER_Description.writeExternal (_Description)); vals.put (FIELD_Description, HELPER_Description.writeExternal (_Description));
vals.put (FIELD_IsRightQuestion, HELPER_IsRightQuestion.writeExternal (_IsRightQuestion));
vals.put (SINGLEREFERENCE_Section, _Section.writeExternalData()); vals.put (SINGLEREFERENCE_Section, _Section.writeExternalData());
vals.put (SINGLEREFERENCE_RightQuestion, _RightQuestion.writeExternalData());
vals.put (MULTIPLEREFERENCE_Factors, _Factors.writeExternalData()); vals.put (MULTIPLEREFERENCE_Factors, _Factors.writeExternalData());
vals.put (MULTIPLEREFERENCE_LeftQuestions, _LeftQuestions.writeExternalData());
} }
...@@ -970,13 +1421,19 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -970,13 +1421,19 @@ public abstract class BaseQuestion extends BaseBusinessClass
{ {
listener.notifyFieldChange(this, other, FIELD_Description, HELPER_Description.toObject(this._Description), HELPER_Description.toObject(otherQuestion._Description)); listener.notifyFieldChange(this, other, FIELD_Description, HELPER_Description.toObject(this._Description), HELPER_Description.toObject(otherQuestion._Description));
} }
if (!HELPER_IsRightQuestion.compare(this._IsRightQuestion, otherQuestion._IsRightQuestion))
{
listener.notifyFieldChange(this, other, FIELD_IsRightQuestion, HELPER_IsRightQuestion.toObject(this._IsRightQuestion), HELPER_IsRightQuestion.toObject(otherQuestion._IsRightQuestion));
}
// Compare single assocs // Compare single assocs
_Section.compare (otherQuestion._Section, listener); _Section.compare (otherQuestion._Section, listener);
_RightQuestion.compare (otherQuestion._RightQuestion, listener);
// Compare multiple assocs // Compare multiple assocs
_Factors.compare (otherQuestion._Factors, listener); _Factors.compare (otherQuestion._Factors, listener);
_LeftQuestions.compare (otherQuestion._LeftQuestions, listener);
} }
} }
...@@ -995,8 +1452,11 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -995,8 +1452,11 @@ public abstract class BaseQuestion extends BaseBusinessClass
super.visitAttributes (visitor); super.visitAttributes (visitor);
visitor.visitField(this, FIELD_Description, HELPER_Description.toObject(getDescription())); visitor.visitField(this, FIELD_Description, HELPER_Description.toObject(getDescription()));
visitor.visitField(this, FIELD_IsRightQuestion, HELPER_IsRightQuestion.toObject(getIsRightQuestion()));
visitor.visitAssociation (_Section); visitor.visitAssociation (_Section);
visitor.visitAssociation (_RightQuestion);
visitor.visitAssociation (_Factors); visitor.visitAssociation (_Factors);
visitor.visitAssociation (_LeftQuestions);
} }
...@@ -1009,10 +1469,18 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1009,10 +1469,18 @@ public abstract class BaseQuestion extends BaseBusinessClass
{ {
visitor.visit (_Section); visitor.visit (_Section);
} }
if (scope.includes (_RightQuestion))
{
visitor.visit (_RightQuestion);
}
if (scope.includes (_Factors)) if (scope.includes (_Factors))
{ {
visitor.visit (_Factors); visitor.visit (_Factors);
} }
if (scope.includes (_LeftQuestions))
{
visitor.visit (_LeftQuestions);
}
} }
...@@ -1042,10 +1510,18 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1042,10 +1510,18 @@ public abstract class BaseQuestion extends BaseBusinessClass
{ {
return filter.matches (getDescription ()); return filter.matches (getDescription ());
} }
else if (attribName.equals (FIELD_IsRightQuestion))
{
return filter.matches (getIsRightQuestion ());
}
else if (attribName.equals (SINGLEREFERENCE_Section)) else if (attribName.equals (SINGLEREFERENCE_Section))
{ {
return filter.matches (getSection ()); return filter.matches (getSection ());
} }
else if (attribName.equals (SINGLEREFERENCE_RightQuestion))
{
return filter.matches (getRightQuestion ());
}
else else
{ {
return super.testFilter (attribName, filter); return super.testFilter (attribName, filter);
...@@ -1079,7 +1555,13 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1079,7 +1555,13 @@ public abstract class BaseQuestion extends BaseBusinessClass
public SearchAll andDescription (QueryFilter<String> filter) public SearchAll andDescription (QueryFilter<String> filter)
{ {
filter.addFilter (context, "tl_quest_lin.left_quest", "Description"); filter.addFilter (context, "tl_quest_lin.description", "Description");
return this;
}
public SearchAll andIsRightQuestion (QueryFilter<Boolean> filter)
{
filter.addFilter (context, "tl_quest_lin.is_right_quest", "IsRightQuestion");
return this; return this;
} }
...@@ -1089,6 +1571,12 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1089,6 +1571,12 @@ public abstract class BaseQuestion extends BaseBusinessClass
return this; return this;
} }
public SearchAll andRightQuestion (QueryFilter<Question> filter)
{
filter.addFilter (context, "tl_quest_lin.right_quest_number", "RightQuestion");
return this;
}
public Question[] public Question[]
search (ObjectTransaction transaction) throws StorageException search (ObjectTransaction transaction) throws StorageException
{ {
...@@ -1128,6 +1616,10 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1128,6 +1616,10 @@ public abstract class BaseQuestion extends BaseBusinessClass
{ {
return HELPER_Description.toObject (getDescription ()); return HELPER_Description.toObject (getDescription ());
} }
else if (attribName.equals (FIELD_IsRightQuestion))
{
return HELPER_IsRightQuestion.toObject (getIsRightQuestion ());
}
else else
{ {
return super.getAttribute (attribName); return super.getAttribute (attribName);
...@@ -1145,6 +1637,10 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1145,6 +1637,10 @@ public abstract class BaseQuestion extends BaseBusinessClass
{ {
return HELPER_Description; return HELPER_Description;
} }
else if (attribName.equals (FIELD_IsRightQuestion))
{
return HELPER_IsRightQuestion;
}
else else
{ {
return super.getAttributeHelper (attribName); return super.getAttributeHelper (attribName);
...@@ -1162,6 +1658,10 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1162,6 +1658,10 @@ public abstract class BaseQuestion extends BaseBusinessClass
{ {
setDescription ((String)(HELPER_Description.fromObject (_Description, attribValue))); setDescription ((String)(HELPER_Description.fromObject (_Description, attribValue)));
} }
else if (attribName.equals (FIELD_IsRightQuestion))
{
setIsRightQuestion ((Boolean)(HELPER_IsRightQuestion.fromObject (_IsRightQuestion, attribValue)));
}
else else
{ {
super.setAttribute (attribName, attribValue); super.setAttribute (attribName, attribValue);
...@@ -1186,14 +1686,26 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1186,14 +1686,26 @@ public abstract class BaseQuestion extends BaseBusinessClass
{ {
return getWriteability_Description (); return getWriteability_Description ();
} }
else if (fieldName.equals (FIELD_IsRightQuestion))
{
return getWriteability_IsRightQuestion ();
}
else if (fieldName.equals (MULTIPLEREFERENCE_Factors)) else if (fieldName.equals (MULTIPLEREFERENCE_Factors))
{ {
return getWriteability_Factors (); return getWriteability_Factors ();
} }
else if (fieldName.equals (MULTIPLEREFERENCE_LeftQuestions))
{
return getWriteability_LeftQuestions ();
}
else if (fieldName.equals (SINGLEREFERENCE_Section)) else if (fieldName.equals (SINGLEREFERENCE_Section))
{ {
return getWriteability_Section (); return getWriteability_Section ();
} }
else if (fieldName.equals (SINGLEREFERENCE_RightQuestion))
{
return getWriteability_RightQuestion ();
}
else else
{ {
return super.getWriteable (fieldName); return super.getWriteable (fieldName);
...@@ -1209,6 +1721,11 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1209,6 +1721,11 @@ public abstract class BaseQuestion extends BaseBusinessClass
fields.add (FIELD_Description); fields.add (FIELD_Description);
} }
if (getWriteability_IsRightQuestion () != FieldWriteability.TRUE)
{
fields.add (FIELD_IsRightQuestion);
}
super.putUnwriteable (fields); super.putUnwriteable (fields);
} }
...@@ -1219,6 +1736,7 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1219,6 +1736,7 @@ public abstract class BaseQuestion extends BaseBusinessClass
result.add(HELPER_Description.getAttribObject (getClass (), _Description, false, FIELD_Description)); result.add(HELPER_Description.getAttribObject (getClass (), _Description, false, FIELD_Description));
result.add(HELPER_IsRightQuestion.getAttribObject (getClass (), _IsRightQuestion, false, FIELD_IsRightQuestion));
return result; return result;
} }
...@@ -1287,6 +1805,24 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1287,6 +1805,24 @@ public abstract class BaseQuestion extends BaseBusinessClass
return newDescription; return newDescription;
} }
/**
* Get the attribute IsRightQuestion
*/
public Boolean getIsRightQuestion (Question obj, Boolean original)
{
return original;
}
/**
* Change the value set for attribute IsRightQuestion.
* May modify the field beforehand
* Occurs before validation.
*/
public Boolean setIsRightQuestion (Question obj, Boolean newIsRightQuestion) throws FieldException
{
return newIsRightQuestion;
}
} }
...@@ -1343,14 +1879,26 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1343,14 +1879,26 @@ public abstract class BaseQuestion extends BaseBusinessClass
{ {
return toFactors (); return toFactors ();
} }
if (name.equals ("LeftQuestions"))
{
return toLeftQuestions ();
}
if (name.equals ("Description")) if (name.equals ("Description"))
{ {
return toDescription (); return toDescription ();
} }
if (name.equals ("IsRightQuestion"))
{
return toIsRightQuestion ();
}
if (name.equals ("Section")) if (name.equals ("Section"))
{ {
return toSection (); return toSection ();
} }
if (name.equals ("RightQuestion"))
{
return toRightQuestion ();
}
return super.to(name); return super.to(name);
...@@ -1358,18 +1906,32 @@ public abstract class BaseQuestion extends BaseBusinessClass ...@@ -1358,18 +1906,32 @@ public abstract class BaseQuestion extends BaseBusinessClass
public PipeLine<From, String> toDescription () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Description)); } public PipeLine<From, String> toDescription () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Description)); }
public PipeLine<From, Boolean> toIsRightQuestion () { return pipe(new ORMAttributePipe<Me, Boolean>(FIELD_IsRightQuestion)); }
public Section.SectionPipeLineFactory<From, Section> toSection () { return toSection (Filter.ALL); } public Section.SectionPipeLineFactory<From, Section> toSection () { return toSection (Filter.ALL); }
public Section.SectionPipeLineFactory<From, Section> toSection (Filter<Section> filter) public Section.SectionPipeLineFactory<From, Section> toSection (Filter<Section> filter)
{ {
return Section.REFERENCE_Section.new SectionPipeLineFactory<From, Section> (this, new ORMSingleAssocPipe<Me, Section>(SINGLEREFERENCE_Section, filter)); return Section.REFERENCE_Section.new SectionPipeLineFactory<From, Section> (this, new ORMSingleAssocPipe<Me, Section>(SINGLEREFERENCE_Section, filter));
} }
public Question.QuestionPipeLineFactory<From, Question> toRightQuestion () { return toRightQuestion (Filter.ALL); }
public Question.QuestionPipeLineFactory<From, Question> toRightQuestion (Filter<Question> filter)
{
return Question.REFERENCE_Question.new QuestionPipeLineFactory<From, Question> (this, new ORMSingleAssocPipe<Me, Question>(SINGLEREFERENCE_RightQuestion, filter));
}
public FactorQuestionLink.FactorQuestionLinkPipeLineFactory<From, FactorQuestionLink> toFactors () { return toFactors(Filter.ALL); } public FactorQuestionLink.FactorQuestionLinkPipeLineFactory<From, FactorQuestionLink> toFactors () { return toFactors(Filter.ALL); }
public FactorQuestionLink.FactorQuestionLinkPipeLineFactory<From, FactorQuestionLink> toFactors (Filter<FactorQuestionLink> filter) public FactorQuestionLink.FactorQuestionLinkPipeLineFactory<From, FactorQuestionLink> toFactors (Filter<FactorQuestionLink> filter)
{ {
return FactorQuestionLink.REFERENCE_FactorQuestionLink.new FactorQuestionLinkPipeLineFactory<From, FactorQuestionLink> (this, new ORMMultiAssocPipe<Me, FactorQuestionLink>(MULTIPLEREFERENCE_Factors, filter)); return FactorQuestionLink.REFERENCE_FactorQuestionLink.new FactorQuestionLinkPipeLineFactory<From, FactorQuestionLink> (this, new ORMMultiAssocPipe<Me, FactorQuestionLink>(MULTIPLEREFERENCE_Factors, filter));
} }
public Question.QuestionPipeLineFactory<From, Question> toLeftQuestions () { return toLeftQuestions(Filter.ALL); }
public Question.QuestionPipeLineFactory<From, Question> toLeftQuestions (Filter<Question> filter)
{
return Question.REFERENCE_Question.new QuestionPipeLineFactory<From, Question> (this, new ORMMultiAssocPipe<Me, Question>(MULTIPLEREFERENCE_LeftQuestions, filter));
}
} }
...@@ -1415,6 +1977,20 @@ class DummyQuestion extends Question ...@@ -1415,6 +1977,20 @@ class DummyQuestion extends Question
return Section.DUMMY_Section.getObjectID(); return Section.DUMMY_Section.getObjectID();
} }
public Question getRightQuestion () throws StorageException
{
return (Question)(Question.DUMMY_Question);
}
/**
* Get the object id for the referenced object. Does not force a DB access.
*/
public Long getRightQuestionID ()
{
return Question.DUMMY_Question.getObjectID();
}
public int getFactorsCount () throws StorageException public int getFactorsCount () throws StorageException
{ {
return 0; return 0;
...@@ -1432,6 +2008,23 @@ class DummyQuestion extends Question ...@@ -1432,6 +2008,23 @@ class DummyQuestion extends Question
return new TreeSet(); return new TreeSet();
} }
public int getLeftQuestionsCount () throws StorageException
{
return 0;
}
public Question getLeftQuestionsAt (int index) throws StorageException
{
throw new RuntimeException ("No elements in a dummy object in association LeftQuestions");
}
public SortedSet getLeftQuestionsSet () throws StorageException
{
return new TreeSet();
}
} }
...@@ -4,13 +4,16 @@ ...@@ -4,13 +4,16 @@
<BUSINESSCLASS name="Question" package="performa.orm"> <BUSINESSCLASS name="Question" package="performa.orm">
<MULTIPLEREFERENCE name="Factors" type="FactorQuestionLink" backreferenceName="Question" /> <MULTIPLEREFERENCE name="Factors" type="FactorQuestionLink" backreferenceName="Question" />
<MULTIPLEREFERENCE name="LeftQuestions" type="Question" backreferenceName="RightQuestion" /> <!-- Can't be greater than 1 -->
<TABLE name="tl_quest_lin" tablePrefix="object" polymorphic="FALSE"> <TABLE name="tl_quest_lin" tablePrefix="object" polymorphic="FALSE">
<ATTRIB name="Description" type="String" dbcol="left_quest" length="80"/> <ATTRIB name="Description" type="String" dbcol="description" length="80"/>
<ATTRIB name="IsRightQuestion" type="Boolean" dbcol="is_right_quest" defaultValue="Boolean.FALSE"/>
<SINGLEREFERENCE name="Section" type="Section" dbcol="section_number" backreferenceName="Questions"/> <SINGLEREFERENCE name="Section" type="Section" dbcol="section_number" backreferenceName="Questions"/>
<SINGLEREFERENCE name="RightQuestion" type="Question" dbcol="right_quest_number" backreferenceName="LeftQuestions"/>
</TABLE> </TABLE>
......
...@@ -27,10 +27,12 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr ...@@ -27,10 +27,12 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr
// Private attributes corresponding to business object data // Private attributes corresponding to business object data
private String dummyDescription; private String dummyDescription;
private Boolean dummyIsRightQuestion;
// Static constants corresponding to attribute helpers // Static constants corresponding to attribute helpers
private static final DefaultAttributeHelper HELPER_Description = DefaultAttributeHelper.INSTANCE; private static final DefaultAttributeHelper HELPER_Description = DefaultAttributeHelper.INSTANCE;
private static final DefaultAttributeHelper HELPER_IsRightQuestion = DefaultAttributeHelper.INSTANCE;
...@@ -38,10 +40,11 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr ...@@ -38,10 +40,11 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr
public QuestionPersistenceMgr () public QuestionPersistenceMgr ()
{ {
dummyDescription = (String)(HELPER_Description.initialise (dummyDescription)); dummyDescription = (String)(HELPER_Description.initialise (dummyDescription));
dummyIsRightQuestion = (Boolean)(HELPER_IsRightQuestion.initialise (dummyIsRightQuestion));
} }
private String SELECT_COLUMNS = "{PREFIX}tl_quest_lin.object_id as id, {PREFIX}tl_quest_lin.object_LAST_UPDATED_DATE as LAST_UPDATED_DATE, {PREFIX}tl_quest_lin.object_CREATED_DATE as CREATED_DATE, {PREFIX}tl_quest_lin.left_quest, {PREFIX}tl_quest_lin.section_number, 1 AS commasafe "; private String SELECT_COLUMNS = "{PREFIX}tl_quest_lin.object_id as id, {PREFIX}tl_quest_lin.object_LAST_UPDATED_DATE as LAST_UPDATED_DATE, {PREFIX}tl_quest_lin.object_CREATED_DATE as CREATED_DATE, {PREFIX}tl_quest_lin.description, {PREFIX}tl_quest_lin.is_right_quest, {PREFIX}tl_quest_lin.section_number, {PREFIX}tl_quest_lin.right_quest_number, 1 AS commasafe ";
private String SELECT_JOINS = ""; private String SELECT_JOINS = "";
public BaseBusinessClass fetchByID(ObjectID id, PersistentSetCollection allPSets, RDBMSPersistenceContext context, SQLManager sqlMgr) throws SQLException, StorageException public BaseBusinessClass fetchByID(ObjectID id, PersistentSetCollection allPSets, RDBMSPersistenceContext context, SQLManager sqlMgr) throws SQLException, StorageException
...@@ -93,7 +96,9 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr ...@@ -93,7 +96,9 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr
// Check for persistent sets already prefetched // Check for persistent sets already prefetched
if (false || !tl_quest_linPSet.containsAttrib(BaseBusinessClass.FIELD_ObjectLastModified) || if (false || !tl_quest_linPSet.containsAttrib(BaseBusinessClass.FIELD_ObjectLastModified) ||
!tl_quest_linPSet.containsAttrib(Question.FIELD_Description)|| !tl_quest_linPSet.containsAttrib(Question.FIELD_Description)||
!tl_quest_linPSet.containsAttrib(Question.SINGLEREFERENCE_Section)) !tl_quest_linPSet.containsAttrib(Question.FIELD_IsRightQuestion)||
!tl_quest_linPSet.containsAttrib(Question.SINGLEREFERENCE_Section)||
!tl_quest_linPSet.containsAttrib(Question.SINGLEREFERENCE_RightQuestion))
{ {
// We will need to retrieve it // We will need to retrieve it
idsToFetch.add (id.longValue()); idsToFetch.add (id.longValue());
...@@ -149,6 +154,16 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr ...@@ -149,6 +154,16 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr
return results; return results;
} }
else if (refName.equals (Question.SINGLEREFERENCE_RightQuestion))
{
String query = "SELECT " + SELECT_COLUMNS +
"FROM {PREFIX}tl_quest_lin " +
"WHERE " + SELECT_JOINS + "right_quest_number = ?";
BaseBusinessClass[] results = loadQuery (allPSets, sqlMgr, context, query, new Object[] { _objectID.longID () }, null, false);
return results;
}
else else
{ {
throw new IllegalArgumentException ("Illegal reference type:" + refName); throw new IllegalArgumentException ("Illegal reference type:" + refName);
...@@ -173,10 +188,10 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr ...@@ -173,10 +188,10 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr
{ {
int rowsUpdated = executeStatement (sqlMgr, int rowsUpdated = executeStatement (sqlMgr,
"UPDATE {PREFIX}tl_quest_lin " + "UPDATE {PREFIX}tl_quest_lin " +
"SET left_quest = ?, section_number = ? , object_LAST_UPDATED_DATE = " + sqlMgr.getPortabilityServices ().getTimestampExpression () + " " + "SET description = ?, is_right_quest = ?, section_number = ? , right_quest_number = ? , object_LAST_UPDATED_DATE = " + sqlMgr.getPortabilityServices ().getTimestampExpression () + " " +
"WHERE tl_quest_lin.object_id = ? AND " + getConcurrencyCheck (sqlMgr, "object_LAST_UPDATED_DATE", obj.getObjectLastModified ()) + " ", "WHERE tl_quest_lin.object_id = ? AND " + getConcurrencyCheck (sqlMgr, "object_LAST_UPDATED_DATE", obj.getObjectLastModified ()) + " ",
CollectionUtils.listEntry (HELPER_Description.getForSQL(dummyDescription, tl_quest_linPSet.getAttrib (Question.FIELD_Description))).listEntry (SQLManager.CheckNull((Long)(tl_quest_linPSet.getAttrib (Question.SINGLEREFERENCE_Section)))).listEntry (objectID.longID ()).listEntry (obj.getObjectLastModified ()).toList().toArray()); CollectionUtils.listEntry (HELPER_Description.getForSQL(dummyDescription, tl_quest_linPSet.getAttrib (Question.FIELD_Description))).listEntry (HELPER_IsRightQuestion.getForSQL(dummyIsRightQuestion, tl_quest_linPSet.getAttrib (Question.FIELD_IsRightQuestion))).listEntry (SQLManager.CheckNull((Long)(tl_quest_linPSet.getAttrib (Question.SINGLEREFERENCE_Section)))).listEntry (SQLManager.CheckNull((Long)(tl_quest_linPSet.getAttrib (Question.SINGLEREFERENCE_RightQuestion)))).listEntry (objectID.longID ()).listEntry (obj.getObjectLastModified ()).toList().toArray());
if (rowsUpdated != 1) if (rowsUpdated != 1)
{ {
...@@ -432,9 +447,11 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr ...@@ -432,9 +447,11 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr
// Object Created // Object Created
tl_quest_linPSet.setAttrib(BaseBusinessClass.FIELD_ObjectCreated, r.getTimestamp ("CREATED_DATE")); tl_quest_linPSet.setAttrib(BaseBusinessClass.FIELD_ObjectCreated, r.getTimestamp ("CREATED_DATE"));
tl_quest_linPSet.setAttrib(Question.FIELD_Description, HELPER_Description.getFromRS(dummyDescription, r, "left_quest")); tl_quest_linPSet.setAttrib(Question.FIELD_Description, HELPER_Description.getFromRS(dummyDescription, r, "description"));
tl_quest_linPSet.setAttrib(Question.FIELD_IsRightQuestion, HELPER_IsRightQuestion.getFromRS(dummyIsRightQuestion, r, "is_right_quest"));
tl_quest_linPSet.setAttrib(Question.SINGLEREFERENCE_Section, r.getObject ("section_number")); tl_quest_linPSet.setAttrib(Question.SINGLEREFERENCE_Section, r.getObject ("section_number"));
tl_quest_linPSet.setAttrib(Question.SINGLEREFERENCE_RightQuestion, r.getObject ("right_quest_number"));
} }
...@@ -451,10 +468,10 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr ...@@ -451,10 +468,10 @@ public class QuestionPersistenceMgr extends ObjectPersistenceMgr
{ {
executeStatement (sqlMgr, executeStatement (sqlMgr,
"INSERT INTO {PREFIX}tl_quest_lin " + "INSERT INTO {PREFIX}tl_quest_lin " +
" (left_quest, section_number, object_id, object_LAST_UPDATED_DATE, object_CREATED_DATE) " + " (description, is_right_quest, section_number, right_quest_number, object_id, object_LAST_UPDATED_DATE, object_CREATED_DATE) " +
"VALUES " + "VALUES " +
" (?, ?, ?, " + sqlMgr.getPortabilityServices ().getTimestampExpression () + ", " + sqlMgr.getPortabilityServices ().getTimestampExpression () + ")", " (?, ?, ?, ?, ?, " + sqlMgr.getPortabilityServices ().getTimestampExpression () + ", " + sqlMgr.getPortabilityServices ().getTimestampExpression () + ")",
CollectionUtils.listEntry (HELPER_Description.getForSQL(dummyDescription, tl_quest_linPSet.getAttrib (Question.FIELD_Description))) .listEntry (SQLManager.CheckNull((Long)(tl_quest_linPSet.getAttrib (Question.SINGLEREFERENCE_Section)))) .listEntry (objectID.longID ()).toList().toArray()); CollectionUtils.listEntry (HELPER_Description.getForSQL(dummyDescription, tl_quest_linPSet.getAttrib (Question.FIELD_Description))).listEntry (HELPER_IsRightQuestion.getForSQL(dummyIsRightQuestion, tl_quest_linPSet.getAttrib (Question.FIELD_IsRightQuestion))) .listEntry (SQLManager.CheckNull((Long)(tl_quest_linPSet.getAttrib (Question.SINGLEREFERENCE_Section)))).listEntry (SQLManager.CheckNull((Long)(tl_quest_linPSet.getAttrib (Question.SINGLEREFERENCE_RightQuestion)))) .listEntry (objectID.longID ()).toList().toArray());
tl_quest_linPSet.setStatus (PersistentSetStatus.PROCESSED); tl_quest_linPSet.setStatus (PersistentSetStatus.PROCESSED);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment