ack)
监听事件处理方法RemovedCallback负责处理数据库触发器的通知,其定义如下。若缓存项失效,可用数据库方法调用getRecordFromdatabase()从数据库取出数据。参数”key”指从缓存中删除的项的索引位置。参数”value”指从缓存中删除的数据对象。参数"CacheItemRemovedReason"指从缓存中删除数据项的原因。
PublicSub RemovedCallback(ByVal key AsString, ByVal value AsObject, ByVal reason As CacheItemRemovedReason)
Dim Source As DataView
Source = getRecordFromdatabase()
Cache.Insert("employeeTable ", Source, New
System.Web.Caching.CacheDependency("d:\download\tblemployee.txt"),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.Normal, onRemove)
EndSub
方法getRecordFromdatabase()负责查询数据库表Employee并返回一个DataView对象引用。它使用一个名为getEmployee的存储过程来抽象从Employee表中取数据的SQL。这个方法有一个名为p_empid的参数,表示Employee的主键。
PublicFunction getRecordFromdatabase (ByVal p_empid As Int32) As DataView
Dim con As OracleConnection = Nothing
Dim cmd As OracleCommand = Nothing
Dim ds As DataSet = Nothing
Try
con = getDatabaseConnection( "UserId=scott;Password=tiger;Data Source=testingdb;")
cmd = New OracleCommand("Administrator.getEmployee", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New OracleParameter("employeeId", OracleDbType.Int64)).Value = p_empid
Dim param AsNew OracleParameter("RC1", OracleDbType.RefCursor)
cmd.Parameters.Add(param).Direction = ParameterDirection.Output
Dim myCommand AsNew OracleDataAdapter(cmd)
ds = New DataSet
myCommand.Fill(ds)
Dim table As DataTable = ds.Tables(0)
Dim index As Int32 = table.Rows.Count
Return ds.Tables(0).DefaultView
Catch ex As Exception
ThrowNew Exception("Exception in Database Tier Method getRecordFromdatabase () " + ex.Message, ex)
Finally
Try
cmd.Dispose()
Catch ex As Exception
Finally
cmd = Nothing
EndTry
Try
con.Close()
Catch ex As Exception
Finally
con = Nothing
EndTry
EndTry
EndFunction
函数getDatabaseConnection接受一个连接字符串(connection stirng)为参数,返回一个OracleConnection对象引用。
PublicFunction getDatabaseConnection(ByVal strconnection as string) As OracleConnection
Dim con As Oracle.DataAccess.Client.OracleConnection = Nothing
Try
con = New Oracle.DataAccess.Client.OracleConnection
con.ConnectionString = strconnection
con.Open()
Return con
Catch ex As Exception
ThrowNew Exception("Exception in Database Tier Method getOracleConnection() " + ex.Message, ex)
EndTry
EndFunction
Oracle数据库Tier实现
定义Employee表上DML事件的触发器体如下。这个触发器简单的调用一个PL/SQL包裹函数来更新名为tblemployee.txt的操作系统文件。文件副本在两台机器(机器1和机器2)上更新。两台机器运行同一个Web应用的不同实例来均衡负载。这里administrator指Oracle数据库的方案(schema)对象所有者。
begin
administrator.plfile(''machine1\\download\\ tblemplo