private static ClassDef GetClassDef() { PropDef propDefPK = new PropDef(ENUM_PKPROP_NAME, typeof(Guid), PropReadWriteRule.WriteNew, null); PropDef propDef = new PropDef(ENUM_PROP_NAME, typeof(TestEnum), PropReadWriteRule.ReadWrite, TestEnum.Option1); PropDef propDef2 = new PropDef(ENUM_PROP_NAME_EMPTY, typeof(TestEnumEmpty), PropReadWriteRule.ReadWrite, null); PropDef propDef3 = new PropDef(ENUM_PROP_NAME_PASCAL, typeof(TestEnumPascalCase), PropReadWriteRule.ReadWrite, null); PrimaryKeyDef primaryKeyDef = new PrimaryKeyDef { propDefPK }; PropDefCol propDefCol = new PropDefCol { propDefPK, propDef, propDef2, propDef3 }; UIFormField uiFormField = new UIFormField(TestUtil.GetRandomString(), propDef.PropertyName, typeof(IComboBox), "EnumComboBoxMapper", "Habanero.Faces.Base", true, null, null, LayoutStyle.Label); UIFormColumn uiFormColumn = new UIFormColumn { uiFormField }; UIFormTab uiFormTab = new UIFormTab { uiFormColumn }; UIForm uiForm = new UIForm { uiFormTab }; UIDef uiDef = new UIDef("default", uiForm, null); UIDefCol uiDefCol = new UIDefCol { uiDef }; ClassDef classDef = new ClassDef(typeof(EnumBO), primaryKeyDef, propDefCol, new KeyDefCol(), null, uiDefCol); return(classDef); }
private static BOPrimaryKey CreatePrimaryBOKeyGuidAndString() { PropDef propDef1 = new PropDef("PropName1", typeof(Guid), PropReadWriteRule.ReadWrite, null) { ClassDef = ContactPersonTestBO.LoadDefaultClassDef() }; PropDef propDef2 = new PropDef("PropName2", typeof(string), PropReadWriteRule.ReadWrite, null) { ClassDef = propDef1.ClassDef }; BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(true)); propCol.Add(propDef2.CreateBOProp(true)); // BOPropCol propCol = new BOPropCol(); // propCol.Add(propDef1.CreateBOProp(true)); // propCol.Add(propDef2.CreateBOProp(true)); PrimaryKeyDef keyDef = new PrimaryKeyDef { IsGuidObjectID = false }; keyDef.Add(propDef1); keyDef.Add(propDef2); return((BOPrimaryKey)keyDef.CreateBOKey(propCol)); }
public void Test_CreatePrimaryKey_TwoPropDefs() { //---------------Set up test pack------------------- PropDef propDef1 = new PropDef("prop1", typeof(String), PropReadWriteRule.ReadWrite, null); PropDef propDef2 = new PropDef("prop2", typeof(String), PropReadWriteRule.ReadWrite, null); PrimaryKeyDef keyDef = new PrimaryKeyDef { IsGuidObjectID = false }; keyDef.Add(propDef2); keyDef.Add(propDef1); BOPropCol boPropCol = new BOPropCol(); boPropCol.Add(propDef1.CreateBOProp(false)); boPropCol.Add(propDef2.CreateBOProp(false)); //---------------Assert Precondition---------------- Assert.AreEqual(2, keyDef.Count); //---------------Execute Test ---------------------- BOPrimaryKey boPrimaryKey = (BOPrimaryKey)keyDef.CreateBOKey(boPropCol); //---------------Test Result ----------------------- Assert.AreEqual(keyDef.Count, boPrimaryKey.Count); Assert.IsTrue(boPrimaryKey.IsCompositeKey); }
private static ClassDef CreateClassDef() { PropDefCol lPropDefCol = CreateBOPropDef(); KeyDef lKeyDef = new KeyDef(); lKeyDef.IgnoreIfNull = true; lKeyDef.Add(lPropDefCol["PK2Prop1"]); lKeyDef.Add(lPropDefCol["PK2Prop2"]); KeyDefCol keysCol = new KeyDefCol(); keysCol.Add(lKeyDef); lKeyDef = new KeyDef(); lKeyDef.IgnoreIfNull = false; lKeyDef.Add(lPropDefCol["PK3Prop"]); keysCol.Add(lKeyDef); PrimaryKeyDef primaryKey = new PrimaryKeyDef(); primaryKey.IsGuidObjectID = true; primaryKey.Add(lPropDefCol["ContactPersonID"]); //Releationships RelationshipDefCol relDefs = CreateRelationshipDefCol(lPropDefCol); ClassDef lClassDef = new ClassDef(typeof(ContactPerson), primaryKey, "contact_person", lPropDefCol, keysCol, relDefs); ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
private void Initialise() { _propDefCol = new PropDefCol(); //PropDefBuilders = new List<PropDefBuilder<T>>(); _propertiesDefBuilder = new PropertiesDefBuilder <T>(this, PropDefBuilders); _relationshipDefCol = new RelationshipDefCol(); _primaryKeyDef = new PrimaryKeyDef(); }
/// <summary> /// Constructor to initialise a new ObjectID /// </summary> /// <param name="lPrimaryKeyDef">The primary key definition</param> internal BOObjectID(PrimaryKeyDef lPrimaryKeyDef) : base(lPrimaryKeyDef) { if (lPrimaryKeyDef.Count != 1 || !lPrimaryKeyDef.IsGuidObjectID) { throw new InvalidObjectIdException( "The BOOBjectID must have a key def that defines exactly one property and that is an ObjectID"); } }
public void TestIgnoreIfNullReturnsFalse() { PrimaryKeyDef pkDef = new PrimaryKeyDef(); Assert.IsFalse(pkDef.IgnoreIfNull); pkDef.IgnoreIfNull = false; Assert.IsFalse(pkDef.IgnoreIfNull); }
public void Test_CreateBOPrimaryKey() { //---------------Set up test pack------------------- PrimaryKeyDef pkDef = new PrimaryKeyDef(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- BOPrimaryKey boPrimaryKey = new BOPrimaryKey(pkDef); //---------------Test Result ----------------------- Assert.IsNotNull(boPrimaryKey); }
private static BOObjectID CreateBOObjectID() { PropDef propDef1 = new PropDef("PropName1", typeof(Guid), PropReadWriteRule.ReadWrite, null); BOPropCol propCol = new BOPropCol(); propCol.Add(propDef1.CreateBOProp(false)); PrimaryKeyDef keyDef = new PrimaryKeyDef(); keyDef.IsGuidObjectID = true; keyDef.Add(propDef1); return((BOObjectID)keyDef.CreateBOKey(propCol)); }
private static ClassDef CreateTestClassDef(string suffix) { PropDefCol propDefCol = new PropDefCol(); PropDef propDef = new PropDef("TestProperty" + suffix, typeof(string), PropReadWriteRule.ReadWrite, null, null, false, false, 100, "Tested Property" + suffix, "This is a property for testing."); propDefCol.Add(propDef); PrimaryKeyDef primaryKeyDef = new PrimaryKeyDef { propDef }; return(new ClassDef("TestAssembly", "TestClass" + suffix, primaryKeyDef, propDefCol, new KeyDefCol(), new RelationshipDefCol(), new UIDefCol())); }
//protected override void ConstructFromClassDef(bool newObject) //{ // base.ConstructFromClassDef(newObject); // //SetTransactionLog(new TransactionLogTable("TransactionLogStub", // // "DateTimeUpdated", // // "WindowsUser", // // "LogonUser", // // "MachineName", // // "BusinessObjectTypeName", // // "CRUDAction", // // "DirtyXML")); //} private static ClassDef CreateClassDef() { PropDefCol lPropDefCol = CreateBOPropDef(); KeyDefCol keysCol = new KeyDefCol(); PrimaryKeyDef primaryKey = new PrimaryKeyDef(); primaryKey.IsGuidObjectID = true; primaryKey.Add(lPropDefCol["TransactionSequenceNo"]); ClassDef lClassDef = new ClassDef(typeof(TransactionLogStub), primaryKey, lPropDefCol, keysCol, null); ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
private static ClassDef CreateClassDef() { PropDefCol lPropDefCol = CreateBOPropDef(); KeyDefCol keysCol = new KeyDefCol(); PrimaryKeyDef primaryKey = new PrimaryKeyDef(); primaryKey.IsGuidObjectID = true; primaryKey.Add(lPropDefCol["MockBOID"]); ClassDef lClassDef = new ClassDef (typeof(MockBOWithCompulsoryField), primaryKey, lPropDefCol, keysCol, new RelationshipDefCol()); ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
private IBusinessObject GetBusinessObjectStub() { PropDefCol propDefCol = new PropDefCol { _propDef_guid }; PrimaryKeyDef def = new PrimaryKeyDef { _propDef_guid }; ClassDef classDef = new ClassDef(typeof(BusinessObjectStub), def, propDefCol, new KeyDefCol(), null); BusinessObjectStub businessObjectStub = new BusinessObjectStub(classDef); BOProp prop = new BOPropLookupList(_propDef_guid); businessObjectStub.Props.Remove(prop.PropertyName); businessObjectStub.Props.Add(prop); return(businessObjectStub); }
public void TestSettingIgnoreIfNullTrueException() { //---------------Set up test pack------------------- var primaryKeyDef = new PrimaryKeyDef(); //---------------Execute Test ---------------------- try { primaryKeyDef.IgnoreIfNull = true; Assert.Fail("Expected to throw an InvalidKeyException"); } //---------------Test Result ----------------------- catch (InvalidKeyException ex) { StringAssert.Contains("you cannot set a primary key's IgnoreIfNull setting to true", ex.Message); } }
public static ClassDef CreateClassDefWithShapeRelationship() { PropDefCol lPropDefCol = CreateBOPropDef(); KeyDef lKeyDef = new KeyDef(); lKeyDef.IgnoreIfNull = true; lKeyDef.Add(lPropDefCol["PK2Prop1"]); lKeyDef.Add(lPropDefCol["PK2Prop2"]); KeyDefCol keysCol = new KeyDefCol(); keysCol.Add(lKeyDef); lKeyDef = new KeyDef(); lKeyDef.IgnoreIfNull = false; lKeyDef.Add(lPropDefCol["PK3Prop"]); keysCol.Add(lKeyDef); PrimaryKeyDef primaryKey = new PrimaryKeyDef(); primaryKey.IsGuidObjectID = true; primaryKey.Add(lPropDefCol["ContactPersonID"]); //Releationships RelationshipDefCol relDefs = new RelationshipDefCol(); RelKeyDef relKeyDef = new RelKeyDef(); IPropDef propDef = lPropDefCol["ContactPersonID"]; RelPropDef lRelPropDef = new RelPropDef(propDef, "OwnerId"); relKeyDef.Add(lRelPropDef); RelationshipDef relDef = new MultipleRelationshipDef("Shapes", typeof(Shape), relKeyDef, false, "", DeleteParentAction.DereferenceRelated); //relDefCol.Add(relDef1); relDefs.Add(relDef); ClassDef lClassDef = new ClassDef(typeof(ContactPerson), primaryKey, "contact_person", lPropDefCol, keysCol, relDefs); ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
private static ClassDef CreateTestClassDef(string suffix) { PropDefCol propDefCol = new PropDefCol(); PropDef propDef = new PropDef("TestProperty" + suffix, typeof(string), PropReadWriteRule.ReadWrite, null, null, false, false, 100, "Tested Property" + suffix, null); propDefCol.Add(propDef); PrimaryKeyDef primaryKeyDef = new PrimaryKeyDef { propDef }; var testClassDef = new ClassDef("Habanero.Test.Structure", "Person" + suffix, primaryKeyDef, propDefCol, new KeyDefCol(), new RelationshipDefCol(), new UIDefCol()); var uiGrid = new UIGrid(); testClassDef.UIDefCol.Add(new UIDef("UIDef1", new UIForm(), uiGrid)); return(testClassDef); }
public void Test_CreatePrimaryKey_OnePropDefs() { //---------------Set up test pack------------------- PropDef propDef1 = new PropDef("prop1", typeof(String), PropReadWriteRule.ReadWrite, null); PrimaryKeyDef keyDef = new PrimaryKeyDef { IsGuidObjectID = false }; keyDef.Add(propDef1); //---------------Assert Precondition---------------- Assert.AreEqual(1, keyDef.Count); //---------------Execute Test ---------------------- bool isCompositeKey = keyDef.IsCompositeKey; //---------------Test Result ----------------------- Assert.IsFalse(isCompositeKey); }
public void Test_ToString_ShouldReturnPropName() { //---------------Set up test pack------------------- const string propertyName = "prop1"; PropDef propDef1 = new PropDef(propertyName, typeof(String), PropReadWriteRule.ReadWrite, null); PrimaryKeyDef keyDef = new PrimaryKeyDef { IsGuidObjectID = false }; keyDef.Add(propDef1); //---------------Assert Precondition---------------- Assert.AreEqual(1, keyDef.Count); //---------------Execute Test ---------------------- var toString = keyDef.ToString(); //---------------Test Result ----------------------- Assert.AreEqual(propertyName, toString); }
private static ClassDef CreateClassDef() { PropDefCol lPropDefCol = CreateBOPropDef(); var keysCol = new KeyDefCol(); var primaryKey = new PrimaryKeyDef { IsGuidObjectID = false }; primaryKey.Add(lPropDefCol[PK1_PROP1_NAME]); var relDefs = new RelationshipDefCol(); var lClassDef = new ClassDef(typeof(BOWithCompositePK), primaryKey, lPropDefCol, keysCol, relDefs); ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
private static ClassDef CreateClassDef() { PropDefCol lPropDefCol = new PropDefCol(); IPropDef propDef = new PropDef("FakeSuperClassID", typeof(Guid), PropReadWriteRule.WriteOnce, null); lPropDefCol.Add(propDef); PrimaryKeyDef primaryKey = new PrimaryKeyDef { IsGuidObjectID = true }; primaryKey.Add(lPropDefCol["FakeSuperClassID"]); KeyDefCol keysCol = new KeyDefCol(); RelationshipDefCol relDefCol = new RelationshipDefCol(); ClassDef lClassDef = new ClassDef(typeof(FakeSuperClass), primaryKey, lPropDefCol, keysCol, relDefCol, null); ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
private static ClassDef CreateClassDef() { PropDefCol propDefCol = CreateBOPropDef(); KeyDefCol keysCol = new KeyDefCol(); PrimaryKeyDef primaryKey = new PrimaryKeyDef(); primaryKey.IsGuidObjectID = true; primaryKey.Add(propDefCol["AddressID"]); RelationshipDefCol relDefCol = CreateRelationshipDefCol(propDefCol); ClassDef classDef = new ClassDef(typeof(Address), primaryKey, "contact_person_address", propDefCol, keysCol, relDefCol); ClassDef.ClassDefs.Add(classDef); return(classDef); }
public void Test_CreateBOPrimaryKey_IsObjectID_False() { //---------------Set up test pack------------------- PrimaryKeyDef pkDef = new PrimaryKeyDef { new PropDef("prop2", typeof(Guid), PropReadWriteRule.ReadWrite, null) }; pkDef.IsGuidObjectID = false; BOPrimaryKey boPrimaryKey = new BOPrimaryKey(pkDef); //---------------Assert Precondition---------------- Assert.IsFalse(pkDef.IsGuidObjectID); //---------------Execute Test ---------------------- bool isObjectID = boPrimaryKey.IsGuidObjectID; //---------------Test Result ----------------------- Assert.IsFalse(isObjectID); }
public void Test_ToString_WhenComposite_ShouldReturnConcatenatedPropNames() { //---------------Set up test pack------------------- string propertyName = TestUtil.GetRandomString(); string propName2 = TestUtil.GetRandomString(); PrimaryKeyDef keyDef = new PrimaryKeyDef { IsGuidObjectID = false }; keyDef.Add(new PropDef(propertyName, typeof(String), PropReadWriteRule.ReadWrite, null)); keyDef.Add(new PropDef(propName2, typeof(String), PropReadWriteRule.ReadWrite, null)); //---------------Assert Precondition---------------- Assert.AreEqual(2, keyDef.Count); //---------------Execute Test ---------------------- var toString = keyDef.ToString(); //---------------Test Result ----------------------- Assert.AreEqual(propertyName + "_" + propName2, toString); }
private static ClassDef CreateClassDef() { PropDefCol lPropDefCol = CreateBOPropDef(); KeyDefCol keysCol = new KeyDefCol(); PrimaryKeyDef primaryKey = new PrimaryKeyDef(); primaryKey.IsGuidObjectID = true; primaryKey.Add(lPropDefCol["EngineID"]); RelationshipDefCol relDefCol = CreateRelationshipDefCol(lPropDefCol); ClassDef lClassDef = new ClassDef(typeof(Engine), primaryKey, lPropDefCol, keysCol, relDefCol); lClassDef.TableName = "Table_Engine"; ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
private static ClassDef CreateClassDef() { PropDefCol lPropDefCol = CreateBOPropDef(); KeyDefCol keysCol = new KeyDefCol(); PrimaryKeyDef primaryKey = new PrimaryKeyDef { IsGuidObjectID = false }; primaryKey.Add(lPropDefCol[PK1_PROP1_NAME]); primaryKey.Add(lPropDefCol[PK1_PROP2_NAME]); RelationshipDefCol relDefs = CreateRelationshipDefCol(lPropDefCol); ClassDef lClassDef = new ClassDef(typeof(ContactPersonCompositeKey), primaryKey, lPropDefCol, keysCol, relDefs); ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
private static ClassDef CreateClassDef() { PropDefCol lPropDefCol = CreateBOPropDef(); KeyDefCol keysCol = new KeyDefCol(); PrimaryKeyDef primaryKey = new PrimaryKeyDef(); primaryKey.IsGuidObjectID = true; primaryKey.Add(lPropDefCol["CarID"]); RelationshipDefCol relDefCol = CreateRelationshipDefCol(lPropDefCol); ClassDef lClassDef = new ClassDef(typeof(Car), primaryKey, "car_table", lPropDefCol, keysCol, relDefCol); ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
private new static ClassDef CreateClassDef() { PropDefCol lPropDefCol = new PropDefCol(); IPropDef propDef = new PropDef("Colour", typeof(int), PropReadWriteRule.ReadWrite, null); lPropDefCol.Add(propDef); propDef = lPropDefCol.Add("FilledCircleID", typeof(Guid), PropReadWriteRule.WriteOnce, "FilledCircleID_field", null); PrimaryKeyDef primaryKey = new PrimaryKeyDef(); primaryKey.IsGuidObjectID = true; primaryKey.Add(lPropDefCol["FilledCircleID"]); KeyDefCol keysCol = new KeyDefCol(); RelationshipDefCol relDefCol = new RelationshipDefCol(); ClassDef lClassDef = new ClassDef(typeof(FilledCircle), primaryKey, "FilledCircle_table", lPropDefCol, keysCol, relDefCol); lClassDef.SuperClassDef = new SuperClassDef(Circle.GetClassDef(), ORMapping.ConcreteTableInheritance); ClassDef.ClassDefs.Add(lClassDef); return(lClassDef); }
/// <summary> /// Generates an "update" sql statement for the properties in the /// business object /// </summary> /// <param name="tableName">The table name</param> /// <param name="propsToInclude">A collection of properties to update, /// if the previous include-all boolean was not set to true</param> /// <param name="isSuperClassStatement">Whether a super-class is involved</param> /// <param name="currentClassDef">The current class definition</param> private void GenerateSingleUpdateStatement(string tableName, IBOPropCol propsToInclude, bool isSuperClassStatement, ClassDef currentClassDef) { _updateSql = new SqlStatement(_connection); _updateSql.Statement.Append( @"UPDATE " + _connection.SqlFormatter.DelimitTable(tableName) + " SET "); int includedProps = 0; foreach (BOProp prop in _bo.Props.SortedValues) { if (propsToInclude.Contains(prop.PropertyName)) { PrimaryKeyDef primaryKeyDef = (PrimaryKeyDef)_bo.ClassDef.PrimaryKeyDef ?? (PrimaryKeyDef)_bo.ID.KeyDef; if (prop.IsDirty && ((primaryKeyDef.IsGuidObjectID && !primaryKeyDef.Contains(prop.PropertyName)) || !primaryKeyDef.IsGuidObjectID)) { includedProps++; _updateSql.Statement.Append(_connection.SqlFormatter.DelimitField(prop.DatabaseFieldName)); _updateSql.Statement.Append(" = "); //prop.PropDef.GetDataMapper().GetDatabaseValue(prop.Value); _updateSql.AddParameterToStatement(prop.Value); _updateSql.Statement.Append(", "); } } } _updateSql.Statement.Remove(_updateSql.Statement.Length - 2, 2); //remove the last ", " if (isSuperClassStatement) { _updateSql.Statement.Append(" WHERE " + StatementGeneratorUtils.PersistedDatabaseWhereClause(BOPrimaryKey.GetSuperClassKey(currentClassDef, _bo), _updateSql)); } else { _updateSql.Statement.Append(" WHERE " + StatementGeneratorUtils.PersistedDatabaseWhereClause((BOKey)_bo.ID, _updateSql)); } if (includedProps > 0) { _statements.Add(_updateSql); } }
private static void CreateInheritanceJoins(IClassDef classDef, Source rootSource) { IClassDef currentClassDef = classDef; while (currentClassDef.IsUsingClassTableInheritance()) { IClassDef superClassDef = currentClassDef.SuperClassClassDef; Source baseSource = new Source(superClassDef.ClassNameExcludingTypeParameter, superClassDef.TableName); Source.Join join = new Source.Join(rootSource, baseSource); PrimaryKeyDef superClassPrimaryKeyDef = (PrimaryKeyDef)superClassDef.PrimaryKeyDef; IPropDef basePrimaryKeyPropDef = superClassPrimaryKeyDef[0]; PrimaryKeyDef currentPrimaryKeyDef = (PrimaryKeyDef)currentClassDef.PrimaryKeyDef; if (currentPrimaryKeyDef != null) { IPropDef thisPrimaryKeyPropDef = currentPrimaryKeyDef[0]; join.JoinFields.Add(new Source.Join.JoinField( new QueryField(thisPrimaryKeyPropDef.PropertyName, thisPrimaryKeyPropDef.DatabaseFieldName, rootSource), new QueryField(basePrimaryKeyPropDef.PropertyName, basePrimaryKeyPropDef.DatabaseFieldName, baseSource))); } else { join.JoinFields.Add(new Source.Join.JoinField( new QueryField(basePrimaryKeyPropDef.PropertyName, basePrimaryKeyPropDef.DatabaseFieldName, rootSource), new QueryField(basePrimaryKeyPropDef.PropertyName, basePrimaryKeyPropDef.DatabaseFieldName, baseSource))); } rootSource.InheritanceJoins.Add(join); rootSource = baseSource; currentClassDef = superClassDef; } }
/// <summary> /// Map the Identity for the given ClassDef /// </summary> /// <returns></returns> public IPrimaryKeyDef MapIdentity() { var classDef = this.ClassDef; var primaryKeyDef = GetPrimaryKeyDef(classDef); if (primaryKeyDef == null) { var propDef = GetPrimaryKeyPropDef(); if (propDef == null) { return(null); } var keyDef = new PrimaryKeyDef { propDef }; keyDef.IsGuidObjectID = IsGuidObjectID(propDef); classDef.PrimaryKeyDef = keyDef; } return(classDef.PrimaryKeyDef); }