public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledInsert o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledInsert)oo; // PersistenceUnitManager persistenceManager = context.getPersistenceStore(); Net.Vpc.Upa.Entity entity = context.GetPersistenceUnit().GetEntity(o.GetEntity().GetName()); string n = context.GetPersistenceStore().GetValidIdentifier(context.GetPersistenceStore().GetPersistenceName(entity)); System.Text.StringBuilder sb = new System.Text.StringBuilder("Insert Into " + n); sb.Append("("); System.Text.StringBuilder sbVals = new System.Text.StringBuilder(); bool isFirst = true; int max = o.CountFields(); for (int i = 0; i < max; i++) { if (isFirst) { isFirst = false; } else { sb.Append(", "); sbVals.Append(", "); } sb.Append(sqlManager.GetSQL(o.GetField(i), context, declarations)); sbVals.Append(sqlManager.GetSQL(o.GetFieldValue(i), context, declarations)); } return(sb.Append(") Values (").Append(sbVals).Append(")").ToString()); }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledPlus o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledPlus)oo; System.Type t1 = o.GetLeft().GetTypeTransform().GetTargetType().GetPlatformType(); System.Type t2 = o.GetRight().GetTypeTransform().GetTargetType().GetPlatformType(); bool s0 = o.GetTypeTransform().GetTargetType().GetPlatformType().Equals(typeof(string)); bool s1 = t1.Equals(typeof(string)); bool s2 = t2.Equals(typeof(string)); if (s0 || s1 || s2) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression c1 = o.GetLeft().Copy(); Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression c2 = o.GetRight().Copy(); c1.SetParentExpression(null); c2.SetParentExpression(null); if (!s1) { if (Net.Vpc.Upa.Impl.Util.PlatformUtils.IsAnyInteger(t1)) { c1 = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledI2V(c1.Copy()); } else if (Net.Vpc.Upa.Impl.Util.PlatformUtils.IsAnyFloat(t1)) { c1 = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledI2V(c1.Copy()); } else { throw new System.ArgumentException("Unsupported"); } } if (!s2) { if (Net.Vpc.Upa.Impl.Util.PlatformUtils.IsAnyInteger(t2)) { c2 = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledI2V(c2.Copy()); } else if (Net.Vpc.Upa.Impl.Util.PlatformUtils.IsAnyFloat(t2)) { c2 = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledI2V(c2.Copy()); } else { throw new System.ArgumentException("Unsupported"); } } Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledConcat cc = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledConcat(c1, c2); return(sqlManager.GetSQL(cc, qlContext, declarations)); } string leftValue = o.GetLeft() != null?sqlManager.GetSQL(o.GetLeft(), qlContext, declarations) : "NULL"; string rightValue = o.GetRight() != null?sqlManager.GetSQL(o.GetRight(), qlContext, declarations) : "NULL"; string s = null; s = leftValue + " + " + rightValue; return("(" + s + ")"); }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledBinaryOperatorExpression o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledBinaryOperatorExpression)oo; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append('('); sb.Append(sqlManager.GetSQL(o.GetLeft(), qlContext, declarations)); sb.Append(GetOperatorString(o)); sb.Append(sqlManager.GetSQL(o.GetRight(), qlContext, declarations)); sb.Append(')'); return(sb.ToString()); }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledInCollection o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledInCollection)oo; Net.Vpc.Upa.Persistence.PersistenceStore qlm = qlContext.GetPersistenceStore(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); int mySize = o.GetRightSize(); if (mySize == 0) { sb.Append("1 <> 1"); } else { if (mySize == 1) { sb.Append(sqlManager.GetSQL(o.GetLeft(), qlContext, declarations)); Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression e = o.GetRight(0); if (e == null || (e is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral && ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral)e).GetValue() == null)) { sb.Append(" Is Null"); } else { sb.Append(" = "); sb.Append(sqlManager.GetSQL(e, qlContext, declarations)); } } else { sb.Append(sqlManager.GetSQL(o.GetLeft(), qlContext, declarations)); sb.Append(" In ("); for (int i = 0; i < mySize; i++) { if (i > 0) { sb.Append(","); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression e = o.GetRight(i); if (e == null) { sb.Append("Null"); } else { sb.Append(sqlManager.GetSQL(e, qlContext, declarations)); } } sb.Append(")"); } } return('(' + sb.ToString() + ')'); }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledDelete o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledDelete)oo; Net.Vpc.Upa.Entity entityManager = context.GetPersistenceUnit().GetEntity(o.GetEntity().GetName()); System.Text.StringBuilder sb = new System.Text.StringBuilder("Delete From " + sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(o.GetEntity().GetName()), context, declarations)); if (o.GetEntityAlias() != null) { sb.Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(o.GetEntityAlias()), context, declarations)); } if (o.GetCondition() != null && o.GetCondition().IsValid()) { sb.Append(" Where ").Append(sqlManager.GetSQL(o.GetCondition(), context, declarations)); } return(sb.ToString()); }
protected internal virtual void AppendWhere(Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression cond, System.Text.StringBuilder sb, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { if (cond != null && cond.IsValid()) { sb.Append(" Where ").Append(sqlManager.GetSQL(cond, context, declarations)); } }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledBetween o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledBetween)oo; string s = sqlManager.GetSQL(o.GetLeft(), qlContext, declarations) + " Between " + sqlManager.GetSQL(o.GetMin(), qlContext, declarations) + " And " + sqlManager.GetSQL(o.GetMax(), qlContext, declarations); return("(" + s + ")"); }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUplet o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUplet)oo; // PersistenceUnitManager queryLanguageManager = qlContext.getPersistenceUnitManager(); Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression sql; Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression[] expressions = o.GetExpressions(); if (expressions.Length > 1) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledConcat concat = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledConcat(); for (int i = 0; i < expressions.Length; i++) { if (i > 0) { concat.Add(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral('~')); } concat.Add(expressions[i]); } sql = concat; } else { sql = expressions[0]; } return(sqlManager.GetSQL(sql, qlContext, declarations)); }
protected internal virtual void AppendOrderBy(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect o, System.Text.StringBuilder sb, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { int max = o.CountOrderByItems(); if (max > 0) { sb.Append(" "); sb.Append("Order By "); for (int i = 0; i < max; i++) { if (i > 0) { sb.Append(", "); } sb.Append(sqlManager.GetSQL(o.GetOrderBy(i), context, declarations)); if (o.IsOrderAscending(i)) { sb.Append(" Asc "); } else { sb.Append(" Desc "); } } } }
protected internal virtual void AppendFields(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect o, System.Text.StringBuilder sb, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { sb.Append(" "); string aliasString = null; string valueString = null; bool started = false; if (o.CountFields() == 0) { sb.Append("..."); } else { // PersistenceStore persistenceStore = context.getPersistenceStore(); for (int i = 0; i < o.CountFields(); i++) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledQueryField fi = o.GetField(i); Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression e = fi.GetExpression(); bool fieldIsSelect = e is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect; valueString = sqlManager.GetSQL(e, context, declarations); if (fieldIsSelect) { valueString = "(" + valueString + ")"; } aliasString = fi.GetAlias(); if (started) { sb.Append(","); } else { started = true; } if (aliasString == null) { sb.Append(valueString); } else { sb.Append(valueString); sb.Append(" "); sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(aliasString), context, declarations)); } } } }
protected internal virtual void AppendHaving(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect o, System.Text.StringBuilder sb, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression hav = o.GetHaving(); if (hav != null && hav.IsValid()) { sb.Append(" Having ").Append(sqlManager.GetSQL(hav, context, declarations)); } }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledInSelection o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledInSelection)oo; Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression[] left = o.GetLeft(); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect query = o.GetSelection(); if (left.Length == 1) { string q = sqlManager.GetSQL(left[0], qlContext, declarations) + " in (" + sqlManager.GetSQL(query, qlContext, declarations) + ")"; return('(' + q + ')'); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUplet uplet = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUplet(left); System.Text.StringBuilder stringBuffer = new System.Text.StringBuilder(sqlManager.GetSQL(uplet, qlContext, declarations)); stringBuffer.Append(" In ("); stringBuffer.Append(sqlManager.GetSQL(query, qlContext, declarations)); stringBuffer.Append(")"); return('(' + stringBuffer.ToString() + ')'); }
public virtual string Simplify(Net.Vpc.Upa.Persistence.EntityExecutionContext ctx, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations, params Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression [] @params) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { string[] p = new string[@params.Length]; for (int i = 0; i < p.Length; i++) { p[i] = sqlManager.GetSQL(@params[i], ctx, declarations); } return(Simplify((GetExpressionType()).Name, p, null)); }
protected internal virtual void AppendJoins(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect o, System.Text.StringBuilder sb, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { for (int i = 0; i < o.CountJoins(); i++) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria e = o.GetJoin(i); // String _valueString = sqlManager.getSQL(e.getEntity(), context, declarations); string _aliasString = e.GetEntityAlias(); string _joinKey = "Inner Join"; switch (e.GetJoinType()) { case Net.Vpc.Upa.Expressions.JoinType.INNER_JOIN: _joinKey = "Inner Join"; break; case Net.Vpc.Upa.Expressions.JoinType.FULL_JOIN: _joinKey = "Full Join"; break; case Net.Vpc.Upa.Expressions.JoinType.LEFT_JOIN: _joinKey = "Left Join"; break; case Net.Vpc.Upa.Expressions.JoinType.RIGHT_JOIN: _joinKey = "Right Join"; break; case Net.Vpc.Upa.Expressions.JoinType.CROSS_JOIN: _joinKey = "Cross Join"; break; } sb.Append(" ").Append(_joinKey).Append(" ").Append(sqlManager.GetSQL(e.GetEntity(), context, declarations)); if (_aliasString != null) { Net.Vpc.Upa.Persistence.PersistenceStore store = context.GetPersistenceStore(); // String goodAlias = store.getPersistenceName(, PersistenceNameType.ALIAS); sb.Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(_aliasString), context, declarations)); } if (e.GetCondition() != null && e.GetCondition().IsValid()) { sb.Append(" On ").Append(sqlManager.GetSQL(e.GetCondition(), context, declarations)); } } }
protected internal virtual void AppendFrom(Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect o, System.Text.StringBuilder sb, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect entity = o.GetEntity(); if (entity == null) { string fns = GetFromNullString(); if (fns != null) { sb.Append(" "); sb.Append(fns); } } else { sb.Append(" From "); if (entity is Net.Vpc.Upa.Expressions.Select) { sb.Append(sqlManager.GetSQL(entity, context, declarations)); } else { Net.Vpc.Upa.Persistence.PersistenceStore persistenceStore = context.GetPersistenceStore(); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName entityName = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)entity; Net.Vpc.Upa.Entity e = context.GetPersistenceUnit().GetEntity(entityName.GetName()); if (entityName.IsUseView() && e.NeedsView() && persistenceStore.IsViewSupported()) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName v = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(e.GetName(), true); sb.Append(sqlManager.GetSQL(v, context, declarations)); } else { sb.Append(sqlManager.GetSQL(entityName, context, declarations)); } } } if (o.GetEntityAlias() != null) { Net.Vpc.Upa.Persistence.PersistenceStore store = context.GetPersistenceStore(); sb.Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(o.GetEntityAlias()), context, declarations)); } }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext context, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUpdate o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledUpdate)oo; Net.Vpc.Upa.Persistence.PersistenceStore persistenceStore = context.GetPersistenceStore(); Net.Vpc.Upa.PersistenceUnit pu = context.GetPersistenceUnit(); Net.Vpc.Upa.Entity entity = pu.GetEntity(o.GetEntity().GetName()); // String persistenceName = persistenceStore.getPersistenceName(entity); System.Text.StringBuilder sb = new System.Text.StringBuilder("Update " + sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(entity.GetName()), context, declarations)); string tableAlias = o.GetEntityAlias(); if (tableAlias != null) { sb.Append(" "); sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(tableAlias), context, declarations)); } sb.Append(" Set "); bool isFirst = true; int max = o.CountFields(); for (int i = 0; i < max; i++) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar vv = o.GetField(i); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar ev = null; Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar fv = null; if (vv.GetChild() == null) { ev = null; fv = vv; } else { ev = vv; fv = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)vv.GetChild(); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression fieldValue = o.GetFieldValue(i); // Object referrer = vv.getReferrer(); Net.Vpc.Upa.Field f = ((Net.Vpc.Upa.Field)fv.GetReferrer()); Net.Vpc.Upa.Entity entityManager = f.GetEntity(); System.Collections.Generic.IList <Net.Vpc.Upa.PrimitiveField> primFields = entityManager.ToPrimitiveFields <Net.Vpc.Upa.EntityPart>(new System.Collections.Generic.List <Net.Vpc.Upa.EntityPart>(new[] { (Net.Vpc.Upa.EntityPart)f })); foreach (Net.Vpc.Upa.PrimitiveField primField in primFields) { if (isFirst) { isFirst = false; } else { sb.Append(", "); } if (ev != null) { sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(ev.GetName()), context, declarations)).Append("."); } sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(primField), context, declarations)); sb.Append("=").Append("(").Append(sqlManager.GetSQL(fieldValue, context, declarations)).Append(")"); } } if (o.GetCondition() != null && o.GetCondition().IsValid()) { sb.Append(" Where ").Append(sqlManager.GetSQL(o.GetCondition(), context, declarations)); } if (persistenceStore.IsViewSupported() && entity.NeedsView() && o.GetEntity().IsUseView()) { string implicitTableAlias = persistenceStore.GetPersistenceName("IT_" + entity.GetName(), Net.Vpc.Upa.Persistence.PersistenceNameType.ALIAS); sb.Append(" "); sb.Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(entity.GetName()), context, declarations)).Append(" ").Append(implicitTableAlias).Append(",").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName(entity.GetName(), true), context, declarations)).Append(" ").Append(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(tableAlias), context, declarations)); } // if (extraFrom != null) return(sb.ToString()); }
public override string GetSQL(object o, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledKeyEnumerationExpression ee = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledKeyEnumerationExpression)o; Net.Vpc.Upa.Entity entity = null; Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar compiledVar = null; if (ee.GetAlias() != null) { compiledVar = ee.GetAlias(); entity = (compiledVar.GetReferrer() is Net.Vpc.Upa.Entity) ? ((Net.Vpc.Upa.Entity)compiledVar.GetReferrer()) : null; } else { //check if alias System.Collections.Generic.IList <Net.Vpc.Upa.Impl.Uql.ExpressionDeclaration> dvalues = ee.GetDeclarations(null); if (dvalues != null) { foreach (Net.Vpc.Upa.Impl.Uql.ExpressionDeclaration @ref in dvalues) { switch (@ref.GetReferrerType()) { case Net.Vpc.Upa.Impl.Uql.DecObjectType.ENTITY: { entity = qlContext.GetPersistenceUnit().GetEntity((string)@ref.GetReferrerName()); break; } } } } } if (entity == null) { throw new System.ArgumentException("Key enumeration must by associated to and entity"); } if ((ee.GetKeys().Count == 0)) { return(sqlManager.GetSQL(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals(new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(1), new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(2)), qlContext, declarations)); } System.Collections.Generic.IList <Net.Vpc.Upa.Field> pfs = entity.GetPrimaryFields(); Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression o2 = null; foreach (object key in ee.GetKeys()) { Net.Vpc.Upa.Impl.Uql.Compiledexpression.DefaultCompiledExpression a = null; bool processed = false; if (entity.GetPersistenceUnit().ContainsEntity(entity.GetIdType())) { if (!entity.GetIdType().IsInstanceOfType(key)) { //primitive seen as entity? // A's id is A.b where b is an entity //TODO fix all cases! if ((entity.GetPrimaryFields()).Count == 1) { Net.Vpc.Upa.Types.ManyToOneType et = (Net.Vpc.Upa.Types.ManyToOneType)entity.GetPrimaryFields()[0].GetDataType(); System.Collections.Generic.IList <Net.Vpc.Upa.Field> ff = et.GetRelationship().GetSourceRole().GetFields(); Net.Vpc.Upa.Key key2 = et.GetRelationship().GetTargetEntity().GetBuilder().IdToKey(key); for (int j = 0; j < (ff).Count; j++) { Net.Vpc.Upa.Field f = ff[j]; Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar rr = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(f); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar p2 = compiledVar == null ? null : (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)compiledVar.Copy(); if (p2 == null) { p2 = rr; } else { p2.SetChild(rr); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals v = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals(p2, new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(key2.GetObjectAt(j), Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(f))); if (a == null) { a = v; } else { a = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledAnd(a, v); } } if (o2 == null) { o2 = a; } else { o2 = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledOr(o2, a); } processed = true; } } } if (!processed) { Net.Vpc.Upa.Key uKey = entity.GetBuilder().IdToKey(key); for (int j = 0; j < (pfs).Count; j++) { Net.Vpc.Upa.Field f = pfs[j]; Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar rr = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar(f); Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar p2 = compiledVar == null ? null : (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledVar)compiledVar.Copy(); if (p2 == null) { p2 = rr; } else { p2.SetChild(rr); } Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals v = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEquals(p2, new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledLiteral(uKey.GetObjectAt(j), Net.Vpc.Upa.Impl.Util.UPAUtils.GetTypeTransformOrIdentity(f))); if (a == null) { a = v; } else { a = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledAnd(a, v); } } if (o2 == null) { o2 = a; } else { o2 = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledOr(o2, a); } } } return(sqlManager.GetSQL(o2, qlContext, declarations)); }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledAvg o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledAvg)oo; return("Avg(" + sqlManager.GetSQL(o.GetExpression(), qlContext, declarations) + ")"); }
public override string GetSQL(object oo, Net.Vpc.Upa.Persistence.EntityExecutionContext qlContext, Net.Vpc.Upa.Impl.Persistence.SQLManager sqlManager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations) /* throws Net.Vpc.Upa.Exceptions.UPAException */ { Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledBinaryOperatorExpression o = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledBinaryOperatorExpression)oo; string leftValue = o.GetLeft() != null?sqlManager.GetSQL(o.GetLeft(), qlContext, declarations) : "NULL"; string rightValue = o.GetRight() != null?sqlManager.GetSQL(o.GetRight(), qlContext, declarations) : "NULL"; string s = null; switch (o.GetOperator()) { case Net.Vpc.Upa.Expressions.BinaryOperator.AND: { s = leftValue + " And " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.OR: { s = leftValue + " Or " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.BIT_AND: { s = leftValue + " & " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.LSHIFT: { s = leftValue + " << " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.BIT_OR: { s = leftValue + " | " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.RSHIFT: { s = leftValue + " >> " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.URSHIFT: { s = leftValue + " >>> " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.XOR: { s = leftValue + " ^ " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.DIFF: { if ("NULL".Equals(rightValue, System.StringComparison.InvariantCultureIgnoreCase)) { s = leftValue + " IS NOT " + rightValue; } else { s = leftValue + " <> " + rightValue; } break; } case Net.Vpc.Upa.Expressions.BinaryOperator.EQ: { if ("NULL".Equals(rightValue, System.StringComparison.InvariantCultureIgnoreCase)) { s = leftValue + " IS " + rightValue; } else { s = leftValue + " = " + rightValue; } break; } case Net.Vpc.Upa.Expressions.BinaryOperator.GT: { s = leftValue + " > " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.GE: { s = leftValue + " >= " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.LT: { s = leftValue + " < " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.LE: { s = leftValue + " < " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.PLUS: { s = leftValue + " + " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.MINUS: { s = leftValue + " - " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.MUL: { s = leftValue + " * " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.DIV: { s = leftValue + " - " + rightValue; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.REM: { s = "{fn mod(" + leftValue + "," + rightValue + " )}"; break; } case Net.Vpc.Upa.Expressions.BinaryOperator.LIKE: { //escape seems to be not supported with '*' wildcard //s=leftValue+" Like "+rightValue+" {escape '*'} "; s = leftValue + " Like " + rightValue + " "; break; } default: { throw new System.ArgumentException("Not Supported Yet"); } } return("(" + s + ")"); }