コード例 #1
0
        private ITypeFieldValueList ExtractCurrentRowValues(IReadOnlyEntity entity, Type type, ITransaction tx)
        {
            ITypeFieldValueList fieldValueList = null;

            ITypeFieldValueList keyFieldValueList = OperationUtils.ExtractEntityTypeKeyValues(entity, type);
            IDbCommand          cmd    = null;
            IDataReader         reader = null;

            try
            {
                cmd    = CreateRetrievalPreparedStatement(keyFieldValueList, tx);
                reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    fieldValueList = ReadValues(type, reader);
                }
            }
            catch (Exception ex)
            {
                string message = String.Format("SQL Exception while trying retrieve current data row from {0}"
                                               , entity.GetType().FullName);
                throw new StatementExecutionException(message, ex);
            }
            finally
            {
                DbMgtUtility.Close(reader);
                DbMgtUtility.Close(cmd);
            }
            return(fieldValueList);
        }
コード例 #2
0
        private Object ExtractCurrentVersionValue(IReadOnlyEntity entity, IColumn versionColumn, Type type
                                                  , ITransaction tx)
        {
            Object versionValue = null;

            ITypeFieldValueList keyFieldValueList = OperationUtils.ExtractEntityTypeKeyValues(entity, type);
            IDbCommand          cmd    = null;
            IDataReader         reader = null;

            try
            {
                cmd    = CreateRetrievalPreparedStatement(keyFieldValueList, tx);
                reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    versionValue = DbLayer.DataManipulate().ReadFromResultSet(reader, versionColumn);
                }
            }
            catch (Exception ex)
            {
                String message = String.Format("SQL Exception while trying retrieve version information from {0}"
                                               , entity.GetType().FullName);
                throw new StatementExecutionException(message, ex);
            }
            finally
            {
                DbMgtUtility.Close(reader);
                DbMgtUtility.Close(cmd);
            }
            return(versionValue);
        }
コード例 #3
0
        private void LoadFromDb(IReadOnlyEntity roEntity, IDataReader reader, ITransaction tx)
        {
            EntityInfo entityInfo = CacheManager.GetEntityInfo(roEntity);

            while (entityInfo != null)
            {
                string tableName = entityInfo.TableInfo.TableName;
                if (entityInfo.EntityType == roEntity.GetType() || tableName == null) //if i==0 that means it's base class and can use existing result set
                {
                    LoadForType(roEntity, entityInfo.EntityType, reader, tx);
                }
                else
                {
                    IDbCommand  superCmd    = null;
                    IDataReader superReader = null;
                    try
                    {
                        ITypeFieldValueList keyValueList = OperationUtils.ExtractEntityTypeKeyValues(roEntity, entityInfo.EntityType);
                        superCmd    = CreateRetrievalPreparedStatement(keyValueList, tx);
                        superReader = superCmd.ExecuteReader();
                        if (superReader.Read())
                        {
                            LoadForType(roEntity, entityInfo.EntityType, superReader, tx);
                        }
                        else
                        {
                            string message =
                                String.Format(
                                    "Super class {0} does not contains a matching record for the base class {1}",
                                    entityInfo.EntityType.FullName, roEntity.GetType().FullName);
                            throw new NoMatchingRecordFoundForSuperClassException(message);
                        }
                    }
                    catch (Exception ex)
                    {
                        String message = String.Format("SQL Exception while trying to read from table {0}", tableName);
                        throw new ReadFromResultSetException(message, ex);
                    }
                    finally
                    {
                        DbMgtUtility.Close(superReader);
                        DbMgtUtility.Close(superCmd);
                    }
                }
                entityInfo = entityInfo.SuperEntityInfo;
            }
        }