Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package net.java.ao.types;
 
 
import static java.sql.Types.LONGVARBINARY;
import static java.sql.Types.VARBINARY;
import static java.sql.Types.BINARY;
import static java.sql.Types.BLOB;
final class BlobType extends AbstractLogicalType<Object>
    public BlobType()
    {
        super("Blob",
              new Class<?>[] { byte[].classInputStream.class },
              new Integer[] {  });
    }
    
    @Override
    public void putToDatabase(EntityManager managerPreparedStatement stmtint indexObject valueint jdbcTypethrows SQLException
    {        
        final InputStream is;
        if (value instanceof byte[])
        {
            is = new ByteArrayInputStream((byte[]) value);
        }
        else if (value instanceof InputStream)
        {
            is = (InputStreamvalue;
        }
        else
        {
            throw new IllegalArgumentException("BLOB value must be of type byte[] or InputStream");
        }
        try
        {
            stmt.setBinaryStream(indexisis.available());
        }
        catch (IOException e)
        {
            throw new SQLException(e.getMessage(), e);
        }
    }
    @Override
    public Object pullFromDatabase(EntityManager managerResultSet resClass<ObjecttypeString columnName)
        throws SQLException
    {
        return manager.getProvider().handleBlob(restypecolumnName);
    }
    
    @Override
    public boolean shouldCache(Class<?> type)
    {
        return !InputStream.class.isAssignableFrom(type) && super.shouldCache(type);
    }
    @Override
    public String valueToString(Object value)
    {
        throw new ActiveObjectsException("Cannot convert BLOB value to string");
    }
New to GrepCode? Check out our FAQ X