/// <summary> /// /// </summary> /// <param name="entity">an actual entity object, not a proxy!</param> /// <param name="entityMode"></param> /// <returns></returns> public string ToString(object entity, EntityMode entityMode) { IClassMetadata cm = _factory.GetClassMetadata(entity.GetType()); if (cm == null) { return(entity.GetType().FullName); } IDictionary <string, string> result = new Dictionary <string, string>(); if (cm.HasIdentifierProperty) { result[cm.IdentifierPropertyName] = cm.IdentifierType.ToLoggableString(cm.GetIdentifier(entity, entityMode), _factory); } IType[] types = cm.PropertyTypes; string[] names = cm.PropertyNames; object[] values = cm.GetPropertyValues(entity, entityMode); for (int i = 0; i < types.Length; i++) { result[names[i]] = types[i].ToLoggableString(values[i], _factory); } return(cm.EntityName + CollectionPrinter.ToString(result)); }
public override TypedValue[] GetTypedValues(ISessionFactoryImplementor sessionFactory, System.Type persistentClass, IDictionary aliasClasses) { IClassMetadata meta = sessionFactory.GetClassMetadata(persistentClass); string[] propertyNames = meta.PropertyNames; IType[] propertyTypes = meta.PropertyTypes; object[] values = meta.GetPropertyValues(_entity); ArrayList list = new ArrayList(); for (int i = 0; i < propertyNames.Length; i++) { object value = values[i]; IType type = propertyTypes[i]; string name = propertyNames[i]; bool isPropertyIncluded = (i != meta.VersionProperty && IsPropertyIncluded(value, name, type)); if (isPropertyIncluded) { if (propertyTypes[i].IsComponentType) { AddComponentTypedValues(name, value, (IAbstractComponentType)type, list); } else { AddPropertyTypedValue(value, type, list); } } } return((TypedValue[])list.ToArray(typeof(TypedValue))); }
public override SqlString ToSqlString( ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses) { SqlStringBuilder builder = new SqlStringBuilder(); builder.Add(StringHelper.OpenParen); IClassMetadata meta = factory.GetClassMetadata(persistentClass); String[] propertyNames = meta.PropertyNames; IType[] propertyTypes = meta.PropertyTypes; object[] propertyValues = meta.GetPropertyValues(_entity); for (int i = 0; i < propertyNames.Length; i++) { object propertyValue = propertyValues[i]; String propertyName = propertyNames[i]; bool isPropertyIncluded = i != meta.VersionProperty && IsPropertyIncluded(propertyValue, propertyName, propertyTypes[i]); if (isPropertyIncluded) { if (propertyTypes[i].IsComponentType) { AppendComponentCondition( propertyName, propertyValue, (IAbstractComponentType)propertyTypes[i], persistentClass, alias, aliasClasses, factory, builder ); } else { AppendPropertyCondition( propertyName, propertyValue, persistentClass, alias, aliasClasses, factory, builder ); } } } if (builder.Count == 1) { builder.Add("1=1"); // yuck! } builder.Add(StringHelper.ClosedParen); return(builder.ToSqlString()); }
/// <summary> /// Retrieves the Id of an existing entity /// </summary> /// <param name="instance"></param> /// <returns></returns> protected override string GetId(object instance) { IClassMetadata metadata = sessionFactory.GetClassMetadata(instance.GetType().BaseType); IEntityPersister persister = sessionFactory.GetEntityPersister(instance.GetType().BaseType.ToString()); ((IGraphInstance)instance).SuspendNotifications = true; object id = metadata.GetIdentifier(instance, EntityMode.Poco); ((IGraphInstance)instance).SuspendNotifications = false; // This is a bit of a hack. if (persister.EntityMetamodel.IdentifierProperty.UnsavedValue.IsUnsaved(id).GetValueOrDefault()) { return(null); } string idString = TypeDescriptor.GetConverter(id).ConvertToString(id); return(idString); }
internal PersistenceUnit GetPU(System.Type t) { if (PersistenceUnits.Count == 0) { throw new PersistenceUnitsNotReadyException(); } if (PersistenceUnits.Count == 1) { return(PersistenceUnits[0]); } foreach (PersistenceUnit pu in persistenceUnits) { ISessionFactoryImplementor sfi = (ISessionFactoryImplementor)pu.SessionFactory; if (sfi.GetClassMetadata(t) != null) { return(pu); } } throw new GeneralException("Persistence Unit cannot be found for " + t); }
/// <summary> /// This translation operation is called when a shard-aware HQL query is to be generated for /// a shard that will execute the query. It transforms the shard-unaware query plan /// that may contain aggregations and paging instructions that will not work as expected /// when query results are to be aggregated from multiple shards. /// </summary> /// <param name="sessionFactory"></param> /// <param name="filter"></param> /// <returns></returns> public IASTNode Translate(ISessionFactoryImplementor sessionFactory, bool filter) { var root = this.UnshardedQueryExpression.Translate(sessionFactory, filter); var entityName = sessionFactory.TryGetGuessEntityName(this.Type); if (entityName == null) { if (this.unshardedQueryExpressionPlan.ReturnMetadata.ReturnTypes[0] is EntityType rootEntityType) { entityName = rootEntityType.GetAssociatedEntityName(sessionFactory); } } var rootClassMetadata = entityName != null ? sessionFactory.GetClassMetadata(entityName) : null; var hqlGenerator = new ShardedHqlGenerator(root, rootClassMetadata, this.parameterValuesByName, this.exitOperationBuilder); return(hqlGenerator.ShardedHql); }
/// <summary> /// /// </summary> /// <param name="entity">an actual entity object, not a proxy!</param> /// <returns></returns> public string ToString(object entity) { IClassMetadata cm = _factory.GetClassMetadata(entity.GetType()); if (cm == null) { return(entity.GetType().FullName); } IDictionary <string, string> result = new Dictionary <string, string>(); if (cm.HasIdentifierProperty) { result[cm.IdentifierPropertyName] = cm.IdentifierType.ToLoggableString(cm.GetIdentifier(entity), _factory); } IType[] types = cm.PropertyTypes; string[] names = cm.PropertyNames; object[] values = cm.GetPropertyValues(entity); for (int i = 0; i < types.Length; i++) { var value = values[i]; if (Equals(LazyPropertyInitializer.UnfetchedProperty, value) || Equals(BackrefPropertyAccessor.Unknown, value)) { result[names[i]] = value.ToString(); } else { result[names[i]] = types[i].ToLoggableString(value, _factory); } } return(cm.EntityName + CollectionPrinter.ToString(result)); }
public bool IsIdentifier(System.Type type, string propertyName) { var metadata = _sessionFactory.GetClassMetadata(type); return(metadata != null && propertyName.Equals(metadata.IdentifierPropertyName)); }
internal SingleTableEntityPersister GetPersister(string entityName) { var persister = ResolvePersister(entityName); return(GetPersister(_sessionFactory.GetClassMetadata(persister.EntityName))); }
public override TypedValue[] GetTypedValues(ISessionFactoryImplementor sessionFactory, System.Type persistentClass, IDictionary aliasClasses) { IClassMetadata meta = sessionFactory.GetClassMetadata( persistentClass ); string[] propertyNames = meta.PropertyNames; IType[] propertyTypes = meta.PropertyTypes; object[] values = meta.GetPropertyValues( _entity ); ArrayList list = new ArrayList(); for( int i = 0; i < propertyNames.Length; i++ ) { object value = values[ i ]; IType type = propertyTypes[ i ]; string name = propertyNames[ i ]; bool isPropertyIncluded = ( i != meta.VersionProperty && IsPropertyIncluded( value, name, type ) ); if( isPropertyIncluded ) { if( propertyTypes[ i ].IsComponentType ) { AddComponentTypedValues( name, value, (IAbstractComponentType)type, list ); } else { AddPropertyTypedValue( value, type, list ); } } } return (TypedValue[])list.ToArray( typeof( TypedValue ) ); }
public override SqlString ToSqlString( ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses ) { SqlStringBuilder builder = new SqlStringBuilder(); builder.Add( StringHelper.OpenParen ); IClassMetadata meta = factory.GetClassMetadata( persistentClass ); String[] propertyNames = meta.PropertyNames; IType[] propertyTypes = meta.PropertyTypes; object[] propertyValues = meta.GetPropertyValues( _entity ); for( int i = 0; i < propertyNames.Length; i++ ) { object propertyValue = propertyValues[ i ]; String propertyName = propertyNames[ i ]; bool isPropertyIncluded = i != meta.VersionProperty && IsPropertyIncluded( propertyValue, propertyName, propertyTypes[ i ] ); if( isPropertyIncluded ) { if( propertyTypes[ i ].IsComponentType ) { AppendComponentCondition( propertyName, propertyValue, (IAbstractComponentType)propertyTypes[ i ], persistentClass, alias, aliasClasses, factory, builder ); } else { AppendPropertyCondition( propertyName, propertyValue, persistentClass, alias, aliasClasses, factory, builder ); } } } if( builder.Count == 1 ) { builder.Add( "1=1" ); // yuck! } builder.Add( StringHelper.ClosedParen ); return builder.ToSqlString(); }