Esempio n. 1
0
 internal static void Insert( CacheObject obj ) {
     Type t = obj.GetType();
     String _typeFullName = t.FullName;
     IList list = FindAll( t );
     obj.Id = getNextId( list );
     int index = list.Add( obj );
     addIdIndex( _typeFullName, obj.Id, index );
     UpdateObjects( _typeFullName, list );
     makeIndexByInsert( obj );
     if (isInMemory( t )) return;
     Serialize( t );
 }
Esempio n. 2
0
 internal static void Delete( CacheObject obj )
 {
     Type t = obj.GetType();
     String _typeFullName = t.FullName;
     makeIndexByDelete( obj );
     IList list = FindAll( t );
     list.Remove( obj );
     UpdateObjects( _typeFullName, list );
     deleteIdIndex( _typeFullName, obj.Id );
     if (isInMemory( t )) return;
     Serialize( t, list );
 }
Esempio n. 3
0
 private static void makeIndexByUpdate( CacheObject cacheObject, String propertyName, Object pValue )
 {
     Type t = cacheObject.GetType();
     String propertyKey = getPropertyKey( t.FullName, propertyName );
     lock (objIndexLockUpdate) {
         NameValueCollection valueCollection = getValueCollection( propertyKey );
         deleteOldValueIdMap( valueCollection, cacheObject.Id );
         valueCollection.Add( pValue.ToString(), cacheObject.Id.ToString() );
         indexList[propertyKey] = valueCollection;
     }
 }
Esempio n. 4
0
 private static void makeIndexByUpdate( CacheObject cacheObject )
 {
     Type t = cacheObject.GetType();
     PropertyInfo[] properties = getProperties( t );
     foreach (PropertyInfo p in properties) {
         String propertyKey = getPropertyKey( t.FullName, p.Name );
         lock (objIndexLockUpdate) {
             NameValueCollection valueCollection = getValueCollection( propertyKey );
             deleteOldValueIdMap( valueCollection, cacheObject.Id );
             addNewValueMap( valueCollection, cacheObject, p );
         }
     }
 }
Esempio n. 5
0
 private static void addNewValueMap( NameValueCollection valueCollection, CacheObject cacheObject, PropertyInfo p )
 {
     Attribute attr = rft.GetAttribute( p, typeof( NotSaveAttribute ) );
     if (attr != null) return;
     String propertyKey = getPropertyKey( cacheObject.GetType().FullName, p.Name );
     Object pValue = rft.GetPropertyValue( cacheObject, p.Name );
     if (pValue == null || strUtil.IsNullOrEmpty( pValue.ToString() )) return;
     valueCollection.Add( pValue.ToString(), cacheObject.Id.ToString() );
     indexList[propertyKey] = valueCollection;
 }
Esempio n. 6
0
 internal static Result updateByIndex( CacheObject obj, Dictionary<String, Object> dic )
 {
     Type t = obj.GetType();
     makeIndexByUpdate( obj );
     if (isInMemory( t )) return new Result();
     try {
         Serialize( t );
         return new Result();
     }
     catch (Exception ex) {
         throw ex;
     }
 }
Esempio n. 7
0
 internal static Result Update( CacheObject obj )
 {
     Type t = obj.GetType();
     makeIndexByUpdate( obj );
     if (isInMemory( t )) return new Result();
     try {
         Serialize( t );
         return new Result();
     }
     catch (Exception ex) {
         throw ex;
     }
 }
Esempio n. 8
0
 internal static void InsertByIndex( CacheObject obj, Dictionary<String, Object> dic )
 {
     Type t = obj.GetType();
     String _typeFullName = t.FullName;
     IList list = FindAll( t );
     obj.Id = getNextId( list );
     int index = list.Add( obj );
     addIdIndex( _typeFullName, obj.Id, index );
     UpdateObjects( _typeFullName, list );
     foreach (KeyValuePair<String, Object> kv in dic) {
         makeIndexByInsert( obj, kv.Key, kv.Value );
     }
     if (isInMemory( t )) return;
     Serialize( t );
 }
        public bool Extract(ExtractionType et)
        {
            var qry = new StringBuilder("DECLARE @params as XML;");
            qry.Append($"SET @params = '{XmlParameterList()}';");
            qry.Append("WITH params AS (SELECT p.value('.', 'varbinary(64)') as handle FROM @params.nodes('/params/p') n(p)) "); // TODO
            switch (et)
            {
                case ExtractionType.QueryPlans:
                    qry.Append("SELECT params.handle, qp.query_plan FROM params CROSS APPLY sys.dm_exec_query_plan(params.handle) as qp");
                    break;
                case ExtractionType.SqlText:
                    qry.Append("SELECT params.handle, st.text FROM params CROSS APPLY sys.dm_exec_sql_text(params.handle) as st");
                    break;
                default:
                    //throw new InvalidOperationException("Unknown ExtractionType");
                    return false;
                    break;
            }

            try
            {
                if (_cn.State == ConnectionState.Closed) _cn.Open();

                using (var cmd = new SqlCommand(qry.ToString(), _cn))
                {
                    var rd = cmd.ExecuteReader();
                    while (rd.Read())
                    {
                        var co = new CacheObject();

                        switch (et)
                        {
                            case ExtractionType.QueryPlans:
                                co.PlanHandle = rd.GetString(0);
                                co.QueryPlan = rd.GetString(1);
                                break;
                            case ExtractionType.SqlText:
                                co.SqlHandle = rd.GetString(0);
                                co.SqlText = rd.GetString(1);
                                break;
                            default:
                                break;
                        }

                        HandlesList[rd.GetString(0)] = co;
                    }
                    rd.Close();
                }
            }
            catch (SqlException e)
            {
                var msg =
                    $"SQL exception : {e.Number}, {e.Message}";
                SimpleLog.Error(msg);
                return false;
            }
            return true;
        }