@Override public Blob createBlob(byte[] bytes) { return BlobProxy.generateProxy( bytes ); }
@Override public Blob createBlob(InputStream stream, long length) { return BlobProxy.generateProxy( stream, length ); }
@Override public Blob fromString(String string) { return BlobProxy.generateProxy( PrimitiveByteArrayTypeDescriptor.INSTANCE.fromString( string ) ); }
@Test @TestForIssue( jiraKey = "HHH-8193" ) public void testStreamResetOnAccess() throws IOException, SQLException { byte[] bytes = new byte[] { 1, 2, 3, 4 }; BlobImplementer blob = (BlobImplementer) BlobProxy.generateProxy( bytes ); int value = blob.getUnderlyingStream().getInputStream().read(); // Call to BlobImplementer#getUnderlyingStream() should mark input stream for reset. assertEquals( bytes.length, blob.getUnderlyingStream().getInputStream().available() ); } }
@Test public void test() { Integer productId = doInJPA( this::entityManagerFactory, entityManager -> { Session session = entityManager.unwrap( Session.class ); //tag::basic-blob-persist-example[] byte[] image = new byte[] {1, 2, 3}; final Product product = new Product(); product.setId( 1 ); product.setName( "Mobile phone" ); product.setImage( BlobProxy.generateProxy( image ) ); entityManager.persist( product ); //end::basic-blob-persist-example[] return product.getId(); } ); doInJPA( this::entityManagerFactory, entityManager -> { try { //tag::basic-blob-find-example[] Product product = entityManager.find( Product.class, productId ); try (InputStream inputStream = product.getImage().getBinaryStream()) { assertArrayEquals(new byte[] {1, 2, 3}, toBytes( inputStream ) ); } //end::basic-blob-find-example[] } catch (Exception e) { fail( e.getMessage() ); } } ); }
/** * {@inheritDoc} */ public Blob createBlob(byte[] bytes) { return BlobProxy.generateProxy( bytes ); }
/** * {@inheritDoc} */ public Blob createBlob(InputStream stream, long length) { return BlobProxy.generateProxy( stream, length ); }
/** * {@inheritDoc} */ public Blob createBlob(byte[] bytes) { return BlobProxy.generateProxy( bytes ); }
@Override public Blob createBlob(byte[] bytes) { return BlobProxy.generateProxy( bytes ); }
/** * {@inheritDoc} */ public Blob createBlob(InputStream stream, long length) { return BlobProxy.generateProxy( stream, length ); }
@Override public Blob createBlob(InputStream stream, long length) { return BlobProxy.generateProxy( stream, length ); }
/** * {@inheritDoc} */ public Blob fromString(String string) { return BlobProxy.generateProxy( PrimitiveByteArrayTypeDescriptor.INSTANCE.fromString( string ) ); }
/** * {@inheritDoc} */ public Blob fromString(String string) { return BlobProxy.generateProxy( PrimitiveByteArrayTypeDescriptor.INSTANCE.fromString( string ) ); }
@Override public Blob fromString(String string) { return BlobProxy.generateProxy( PrimitiveByteArrayJavaDescriptor.INSTANCE.fromString( string ) ); }