/// <summary> /// Retrieves the foreign key in this mapping and all its children /// </summary> /// <returns></returns> public IEnumerable <ForeignKeyMappingInfo> GetForeignKeys() { var thisLevelFks = SimpleProperties.OfType <ForeignKeyMappingInfo>(); var lowerLevelsFks = CollectionProperties.SelectMany(e => e.GetForeignKeys()); return(thisLevelFks.Concat(lowerLevelsFks)); }
public string[] ToColumns(string tableAlias, string path, bool inSelect, bool forceAlias) { CheckInitialized(); IPropertyMapping propertyMapping = GetPropertyMapping(path); // If this from element is a collection and the path is a collection property (maxIndex, etc.) then // generate a sub-query. if (!inSelect && _queryableCollection != null && CollectionProperties.IsCollectionProperty(path)) { IDictionary <string, IFilter> enabledFilters = _fromElement.Walker.EnabledFilters; string subquery = CollectionSubqueryFactory.CreateCollectionSubquery( _joinSequence, enabledFilters, propertyMapping.ToColumns(tableAlias, path) ); if (Log.IsDebugEnabled()) { Log.Debug("toColumns({0},{1}) : subquery = {2}", tableAlias, path, subquery); } return(new [] { "(" + subquery + ")" }); } else { if (forceAlias) { return(propertyMapping.ToColumns(tableAlias, path)); } else if (_fromElement.Walker.StatementType == HqlSqlWalker.SELECT) { return(propertyMapping.ToColumns(tableAlias, path)); } else if (_fromElement.Walker.CurrentClauseType == HqlSqlWalker.SELECT) { return(propertyMapping.ToColumns(tableAlias, path)); } else if (_fromElement.Walker.IsSubQuery) { // We already know it's subqery for DML query. // If this FROM_ELEMENT represents a correlation to the outer-most query we must use real table name // for UPDATE(typically in a SET clause)/DELETE queries unless it's multi-table reference inside top level where clause // (as this subquery will actually be used in the "id select" phase of that multi-table executor) var useAlias = _fromElement.Walker.StatementType == HqlSqlWalker.INSERT || (IsMultiTable && _fromElement.Walker.CurrentTopLevelClauseType == HqlSqlWalker.WHERE); if (!useAlias && IsCorrelation) { return(propertyMapping.ToColumns(ExtractTableName(), path)); } return(propertyMapping.ToColumns(tableAlias, path)); } else { string[] columns = propertyMapping.ToColumns(path); Log.Info("Using non-qualified column reference [{0} -> ({1})]", path, ArrayHelper.ToString(columns)); return(columns); } } }
public static void Main(string[] args) { Gnome.Program program = new Program("collection-properties", "0.10.0", Modules.UI, args); Store store = Store.GetStore(); if(args.Length < 1) { Console.WriteLine("Usage: ColPropViewer [collectionID]"); Console.WriteLine(" where collectionID is:"); foreach(ShallowNode sn in store) { Collection col = store.GetCollectionByID(sn.ID); Console.WriteLine("{0} : {1}", col.Name, col.ID); } } else { Collection col = store.GetCollectionByID(args[0]); if(col != null) { CollectionProperties cp = new CollectionProperties(); cp.Collection = col; cp.Closed += new EventHandler(on_cp_closed); cp.Show(); program.Run(); } } }
/// <summary>Initializes a new instance of the <see cref="T:System.Object"></see> class.</summary> public TypeMeta(Type typeRef, Hijack h) { _hijack = h; TypeRef = typeRef; _isAnonymous = typeRef.IsAnonymousType(); if (!_isAnonymous) { try { DefaultInstance = Activator.CreateInstance(typeRef); } catch (Exception) { DefaultInstance = typeRef.InstanceNonpublic(); } } var properties = GetProperties(); InlineProperties = properties.Where(x => x.PropertyType.IsInlineable()).ToArray(); CollectionProperties = properties.Where(x => (!x.PropertyType.IsDictionary() && x.PropertyType.IsEnumerable()) || (x.PropertyType.IsTuple() && !x.PropertyType.IsInlineable())).ToArray(); DictionaryProperties = properties.Where(x => x.PropertyType.IsDictionary()).ToArray(); NestedProperties = properties.Where(x => !InlineProperties.Contains(x) && !CollectionProperties.Contains(x) && !DictionaryProperties.Contains(x)).ToArray(); }
public override void Resolve(bool generateJoin, bool implicitJoin, string classAlias, IASTNode parent) { // If this dot has already been resolved, stop now. if (IsResolved) { return; } IType propertyType = PrepareLhs(); // Prepare the left hand side and get the data type. // If there is no data type for this node, and we're at the end of the path (top most dot node), then // this might be a Java constant. if (propertyType == null) { if (parent == null) { Walker.LiteralProcessor.LookupConstant(this); } // If the propertyType is null and there isn't a parent, just // stop now... there was a problem resolving the node anyway. return; } if (propertyType.IsComponentType) { // The property is a component... CheckLhsIsNotCollection(); DereferenceComponent(parent); InitText(); } else if (propertyType.IsEntityType) { // The property is another class.. CheckLhsIsNotCollection(); DereferenceEntity(( EntityType )propertyType, implicitJoin, classAlias, generateJoin, parent); InitText(); } else if (propertyType.IsCollectionType) { // The property is a collection... CheckLhsIsNotCollection(); DereferenceCollection((CollectionType)propertyType, implicitJoin, false, classAlias); } else { // Otherwise, this is a primitive type. if (!CollectionProperties.IsAnyCollectionProperty(_propertyName)) { CheckLhsIsNotCollection(); } _dereferenceType = DerefPrimitive; InitText(); } IsResolved = true; }
public PropertyBase FindProperty(string name) { var sp = Properties.SingleOrDefault(x => x.称 == name); if (sp != null) { return(sp); } return(CollectionProperties.SingleOrDefault(x => x.称 == name)); }
public void HandlePropertyBeingDereferenced(IType propertySource, string propertyName) { if (QueryableCollection != null && CollectionProperties.IsCollectionProperty(propertyName)) { // propertyName refers to something like collection.size... return; } if (propertySource.IsComponentType) { // property name is a sub-path of a component... return; } IQueryable persister = Queryable; if (persister != null) { try { Declarer propertyDeclarer = persister.GetSubclassPropertyDeclarer(propertyName); if (Log.IsInfoEnabled()) { Log.Info("handling property dereference [{0} ({1}) -> {2} ({3})]", persister.EntityName, ClassAlias, propertyName, propertyDeclarer); } if (propertyDeclarer == Declarer.SubClass) { _dereferencedBySubclassProperty = true; _includeSubclasses = true; } else if (propertyDeclarer == Declarer.SuperClass) { _dereferencedBySuperclassProperty = true; } } catch (QueryException ex) { // ignore it; the incoming property could not be found so we // cannot be sure what to do here. At the very least, the // safest is to simply not apply any dereference toggling... Log.Debug(ex, "Unable to find property {0}, no dereference will be handled for it.", propertyName); } } }
public void ResolveCollectionProperty(IASTNode expr) { String propertyName = CollectionProperties.GetNormalizedPropertyName(_methodName); if (expr is FromReferenceNode) { FromReferenceNode collectionNode = ( FromReferenceNode )expr; // If this is 'elements' then create a new FROM element. if (CollectionPropertyNames.Elements == propertyName) { HandleElements(collectionNode, propertyName); } else { // Not elements(x) _fromElement = collectionNode.FromElement; DataType = _fromElement.GetPropertyType(propertyName, propertyName); _selectColumns = _fromElement.ToColumns(_fromElement.TableAlias, propertyName, _inSelect); } if (collectionNode is DotNode) { PrepareAnyImplicitJoins(( DotNode )collectionNode); } if (!_inSelect) { _fromElement.Text = ""; _fromElement.UseWhereFragment = false; } PrepareSelectColumns(_selectColumns); Text = _selectColumns[0]; Type = HqlSqlWalker.SQL_TOKEN; } else { throw new SemanticException( "Unexpected expression " + expr + " found for collection function " + propertyName ); } }
public void ResolveCollectionProperty(IASTNode expr) { var propertyName = CollectionProperties.GetNormalizedPropertyName(_methodName); var collectionNode = expr as FromReferenceNode; if (collectionNode == null) { throw new SemanticException(string.Format("Unexpected expression {0} found for collection function {1}", expr, propertyName)); } // If this is 'elements' then create a new FROM element. if (CollectionPropertyNames.Elements == propertyName) { HandleElements(collectionNode, propertyName); } else { // Not elements(x) _fromElement = collectionNode.FromElement; DataType = _fromElement.GetPropertyType(propertyName, propertyName); _selectColumns = _fromElement.ToColumns(_fromElement.TableAlias, propertyName, _inSelect); } var dotNode = collectionNode as DotNode; if (dotNode != null) { PrepareAnyImplicitJoins(dotNode); } if (!_inSelect) { _fromElement.Text = ""; _fromElement.UseWhereFragment = false; } PrepareSelectColumns(_selectColumns); Text = _selectColumns[0]; Type = HqlSqlWalker.SQL_TOKEN; }
public IPropertyMapping GetPropertyMapping(string propertyName) { CheckInitialized(); if (_queryableCollection == null) { // Not a collection? return((IPropertyMapping)_persister); // Return the entity property mapping. } // If the property is a special collection property name, return a CollectionPropertyMapping. if (CollectionProperties.IsCollectionProperty(propertyName)) { if (_collectionPropertyMapping == null) { _collectionPropertyMapping = new CollectionPropertyMapping(_queryableCollection); } return(_collectionPropertyMapping); } if (_queryableCollection.ElementType.IsAnyType) { // collection of <many-to-any/> mappings... // used to circumvent the component-collection check below... return(_queryableCollection); } if (_queryableCollection.ElementType.IsComponentType) { // Collection of components. if (propertyName == Persister.Entity.EntityPersister.EntityID) { return((IPropertyMapping)_queryableCollection.OwnerEntityPersister); } } return(_queryableCollection); }
private void DereferenceCollection(CollectionType collectionType, bool implicitJoin, bool indexed, string classAlias) { _dereferenceType = DerefCollection; string role = collectionType.Role; //foo.bars.size (also handles deprecated stuff like foo.bars.maxelement for backwardness) IASTNode sibling = NextSibling; bool isSizeProperty = sibling != null && CollectionProperties.IsAnyCollectionProperty(sibling.Text); if (isSizeProperty) { indexed = true; //yuck!} } IQueryableCollection queryableCollection = SessionFactoryHelper.RequireQueryableCollection(role); string propName = Path; FromClause currentFromClause = Walker.CurrentFromClause; if (Walker.StatementType != HqlSqlWalker.SELECT && indexed && classAlias == null) { // should indicate that we are processing an INSERT/UPDATE/DELETE // query with a subquery implied via a collection property // function. Here, we need to use the table name itself as the // qualification alias. // TODO : verify this works for all databases... // TODO : is this also the case in non-"indexed" scenarios? string alias = GetLhs().FromElement.Queryable.TableName; _columns = FromElement.ToColumns(alias, _propertyPath, false, true); } //We do not look for an existing join on the same path, because //it makes sense to join twice on the same collection role FromElementFactory factory = new FromElementFactory( currentFromClause, GetLhs().FromElement, propName, classAlias, GetColumns(), implicitJoin ); FromElement elem = factory.CreateCollection(queryableCollection, role, _joinType, _fetch, indexed); if (Log.IsDebugEnabled) { Log.Debug("dereferenceCollection() : Created new FROM element for " + propName + " : " + elem); } SetImpliedJoin(elem); FromElement = elem; // This 'dot' expression now refers to the resulting from element. if (isSizeProperty) { elem.Text = ""; elem.UseWhereFragment = false; } if (!implicitJoin) { IEntityPersister entityPersister = elem.EntityPersister; if (entityPersister != null) { Walker.AddQuerySpaces(entityPersister.QuerySpaces); } } Walker.AddQuerySpaces(queryableCollection.CollectionSpaces); // Always add the collection's query spaces. }
public string[] ToColumns(string tableAlias, string path, bool inSelect, bool forceAlias) { CheckInitialized(); IPropertyMapping propertyMapping = GetPropertyMapping(path); // If this from element is a collection and the path is a collection property (maxIndex, etc.) then // generate a sub-query. if (!inSelect && _queryableCollection != null && CollectionProperties.IsCollectionProperty(path)) { IDictionary <string, IFilter> enabledFilters = _fromElement.Walker.EnabledFilters; string subquery = CollectionSubqueryFactory.CreateCollectionSubquery( _joinSequence, enabledFilters, propertyMapping.ToColumns(tableAlias, path) ); if (Log.IsDebugEnabled) { Log.Debug("toColumns(" + tableAlias + "," + path + ") : subquery = " + subquery); } return(new [] { "(" + subquery + ")" }); } else { if (forceAlias) { return(propertyMapping.ToColumns(tableAlias, path)); } else if (_fromElement.Walker.StatementType == HqlSqlWalker.SELECT) { return(propertyMapping.ToColumns(tableAlias, path)); } else if (_fromElement.Walker.CurrentClauseType == HqlSqlWalker.SELECT) { return(propertyMapping.ToColumns(tableAlias, path)); } else if (_fromElement.Walker.IsSubQuery) { // for a subquery, the alias to use depends on a few things (we // already know this is not an overall SELECT): // 1) if this FROM_ELEMENT represents a correlation to the // outer-most query // A) if the outer query represents a multi-table // persister, we need to use the given alias // in anticipation of one of the multi-table // executors being used (as this subquery will // actually be used in the "id select" phase // of that multi-table executor) // B) otherwise, we need to use the persister's // table name as the column qualification // 2) otherwise (not correlated), use the given alias if (IsCorrelation) { if (IsMultiTable) { return(propertyMapping.ToColumns(tableAlias, path)); } else { return(propertyMapping.ToColumns(ExtractTableName(), path)); } } else { return(propertyMapping.ToColumns(tableAlias, path)); } } else { string[] columns = propertyMapping.ToColumns(path); Log.Info("Using non-qualified column reference [" + path + " -> (" + ArrayHelper.ToString(columns) + ")]"); return(columns); } } }
public IEnumerable <PropertyMappingInfo> AllPropertyMappings() => SimpleProperties .Concat(CollectionProperties.SelectMany(p => p.AllPropertyMappings()));
public void on_share_clicked(object o, EventArgs args) { TreeSelection tSelect = BookTreeView.Selection; if(tSelect.CountSelectedRows() == 1) { TreeModel tModel; TreeIter iter; tSelect.GetSelected(out tModel, out iter); curAddrBook = (AddressBook) tModel.GetValue(iter,0); CollectionProperties colProp = new CollectionProperties(); colProp.TransientFor = CBApp; colProp.Collection = curAddrBook; colProp.ActiveTag = 1; colProp.Run(); } }
public void on_properties(object o, EventArgs eventArgs) { CollectionProperties colProp = new CollectionProperties(); colProp.TransientFor = SloggerApp; colProp.Collection = curSlog; colProp.ActiveTag = 1; colProp.Run(); }