From: Richard B. <rb...@us...> - 2004-11-02 05:36:23
|
Update of /cvsroot/jcframework/dotnet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20314 Modified Files: CClassMap.vb CPersistenceBroker.vb CPersistentCriteria.vb CXMLConfigLoader.vb Log Message: Fixed problem with ProcessDirectSQL when using namespaces Fixed issues with shared tables and SQL generation Index: CPersistenceBroker.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistenceBroker.vb,v retrieving revision 1.76 retrieving revision 1.77 diff -u -d -r1.76 -r1.77 --- CPersistenceBroker.vb 1 Nov 2004 21:28:02 -0000 1.76 +++ CPersistenceBroker.vb 2 Nov 2004 05:36:13 -0000 1.77 @@ -1502,6 +1502,7 @@ Dim am As CAttributeMap Dim i As Integer Dim preString, postString As String + Dim tmpStr As String clauses = Split(inSQL) Try @@ -1527,24 +1528,45 @@ Loop If subclause.IndexOf(".") > 0 Then objString = Split(subclause, ".") - Try - clMap = Me.getClassMap(objString(0)) - Catch ex As Exception - Throw New NoClassMapException("Unknown class in SQL statement: " & subclause) - End Try + tmpStr = "" + For i = 0 To objString.Length - 2 + If tmpStr.Length > 0 Then tmpStr &= "." + tmpStr &= objString(i) + Try + clMap = Me.getClassMap(tmpStr) + Catch ex As Exception + End Try + Next If clMap Is Nothing Then - Throw New NoClassMapException("Unknown class in SQL statement: " & subclause) - End If - If firstClassMap Is Nothing Then firstClassMap = clMap - Try - am = clMap.getAttributeMapByString(objString(1), True) - Catch - Throw New NoAttributeMapException("Could not find attribute map for: " & subclause) - End Try - If am Is Nothing Then - Throw New NoAttributeMapException("Could not find attribute map for: " & subclause) + 'See if subclause is a class name + Try + clMap = Me.getClassMap(subclause) + Catch + Throw New NoClassMapException("Unknown class in SQL statement: " & subclause) + End Try + If firstClassMap Is Nothing Then firstClassMap = clMap + Dim t As CTableMap + Try + t = clMap.Tables(1) + Catch + Throw New NoTableMapException("Could not load table map for " & subclause) + End Try + If t Is Nothing Then + Throw New NoTableMapException("Could not load table map for " & subclause) + End If + subclause = t.Name + Else + If firstClassMap Is Nothing Then firstClassMap = clMap + Try + am = clMap.getAttributeMapByString(objString(objString.Length - 1), True) + Catch + Throw New NoAttributeMapException("Could not find attribute map for: " & subclause) + End Try + If am Is Nothing Then + Throw New NoAttributeMapException("Could not find attribute map for: " & subclause) + End If + subclause = am.ColumnMap.getFullyQualifiedName End If - subclause = am.ColumnMap.getFullyQualifiedName Else Try clMap = Me.getClassMap(subclause) Index: CPersistentCriteria.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CPersistentCriteria.vb,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- CPersistentCriteria.vb 28 Oct 2004 00:16:12 -0000 1.9 +++ CPersistentCriteria.vb 2 Nov 2004 05:36:13 -0000 1.10 @@ -153,6 +153,10 @@ cm = m_classMap Do Tables.Add(cm.Tables.Item(1)) + While Not cm Is Nothing AndAlso Not cm.SharedTableValue Is Nothing + 'Need to skip parents of shared table classes + cm = cm.SuperClass + End While cm = cm.SuperClass Loop While Not cm Is Nothing criCond = New CCriteriaCondition @@ -198,7 +202,7 @@ persistentBroker = getPersistenceBrokerInstance() m_className = pClassName - m_classMap = persistentBroker.getClassMap(m_className) + Me.ClassMap = persistentBroker.getClassMap(m_className) End Sub '''----------------------------------------------------------------------------- @@ -230,6 +234,7 @@ Public Sub fillStatementWithWhere(ByRef statement As CSqlStatement) Implements _CPersistentCriteria.fillStatementWithWhere Dim inheritedAssoc As String Dim clauseConditionAdded As Boolean = False + Dim cm As CClassMap inheritedAssoc = Me.ClassMap.getInheritedAssociations If inheritedAssoc Is Nothing Then @@ -256,7 +261,19 @@ End If End If WhereCondition.fillStatement(statement) + clauseConditionAdded = True End If + cm = Me.ClassMap + While Not cm Is Nothing + If Not cm.SharedTableValue Is Nothing Then + If clauseConditionAdded Then + statement.addSqlClause(" " & cm.RelationalDatabase.getClauseStringAnd & " ") + clauseConditionAdded = True + End If + statement.addSqlClause(CType(cm.Tables(1), CTableMap).Name & "." & cm.SharedTableField & cm.RelationalDatabase.getClauseStringEqualTo(cm.RelationalDatabase.getValueFor(cm.SharedTableValue))) + End If + cm = cm.SuperClass + End While End Sub '''----------------------------------------------------------------------------- Index: CXMLConfigLoader.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CXMLConfigLoader.vb,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- CXMLConfigLoader.vb 1 Nov 2004 00:10:51 -0000 1.27 +++ CXMLConfigLoader.vb 2 Nov 2004 05:36:13 -0000 1.28 @@ -606,8 +606,16 @@ attrFromAttribute = elementChild.GetAttributeNode("fromAttribute") attrToAttribute = elementChild.GetAttributeNode("toAttribute") If ((Not attrFromAttribute Is Nothing) And (Not attrToAttribute Is Nothing)) Then - amFromAttribute = fromClassMap.getAttributeMapByString(attrFromAttribute.Value, False) - amToAttribute = toClassMap.getAttributeMapByString(attrToAttribute.Value, False) + If fromClassMap.SharedTableValue Is Nothing Then + amFromAttribute = fromClassMap.getAttributeMapByString(attrFromAttribute.Value, False) + Else + amFromAttribute = fromClassMap.getAttributeMapByString(attrFromAttribute.Value, True) + End If + If toClassMap.SharedTableValue Is Nothing Then + amToAttribute = toClassMap.getAttributeMapByString(attrToAttribute.Value, False) + Else + amToAttribute = toClassMap.getAttributeMapByString(attrToAttribute.Value, True) + End If If amFromAttribute Is Nothing Then Throw New XMLMappingException("Error in association definition") End If @@ -624,7 +632,7 @@ End If udaAm.addEntry(entry) End If - End If + End If End If nodeChild = nodeChild.NextSibling Loop Index: CClassMap.vb =================================================================== RCS file: /cvsroot/jcframework/dotnet/CClassMap.vb,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- CClassMap.vb 1 Nov 2004 21:28:02 -0000 1.41 +++ CClassMap.vb 2 Nov 2004 05:36:13 -0000 1.42 @@ -999,10 +999,11 @@ statement.addSqlClause(", ") End If statement.addSqlClause(ClassMap.getAttributeMap(i).ColumnMap.getFullyQualifiedName) - ' statement.addSqlClause(ClassMap.getAttributeMap(i).ColumnMap.getFullyQualifiedName & _ - ' Me.RelationalDatabase.getClauseStringAs & ClassMap.getAttributeMap(i).ColumnMap.getFullyQualifiedName) End If Next i + While Not ClassMap Is Nothing AndAlso Not ClassMap.SharedTableValue Is Nothing + ClassMap = ClassMap.SuperClass + End While ClassMap = ClassMap.SuperClass Loop While Not ClassMap Is Nothing getSelectSql = statement @@ -1282,7 +1283,7 @@ End If m_updateWhereParamPosition = Me.getSize For Each AttrMap In Me.AttributeMaps - If AttrMap.ColumnMap.IsIdentity OrElse (Not Me.SharedTableValue Is Nothing AndAlso AttrMap.AttributeMap Is Nothing) Then + If AttrMap.ColumnMap.IsIdentity OrElse (Not Me.SharedTableValue Is Nothing AndAlso Not AttrMap.AttributeMap Is Nothing) Then m_updateWhereParamPosition -= 1 End If Next |