/// <summary> /// Builds an SqlQuery to delete the database record with the specified identifier for the type specified by the IObjectInfo. /// </summary> /// <param name="objectInfo">The object information.</param> /// <param name="identifier">The identifier of the instance to delete.</param> /// <returns> /// The created <see cref="SqlQuery" />. /// </returns> public SqlQuery BuildDeleteSqlQuery(IObjectInfo objectInfo, object identifier) { if (objectInfo == null) { throw new ArgumentNullException("objectInfo"); } string deleteCommand; if (!this.deleteCommandCache.TryGetValue(objectInfo.ForType, out deleteCommand)) { var deleteSqlQuery = new DeleteSqlBuilder(this.SqlCharacters) .From(objectInfo) .WhereEquals(objectInfo.TableInfo.IdentifierColumn.ColumnName, identifier) .ToSqlQuery(); var newDeleteCommandCache = new Dictionary<Type, string>(this.deleteCommandCache); newDeleteCommandCache[objectInfo.ForType] = deleteSqlQuery.CommandText; this.deleteCommandCache = newDeleteCommandCache; return deleteSqlQuery; } return new SqlQuery(deleteCommand, identifier); }
/// <summary> /// Binds the select query option to the SqlBuilder. /// </summary> /// <param name="selectQueryOption">The select query option.</param> /// <param name="objectInfo">The IObjectInfo for the type to bind the select list for.</param> /// <returns>The SqlBuilder after the select and from clauses have been added.</returns> public static IWhereOrOrderBy BindSelect(SelectQueryOption selectQueryOption, IObjectInfo objectInfo) { if (objectInfo == null) { throw new ArgumentNullException("objectInfo"); } if (selectQueryOption == null || (selectQueryOption.Properties.Count == 1 && selectQueryOption.Properties[0] == "*")) { return SqlBuilder.Select("*").From(objectInfo.ForType); } var columnNames = new string[selectQueryOption.Properties.Count]; int columnCount = 0; for (int i = 0; i < selectQueryOption.Properties.Count; i++) { var property = selectQueryOption.Properties[i]; var column = objectInfo.TableInfo.GetColumnInfoForProperty(property); if (column == null) { throw new ODataException(string.Format(CultureInfo.InvariantCulture, Messages.InvalidPropertyName, objectInfo.ForType.Name, property)); } columnNames[columnCount++] = column.ColumnName; } return SqlBuilder.Select(columnNames).From(objectInfo.ForType); }
internal IWhere From(IObjectInfo objectInfo) { this.InnerSql.Append(" FROM "); this.AppendTableName(objectInfo); return this; }
protected override string BuildInsertCommandText(IObjectInfo objectInfo) { if (objectInfo == null) { throw new ArgumentNullException("objectInfo"); } var commandText = base.BuildInsertCommandText(objectInfo); if (objectInfo.TableInfo.IdentifierStrategy == IdentifierStrategy.Sequence) { commandText = "DECLARE @@id " + GetSqlType(objectInfo.TableInfo.IdentifierColumn) + ";" + "SELECT @@id = NEXT VALUE FOR " + objectInfo.TableInfo.IdentifierColumn.SequenceName + ";" + commandText; var firstParenthesisIndex = commandText.IndexOf('(') + 1; commandText = commandText.Insert( firstParenthesisIndex, this.SqlCharacters.EscapeSql(objectInfo.TableInfo.IdentifierColumn.ColumnName) + ","); var secondParenthesisIndex = commandText.IndexOf('(', firstParenthesisIndex) + 1; commandText = commandText.Insert( secondParenthesisIndex, "@@id,"); } return commandText; }
protected override string BuildInsertCommandText(IObjectInfo objectInfo) { if (objectInfo == null) { throw new ArgumentNullException("objectInfo"); } var commandText = base.BuildInsertCommandText(objectInfo); if (objectInfo.TableInfo.IdentifierStrategy == IdentifierStrategy.Sequence) { var firstParenthesisIndex = commandText.IndexOf('(') + 1; commandText = commandText.Insert( firstParenthesisIndex, this.SqlCharacters.EscapeSql(objectInfo.TableInfo.IdentifierColumn.ColumnName) + ","); var secondParenthesisIndex = commandText.IndexOf('(', firstParenthesisIndex) + 1; commandText = commandText.Insert( secondParenthesisIndex, "GEN_ID(" + objectInfo.TableInfo.IdentifierColumn.SequenceName + ", 1),"); } if (objectInfo.TableInfo.IdentifierStrategy != IdentifierStrategy.Assigned) { commandText += " RETURNING " + objectInfo.TableInfo.IdentifierColumn.ColumnName; } return commandText; }
internal static Func<object, object> CreateGetIdentifier(IObjectInfo objectInfo) { var dynamicMethod = new DynamicMethod( name: "MicroLite" + objectInfo.ForType.Name + "GetIdentifier", returnType: typeof(object), parameterTypes: new[] { typeof(object) }); // arg_0 var ilGenerator = dynamicMethod.GetILGenerator(); // var instance = ({Type})arg_0; ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Castclass, objectInfo.ForType); // var identifier = instance.Id; ilGenerator.Emit(OpCodes.Callvirt, objectInfo.TableInfo.IdentifierColumn.PropertyInfo.GetGetMethod()); // value = (object)identifier; ilGenerator.EmitBoxIfValueType(objectInfo.TableInfo.IdentifierColumn.PropertyInfo.PropertyType); // return identifier; ilGenerator.Emit(OpCodes.Ret); var getIdentifierValue = (Func<object, object>)dynamicMethod.CreateDelegate(typeof(Func<object, object>)); return getIdentifierValue; }
internal static Func<object, SqlArgument[]> CreateGetInsertValues(IObjectInfo objectInfo) { var dynamicMethod = new DynamicMethod( name: "MicroLite" + objectInfo.ForType.Name + "GetInsertValues", returnType: typeof(SqlArgument[]), parameterTypes: new[] { typeof(object) }, // arg_0 m: typeof(ObjectInfo).Module); var ilGenerator = dynamicMethod.GetILGenerator(); ilGenerator.DeclareLocal(objectInfo.ForType); // loc_0 - {Type} instance; ilGenerator.DeclareLocal(typeof(SqlArgument[])); // loc_1 - SqlArgument[] sqlArguments; // instance = ({Type})arg_0; ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Castclass, objectInfo.ForType); ilGenerator.Emit(OpCodes.Stloc_0); // sqlArguments = new SqlArgument[count]; ilGenerator.EmitEfficientInt(objectInfo.TableInfo.InsertColumnCount); ilGenerator.Emit(OpCodes.Newarr, typeof(SqlArgument)); ilGenerator.Emit(OpCodes.Stloc_1); EmitGetPropertyValues(ilGenerator, objectInfo, c => c.AllowInsert); // return sqlArguments; ilGenerator.Emit(OpCodes.Ldloc_1); ilGenerator.Emit(OpCodes.Ret); var getInsertValues = (Func<object, SqlArgument[]>)dynamicMethod.CreateDelegate(typeof(Func<object, SqlArgument[]>)); return getInsertValues; }
internal ISetOrWhere Table(IObjectInfo objectInfo) { this.AppendTableName(objectInfo); this.InnerSql.Append(" SET "); return this; }
void IObjectManager.CreateObject(IObjectInfo objInfo) { var variableInfo = objInfo as VariableInfo; if (variableInfo == null) throw new ArgumentException(); DefineVariable(variableInfo); }
public void Encode(ByteArrayOutputStream os, IObjectInfo info) { PrimitiveCodec.WriteLong(os, info.GetInternalID()); long sourceDatabaseId = ((FrozenObjectInfo)info).SourceDatabaseId(this._enclosing .Transaction()); PrimitiveCodec.WriteLong(os, sourceDatabaseId); PrimitiveCodec.WriteLong(os, ((FrozenObjectInfo)info).UuidLongPart()); PrimitiveCodec.WriteLong(os, info.GetCommitTimestamp()); }
public static void AlterObject(this IQueryContext context, IObjectInfo objectInfo) { if (objectInfo == null) throw new ArgumentNullException("objectInfo"); if (!context.UserCanAlterObject(objectInfo.ObjectType, objectInfo.FullName)) throw new MissingPrivilegesException(context.UserName(), objectInfo.FullName, Privileges.Alter); context.Session().AlterObject(objectInfo); }
private void AssertInfosAreConsistent(long[] ids, IObjectInfo[] infos) { for (var i = 0; i < infos.Length; i++) { var info = Db().GetObjectInfo(Db().GetByID(ids[i])); Assert.AreEqual(info.GetInternalID(), infos[i].GetInternalID()); Assert.AreEqual(info.GetUUID().GetLongPart(), infos[i].GetUUID().GetLongPart()); Assert.AreSame(info.GetObject(), infos[i].GetObject()); } }
protected override string BuildInsertCommandText(IObjectInfo objectInfo) { var commandText = base.BuildInsertCommandText(objectInfo); if (objectInfo.TableInfo.IdentifierStrategy == IdentifierStrategy.DbGenerated) { commandText += " RETURNING " + objectInfo.TableInfo.IdentifierColumn.ColumnName; } return commandText; }
private void AssertGeneration(IObjectInfo objectInfo, bool expectGeneration) { if (expectGeneration) { Assert.IsNotNull(objectInfo.GetUUID()); } else { Assert.IsNull(objectInfo.GetUUID()); Assert.AreEqual(0L, objectInfo.GetCommitTimestamp()); } }
/// <summary> /// Appends the table name to the inner sql. /// </summary> /// <param name="objectInfo">The object information.</param> protected void AppendTableName(IObjectInfo objectInfo) { if (!string.IsNullOrEmpty(objectInfo.TableInfo.Schema)) { this.InnerSql.Append(this.sqlCharacters.LeftDelimiter) .Append(objectInfo.TableInfo.Schema) .Append(this.sqlCharacters.RightDelimiter) .Append('.'); } this.AppendTableName(objectInfo.TableInfo.Name); }
public WhenNotUsingDefaultSettings() { var settings = UnitTest.GetConventionMappingSettings(IdentifierStrategy.Assigned); settings.Ignore = (PropertyInfo propertyInfo) => { return propertyInfo.Name == "Website"; }; settings.UsePluralClassNameForTableName = false; var mappingConvention = new ConventionMappingConvention(settings); this.objectInfo = mappingConvention.CreateObjectInfo(typeof(Customer)); }
public override SqlQuery BuildSelectInsertIdSqlQuery(IObjectInfo objectInfo) { if (objectInfo == null) { throw new ArgumentNullException("objectInfo"); } if (objectInfo.TableInfo.IdentifierStrategy == IdentifierStrategy.Sequence) { return new SqlQuery("SELECT @@id"); } return base.BuildSelectInsertIdSqlQuery(objectInfo); }
public static bool AlterObject(this ITransaction transaction, IObjectInfo objInfo) { if (objInfo == null) throw new ArgumentNullException("objInfo"); var manager = transaction.GetObjectManager(objInfo.ObjectType); if (manager == null) throw new InvalidOperationException(); if (manager.ObjectType != objInfo.ObjectType) throw new ArgumentException(); return manager.AlterObject(objInfo); }
public static void CreateObject(this ITransaction transaction, IObjectInfo objInfo) { if (objInfo == null) throw new ArgumentNullException("objInfo"); var manager = transaction.GetObjectManager(objInfo.ObjectType); if (manager == null) throw new InvalidOperationException(String.Format("Could not find any manager for object type '{0}' configured for the system.", objInfo.ObjectType)); if (manager.ObjectType != objInfo.ObjectType) throw new ArgumentException( String.Format("Could not create an object of type '{0}' with the manager '{1}' (supported '{2}' type)", objInfo.ObjectType, manager.GetType().FullName, manager.ObjectType)); manager.CreateObject(objInfo); }
internal Db4oReplicationReferenceImpl(IObjectInfo objectInfo) { ObjectReference yo = (ObjectReference)objectInfo; Transaction trans = yo.Transaction(); Db4objects.Db4o.Internal.VirtualAttributes va = yo.VirtualAttributes(trans); if (va != null) { SetVirtualAttributes((Db4objects.Db4o.Internal.VirtualAttributes)va.ShallowClone( )); } else { // No virtu SetVirtualAttributes(new Db4objects.Db4o.Internal.VirtualAttributes()); } object obj = yo.GetObject(); SetObject(obj); Ref_init(); }
public override bool AlterObject(IObjectInfo objectInfo) { if (objectInfo == null) throw new ArgumentNullException("objectInfo"); if (objectInfo.ObjectType == DbObjectType.Cursor || objectInfo.ObjectType == DbObjectType.Variable) { throw new NotSupportedException(); } if (objectInfo.ObjectType == DbObjectType.Table) { return AlterTable((TableInfo) objectInfo); } if (objectInfo.ObjectType == DbObjectType.Trigger && Request.Context.TriggerExists(objectInfo.FullName.Name)) { // TODO: } return base.AlterObject(objectInfo); }
internal Db4oReplicationReferenceImpl(IObjectInfo objectInfo, object obj) { if (obj == null) { throw new InvalidOperationException("obj may not be null"); } _version = objectInfo.GetCommitTimestamp(); ObjectReference @ref = (ObjectReference)objectInfo; Transaction trans = @ref.Transaction(); Db4objects.Db4o.Internal.VirtualAttributes va = @ref.VirtualAttributes(trans); if (va != null) { SetVirtualAttributes((Db4objects.Db4o.Internal.VirtualAttributes)va.ShallowClone( )); } else { SetVirtualAttributes(new Db4objects.Db4o.Internal.VirtualAttributes()); } SetObject(obj); Ref_init(); }
public virtual void Test() { var q = Db().Query(); q.Constrain(typeof (Item)); var objectSet = q.Execute(); var ids = objectSet.Ext().GetIDs(); var infos = new IObjectInfo[ids.Length]; var items = new Item[ids .Length]; for (var i = 0; i < items.Length; i++) { items[i] = (Item) Db().GetByID(ids[i]); infos[i] = new LazyObjectReference(Trans(), (int) ids[i]); } AssertInfosAreConsistent(ids, infos); for (var i = 0; i < items.Length; i++) { Db().Purge(items[i]); } Db().Purge(); AssertInfosAreConsistent(ids, infos); }
/// <summary> /// Binds the order by query option to the sql builder. /// </summary> /// <param name="orderByQueryOption">The order by query.</param> /// <param name="objectInfo">The IObjectInfo for the type to bind the order by list for.</param> /// <param name="orderBySqlBuilder">The order by SQL builder.</param> /// <returns>The SqlBuilder after the order by clause has been added.</returns> public static IOrderBy BindOrderBy(OrderByQueryOption orderByQueryOption, IObjectInfo objectInfo, IOrderBy orderBySqlBuilder) { if (objectInfo == null) { throw new ArgumentNullException("objectInfo"); } if (orderBySqlBuilder == null) { throw new ArgumentNullException("orderBySqlBuilder"); } if (orderByQueryOption != null) { for (int i = 0; i < orderByQueryOption.Properties.Count; i++) { var property = orderByQueryOption.Properties[i]; var column = objectInfo.TableInfo.GetColumnInfoForProperty(property.Name); if (column == null) { throw new ODataException(string.Format(CultureInfo.InvariantCulture, Messages.InvalidPropertyName, objectInfo.ForType.Name, property.Name)); } var columnName = column.ColumnName; if (property.Direction == OrderByDirection.Ascending) { orderBySqlBuilder.OrderByAscending(columnName); } else { orderBySqlBuilder.OrderByDescending(columnName); } } } return orderBySqlBuilder; }
public RuleManager(IObjectInfo objectInfo) { _objectInfo = objectInfo ?? throw new ArgumentNullException(nameof(objectInfo)); }
public RectTransform(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader) : base(objectInfo) { Parse(reader); }
//public AudioClipObject(IObjectInfo<AssetsObject> objectInfo) : base(objectInfo) //{ } public AudioClipObject(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader) : base(objectInfo) { Parse(reader); }
public override SqlQuery BuildSelectInsertIdSqlQuery(IObjectInfo objectInfo) { return(new SqlQuery("SELECT LAST_INSERT_ID()")); }
public WwiseKoreographySet(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader, bool parseLiteral = false) : base(objectInfo, reader, parseLiteral) { }
public MainLevelPackCollectionObject(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader) : base(objectInfo) { Parse(reader); }
public LevelDecoratorBase(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader, bool parseLiteral = false) : base(objectInfo, reader, parseLiteral) { }
/// <summary>Creates a new instance for the specified object.</summary> /// <remarks>Creates a new instance for the specified object.</remarks> public CancellableObjectEventArgs(Transaction transaction, IObjectInfo objectInfo , object obj) : base(transaction, objectInfo) { _object = obj; }
public virtual void ObjectOnInstantiate(Transaction transaction, IObjectInfo obj) { }
public virtual void ObjectOnNew(Transaction transaction, IObjectInfo obj) { }
void IObjectManager.CreateObject(IObjectInfo objInfo) { CreateType((UserTypeInfo)objInfo); }
public GameObject(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader) : base(objectInfo) { Parse(reader); }
public WwiseStateReference(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader, bool parseLiteral = false) : base(objectInfo, reader, parseLiteral) { }
public EnemyActionAimStart(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader, bool parseLiteral = false) : base(objectInfo, reader, parseLiteral) { }
public WhenUsingLowercaseWithUnderscores() { var mappingConvention = new ConventionMappingConvention(ConventionMappingSettings.LowercaseWithUnderscores); this.objectInfo = mappingConvention.CreateObjectInfo(typeof(Customer)); }
public SmartPtr(AssetsObject owner, IObjectInfo <T> target) { Init(owner, target); }
public TrackSection(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader, bool parseLiteral = false) : base(objectInfo, reader, parseLiteral) { }
private void UsefulForCSharp(IObjectInfo info) { Assert.Fail(); }
public TextAsset(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader) : base(objectInfo) { Parse(reader); ParseDetails(reader); }
public GeoSet(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader, bool readLiteral = false) : base(objectInfo, reader, readLiteral) { }
public IgnoredProperties() { var mappingConvention = new ConventionMappingConvention(ConventionMappingSettings.Default); this.objectInfo = mappingConvention.CreateObjectInfo(typeof(Product)); }
public override SqlQuery BuildSelectInsertIdSqlQuery(IObjectInfo objectInfo) => new SqlQuery("SELECT lastval()");
public DecorationSet(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader, bool parseLiteral = false) : base(objectInfo, reader, parseLiteral) { }
public WhenUsingDefaultSettings() { var mappingConvention = new ConventionMappingConvention(ConventionMappingSettings.Default); this.objectInfo = mappingConvention.CreateObjectInfo(typeof(Customer)); }
public GridDecorationSet(IObjectInfo <AssetsObject> oi, AssetsReader reader) { objectinfo = oi; Parse(reader); }
bool IObjectManager.AlterObject(IObjectInfo objInfo) { return(AlterType((UserTypeInfo)objInfo)); }
protected GameObject(IObjectInfo <AssetsObject> objectInfo) : base(objectInfo) { IsActive = true; }
public BaseType(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader, bool parseLiteral = false) : base(objectInfo, reader, parseLiteral) { }
public BeatmapCharacteristicObject(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader) : base(objectInfo) { Parse(reader); }
public static ISmartPtr <T> PtrFrom <T>(this IObjectInfo <T> objectInfo, AssetsObject owner) where T : AssetsObject { return(new SmartPtr <T>(owner, objectInfo)); }
public virtual void ObjectOnDeactivate(Transaction transaction, IObjectInfo obj) { }
protected Component(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader) : base(objectInfo) { Parse(reader); }
public ObjectInfoEventArgs(Transaction transaction, IObjectInfo info) : base(transaction ) { _info = info; }
protected Component(IObjectInfo <AssetsObject> objectInfo) : base(objectInfo) { }
public override SqlQuery BuildSelectInsertIdSqlQuery(IObjectInfo objectInfo) { return new SqlQuery("SELECT LAST_INSERT_ID()"); }
public CullingRange(IObjectInfo <AssetsObject> objectInfo, AssetsReader reader, bool parseLiteral = false) : base(objectInfo, reader, parseLiteral) { }