示例#1
0
        public override IExternalBlobConnection GetConnection()
        {
            IExternalBlobConnection connectionFrom = _from.GetConnection();
            IExternalBlobConnection connectionTo   = _to.GetConnection();

            return(new MigrationConnection(connectionFrom, connectionTo));
        }
        public override void NullSafeSet(DbCommand cmd, object value, int index, ISessionImplementor session)
        {
            if (value == null)
            {
                ((IDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
            }
            else
            {
                IExternalBlobConnection conn = GetExternalBlobConnection(session);
                IExternalBlobConnection blobconn;
                byte[] payload;
                if (!ExtractLobData(value, out blobconn, out payload) || !conn.Equals(blobconn)) // Skip writing if an equal connection is used
                {
                    using (ExternalBlobWriter writer = conn.OpenWriter())
                    {
                        WriteLobTo(value, writer);
                        payload = writer.Commit();

                        var persistedLob = ((IPersistedLob)value);

                        if (!persistedLob.IsPersisted)
                        {
                            ((IPersistedLob)value).SetPersistedIdentifier(payload, conn);
                        }
                    }
                }
                ((IDataParameter)cmd.Parameters[index]).Value = payload;
            }
        }
示例#3
0
		public ExternalBlob(IExternalBlobConnection connection, byte[] identifier)
		{
			if (connection == null) throw new ArgumentNullException("connection");
			if (identifier == null) throw new ArgumentNullException("identifier");
			this.connection = connection;
			this.identifier = identifier;
		}
 bool IExternalBlobConnection.Equals(IExternalBlobConnection connection)
 {
     if (connection is ExternalBlobDbConnectionWrapper)
     {
         connection = (connection as ExternalBlobDbConnectionWrapper)._externalConnection;
     }
     return(_externalConnection.Equals(connection));
 }
示例#5
0
		public ExternalClob(IExternalBlobConnection connection, byte[] identifier, Encoding encoding)
		{
			if (connection == null) throw new ArgumentNullException("connection");
			if (identifier == null) throw new ArgumentNullException("identifier");
			if (encoding == null) throw new ArgumentNullException("encoding");
			this.connection = connection;
			this.identifier = identifier;
			this.encoding = encoding;
		}
示例#6
0
 public ExternalXlob(IExternalBlobConnection connection, byte[] identifier, IXmlCompressor compression)
 {
     if (connection == null) throw new ArgumentNullException("connection");
     if (identifier == null) throw new ArgumentNullException("identifier");
     if (compression == null) throw new ArgumentNullException("compression");
     _connection = connection;
     _identifier = identifier;
     _compression = compression;
 }
示例#7
0
        public override bool Equals(IExternalBlobConnection connection)
        {
            var c = connection as FileSystemCasConnection;

            if (c == null)
            {
                return(false);
            }
            return(_path.Equals(c._path) && _hashName == c._hashName);
        }
        public override object NullSafeGet(DbDataReader rs, string name, ISessionImplementor session, object owner)
        {
            int index = rs.GetOrdinal(name);

            if (rs.IsDBNull(index))
            {
                return(null);
            }

            IExternalBlobConnection conn = GetExternalBlobConnection(session);

            byte[] payload;

            if (conn.BlobIdentifierLength == Int32.MaxValue)
            {
                var length = (int)rs.GetBytes(index, 0L, null, 0, 0);
                payload = new byte[length];
                // The if here makes MySql happy (See https://nhibernate.jira.com/browse/NH-2096 for details)
                if (length > 0)
                {
                    rs.GetBytes(index, 0L, payload, 0, length);
                }
            }
            else
            {
                payload = new byte[conn.BlobIdentifierLength];

                // The if here makes MySql happy (See https://nhibernate.jira.com/browse/NH-2096 for details)
                if (payload.Length > 0)
                {
                    var i = (int)rs.GetBytes(index, 0, payload, 0, payload.Length);

                    if (i != payload.Length)
                    {
                        if (Logger.IsErrorEnabled())
                        {
                            Logger.Error("Unknown payload (identifier) length. Recieved {0} but expected {1} bytes for owner: {2}", i, payload.Length, owner);
                        }
                        return(null);
                    }
                }
                else
                {
                    if (Logger.IsErrorEnabled())
                    {
                        Logger.Error("Unknown payload (identifier) length. Recieved 0 but expected {0} bytes for owner: {1}", payload.Length, owner);
                    }
                    return(null);
                }
            }

            return(CreateLobInstance(conn, payload));
        }
        public override object Assemble(object cached, ISessionImplementor session, object owner)
        {
            var payload = cached as byte[];

            if (payload == null)
            {
                return(null);
            }
            IExternalBlobConnection conn = GetExternalBlobConnection(session);

            return(CreateLobInstance(conn, payload));
        }
		protected override bool ExtractLobData(object lob, out IExternalBlobConnection connection, out byte[] identifier)
		{
			ExternalClob clob = lob as ExternalClob;
			if (clob == null)
			{
				connection = null;
				identifier = null;
				return false;
			}
			connection = clob.Connection;
			identifier = clob.Identifier;
			return true;
		}
示例#11
0
 public ExternalBlob(IExternalBlobConnection connection, byte[] identifier)
 {
     if (connection == null)
     {
         throw new ArgumentNullException("connection");
     }
     if (identifier == null)
     {
         throw new ArgumentNullException("identifier");
     }
     _connection = connection;
     _identifier = identifier;
 }
示例#12
0
 public ExternalXlob(IExternalBlobConnection connection, byte[] identifier, IXmlCompressor compression)
 {
     if (connection == null)
     {
         throw new ArgumentNullException("connection");
     }
     if (identifier == null)
     {
         throw new ArgumentNullException("identifier");
     }
     if (compression == null)
     {
         throw new ArgumentNullException("compression");
     }
     _connection  = connection;
     _identifier  = identifier;
     _compression = compression;
 }
示例#13
0
 public ExternalClob(IExternalBlobConnection connection, byte[] identifier, Encoding encoding)
 {
     if (connection == null)
     {
         throw new ArgumentNullException("connection");
     }
     if (identifier == null)
     {
         throw new ArgumentNullException("identifier");
     }
     if (encoding == null)
     {
         throw new ArgumentNullException("encoding");
     }
     _connection = connection;
     _identifier = identifier;
     _encoding   = encoding;
 }
        public override object Disassemble(object value, ISessionImplementor session, object owner)
        {
            if (value == null)
            {
                return(null);
            }

            IExternalBlobConnection blobconn;

            byte[] payload;
            bool   hasExternalLob = ExtractLobData(value, out blobconn, out payload);

            IExternalBlobConnection conn = GetExternalBlobConnection(session);

            if (conn.DisassembleRequiresExternalBlob && !hasExternalLob)
            {
                throw new Exception("Unable to cache an unsaved lob.");
            }

            return(payload);
        }
示例#15
0
        protected override bool ExtractLobData(object lob, out IExternalBlobConnection connection, out byte[] identifier)
        {
            var blob = lob as ExternalBlob;
            if (blob == null)
            {
                var persistedLob = lob as IPersistedLob;

                if (persistedLob != null && persistedLob.IsPersisted)
                {
                    identifier = persistedLob.GetPersistedIdentifier();
                    connection = (IExternalBlobConnection) persistedLob.GetExternalStore();
                    return true;
                }

                connection = null;
                identifier = null;
                return false;
            }
            connection = blob.Connection;
            identifier = blob.Identifier;
            return true;
        }
示例#16
0
        protected override bool ExtractLobData(object lob, out IExternalBlobConnection connection, out byte[] identifier)
        {
            var xlob = lob as ExternalXlob;

            if (xlob == null)
            {
                var persistedLob = lob as IPersistedLob;

                if (persistedLob != null && persistedLob.IsPersisted)
                {
                    identifier = persistedLob.GetPersistedIdentifier();
                    connection = (IExternalBlobConnection)persistedLob.GetExternalStore();
                    return(true);
                }

                connection = null;
                identifier = null;
                return(false);
            }
            connection = xlob.Connection;
            identifier = xlob.Identifier;
            return(true);
        }
 public bool Equals(IExternalBlobConnection connection)
 {
     return(_from.Equals(connection));
 }
 public MigrationConnection(IExternalBlobConnection from, IExternalBlobConnection to)
 {
     _from = from;
     _to   = to;
 }
示例#19
0
		public ExternalClob(IExternalBlobConnection connection, byte[] identifier, Encoding encoding, IStreamCompressor compression) : this(connection, identifier, encoding)
		{
			this.compression = compression;
		}
示例#20
0
 protected override object CreateLobInstance(IExternalBlobConnection connection, byte[] payload)
 {
     return(new ExternalXlob(connection, payload, _compression));
 }
示例#21
0
 protected abstract object CreateLobInstance(IExternalBlobConnection connection, byte[] payload);
示例#22
0
 public override bool Equals(IExternalBlobConnection connection)
 {
     var c = connection as FileSystemCasConnection;
     if (c == null) return false;
     return _path.Equals(c._path) && _hashName == c._hashName;
 }
 public ExternalBlobDbConnectionWrapper(DbConnection db, IExternalBlobConnection externalConnection)
 {
     _db = db;
     _externalConnection = externalConnection;
 }
		protected override object CreateLobInstance(IExternalBlobConnection connection, byte[] identifier)
		{
			return new ExternalClob(connection, identifier, encoding, compression);
		}
示例#25
0
 public abstract bool Equals(IExternalBlobConnection connection);
示例#26
0
 public bool Equals(IExternalBlobConnection connection)
 {
     return _from.Equals(connection);
 }
示例#27
0
 protected override object CreateLobInstance(IExternalBlobConnection connection, byte[] payload)
 {
     return new ExternalBlob(connection, payload, _compression);
 }
		protected abstract object CreateLobInstance(IExternalBlobConnection connection, byte[] identifier);
 public ExternalBlobDbConnectionWrapper(IDbConnection db, IExternalBlobConnection externalConnection)
 {
     _db = db;
     _externalConnection = externalConnection;
 }
示例#30
0
 public override bool Equals(IExternalBlobConnection connection)
 {
     return connection is ByteArrayConnection;
 }
示例#31
0
 public ExternalBlob(IExternalBlobConnection connection, byte[] identifier, IStreamCompressor compression)
     : this(connection, identifier)
 {
     _compression = compression;
 }
		public ExternalBlobDbConnectionWrapper(IDbConnection db, IExternalBlobConnection cas)
		{
			_db = db;
			_cas = cas;
		}
		public abstract bool Equals(IExternalBlobConnection connection);
		bool IExternalBlobConnection.Equals(IExternalBlobConnection connection)
		{
			if (connection is ExternalBlobDbConnectionWrapper) connection = (connection as ExternalBlobDbConnectionWrapper)._cas;
			return _cas.Equals(connection);
		}
示例#35
0
 public override bool Equals(IExternalBlobConnection connection)
 {
     return(connection is ByteArrayConnection);
 }
示例#36
0
 public ExternalBlob(IExternalBlobConnection connection, byte[] identifier, IStreamCompressor compression) : this(connection, identifier)
 {
     _compression = compression;
 }
		protected abstract bool ExtractLobData(object lob, out IExternalBlobConnection connection, out byte[] identifier);
 protected abstract object CreateLobInstance(IExternalBlobConnection connection, byte[] payload);
 protected abstract bool ExtractLobData(object lob, out IExternalBlobConnection connection, out byte[] identifier);
示例#40
0
 public MigrationConnection(IExternalBlobConnection from, IExternalBlobConnection to)
 {
     _from = from;
     _to = to;
 }