private APGenTable[] GetAllTables(APGenBusinessModelSection businessModel)
		{
			APGenTable[] tables = new APGenTable[businessModel.Tables.Count];
			businessModel.Tables.CopyTo(tables, 0);

			return tables;
		}
		/// <summary>
		/// Synchronize database.
		/// </summary>
		/// <param name="businessModel">Business model.</param>
		public override void Sync(APGenBusinessModelSection businessModel)
		{
		   using (APDatabase db = new APDatabase(this))
		   {
		      try
		      {
					db.BeginTrans();

					foreach (APGenTable table in GetAllTables(businessModel))
					{
						_setScanTable(table.TableName);

						DbCommand dbCmd = db.CreateSqlCommand("select table_name from user_tables where temporary = 'N' and table_name = '{0}'", table.TableName.ToUpper());
						object id = dbCmd.ExecuteScalar();
						if (id == null)
							CreateTable(db, table);
						else
							ModifyTable(db, table);
					}


					SyncSequence(db, businessModel);

					db.Commit();
				}
				catch(Exception ex)
				{
					db.Rollback();

					throw new ProviderException(String.Format("Table: {0}, Column: {1}", scanTableName, scanColumnName), ex);
				}
			}
		}
Exemplo n.º 3
0
		//static string currentIdNewIdProc = "ap_Query_NewId";
		private APGenTable[] GetAllTables(APGenBusinessModelSection businessModel)
		{
			// CurrentId table also include in.

			APGenTable tableCurrentId = new APGenTable() { Name = currentIdTable, TableName = currentIdTable };
			tableCurrentId.Columns.Add(new APGenColumn() { Name = currentIdName, ColumnName = currentIdName, PrimaryKey = true, IsNullable = false, DBType = DbType.String, DataLength = 512 });
			tableCurrentId.Columns.Add(new APGenColumn() { Name = currentIdValue, ColumnName = currentIdValue, IsNullable = false, DBType = DbType.Int64 });

			APGenTable[] tables = new APGenTable[businessModel.Tables.Count + 1];
			tables[0] = tableCurrentId;
			businessModel.Tables.CopyTo(tables, 1);

			return tables;
		}
Exemplo n.º 4
0
		/// <summary>
		/// Synchronize database.
		/// </summary>
		/// <param name="businessModel">Business model.</param>
		public override void Sync(APGenBusinessModelSection businessModel)
		{
		   using (APDatabase db = new APDatabase(this))
		   {
		      try
		      {
					db.BeginTrans();


					foreach (APGenTable table in GetAllTables(businessModel))
					{
						_setScanTable(table.TableName);

						DbCommand dbCmd = db.CreateSqlCommand("select id from sysobjects where type = 'U' and name = '{0}'", table.TableName);
						object id = dbCmd.ExecuteScalar();
						if (id == null)
							CreateTable(db, table);
						else
							ModifyTable(db, table);
					}


					SyncCurrentId(db, businessModel);
					//_createCurrentIdProc(db);


					db.Commit();
				}
				catch (Exception ex)
				{
					db.Rollback();

					throw new ProviderException(String.Format("Table: {0}, Column: {1}", scanTableName, scanColumnName), ex);
				}
			}
		}
Exemplo n.º 5
0
		private void SyncCurrentId(APDatabase db, APGenBusinessModelSection businessModel)
		{
			List<string> tcnames = new List<string>();
			DbCommand dbCmd = db.CreateSqlCommand("select {1} from {0}", currentIdTable, currentIdName);
			using (IDataReader reader = dbCmd.ExecuteReader())
			{
				while (reader.Read())
				{
					tcnames.Add(reader.GetString(0));
				}
			}

			foreach (APGenTable table in businessModel.Tables)
			{
				foreach (APGenColumn column in table.Columns)
				{
					if (column.IdentityType == APColumnIdentityType.Provider
						&& businessModel.CanIdentityRelyOnProvider(column)
						&& column.ParsedType != typeof(Guid))
					{
						string tcname = table.TableName + "." + column.ColumnName;
						if (!tcnames.Contains(tcname))
						{
							dbCmd = db.CreateSqlCommand("insert into {0} ({1}, {2}) values ('{3}', '{4}')",
								currentIdTable, currentIdName, currentIdValue,
								tcname, column.ProviderIdentityBase);
							dbCmd.ExecuteNonQuery();
						}
					}
				}
			}
		}
		private void SyncSequence(APDatabase db, APGenBusinessModelSection businessModel)
		{
			List<string> seqnames = new List<string>();
			DbCommand dbCmd = db.CreateSqlCommand("select sequence_name from user_sequences");
			using (IDataReader reader = dbCmd.ExecuteReader())
			{
				while (reader.Read())
				{
					seqnames.Add(reader.GetString(0));
				}
			}

			foreach (APGenTable table in businessModel.Tables)
			{
				foreach (APGenColumn column in table.Columns)
				{
					if (column.IdentityType == APColumnIdentityType.Provider
						&& businessModel.CanIdentityRelyOnProvider(column)
						&& column.ParsedType != typeof(Guid))
					{
						string seqname = SEQ_name(table.TableName, column.ColumnName).ToUpper();
						if (!seqnames.Contains(seqname))
						{
							dbCmd = db.CreateSqlCommand("create sequence {0} increment by 1 start with {1} nomaxvalue nocycle nocache",
								seqname, column.ProviderIdentityBase);
							dbCmd.ExecuteNonQuery();
						}
					}
				}
			}
		}
Exemplo n.º 7
0
		/// <summary>
		/// Synchronize database.
		/// </summary>
		/// <param name="businessModel">Business model.</param>
		public abstract void Sync(APGenBusinessModelSection businessModel);