Package javax.sql.rowset.serial

Examples of javax.sql.rowset.serial.SerialBlob


  public long save(SequencerReference sequencerReference) throws IOException {
    MapSqlParameterSource params = new MapSqlParameterSource();

    Blob ipBlob = null;
    try {
       ipBlob = new SerialBlob(sequencerReference.getIpAddress().getAddress());
    }
    catch (SQLException e) {
      e.printStackTrace();
    }
View Full Code Here


    Blob xmlblob = null;
    try {
      if (status.getXml() != null) {
        byte[] rbytes = status.getXml().getBytes();
        xmlblob = new SerialBlob(rbytes);
        params.addValue("xml", xmlblob);
      }
      else {
        params.addValue("xml", null);
      }
View Full Code Here

      user.setRoles(roles.toArray(new String[user.getRoles().length]));

      try {
        if (user.getRoles().length > 0) {
          byte[] rbytes = LimsUtils.join(user.getRoles(), ",").getBytes();
          roleBlob = new SerialBlob(rbytes);
        }
      }
      catch (SerialException e) {
        e.printStackTrace();
      }
View Full Code Here

    }

    public Image addImage(User owner, byte[] image) {
        try {
            Image im = new Image();
            im.setImage(new SerialBlob(image));
            im.setUser(owner);
            im.setTimestamp(new Date());
            em.persist(im);
            addLinked(owner, im);
            return im;
View Full Code Here

        PreparedStatement pstmt = con.prepareStatement("INSERT INTO testblob(id, lo) VALUES(?,?)");

        byte [] initialData = randomData();
       
        pstmt.setString(1,"testConcurrentReplace");
        pstmt.setObject(2, new SerialBlob(initialData), Types.BLOB);
        assertEquals(1, pstmt.executeUpdate());

        con.commit();
       
        con2.rollback();
       
        // con2 access the blob
        PreparedStatement pstmt2 = con2.prepareStatement("SELECT lo FROM testblob WHERE id=?");
        pstmt2.setString(1, "testConcurrentReplace");
        ResultSet rs2 = pstmt2.executeQuery();
        assertTrue(rs2.next());
       
       
        // con replace the blob
        byte [] newData = randomData();
        pstmt = con.prepareStatement("UPDATE testblob SET lo=? where id=?");
        pstmt.setObject(1, new SerialBlob(newData), Types.BLOB);
        pstmt.setString(2,"testConcurrentReplace");
        assertEquals(1, pstmt.executeUpdate());
       
        // con2 read the blob content
        Blob initContentBlob = rs2.getBlob(1);
View Full Code Here

public class BlobConverter implements TypeConverter<Blob> {

  @Override
  public Blob fromBytes(byte[] t) {
    try {
      return new SerialBlob(t);
    } catch (SerialException e) {
      throw new RuntimeException(e);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
View Full Code Here

            if (type.equals(Array.class) && !(value instanceof SerialArray)) {
                return new SerialArray((Array) value);
            }

            if (type.equals(Blob.class) && !(value instanceof SerialBlob)) {
                return new SerialBlob((Blob) value);
            }

            if (type.equals(Clob.class) && !(value instanceof SerialClob)) {
                return new SerialClob((Clob) value);
            }
View Full Code Here

            throw new SQLException();
        }
        if (params == null) {
            throw new SQLException();
        }
        params.put(Integer.valueOf(parameterIndex - 1), new SerialBlob(x));
    }
View Full Code Here

public class SerialBlobTest extends TestCase {

    public void testConstructorLBlob() throws Exception {
        boolean isAbnormal = false;
        MockSerialBlob mockBlob = new MockSerialBlob(isAbnormal);
        SerialBlob serialBlob = new SerialBlob(mockBlob);
        // SerialBlob constructor initiliases with the data of given blob,
        // therefore, blob.getBytes is invoked.
        assertTrue(mockBlob.isGetBytesInvoked);
        assertEquals(1, serialBlob.length());

        isAbnormal = true;
        mockBlob = new MockSerialBlob(isAbnormal);
        try {
            new SerialBlob(mockBlob);
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }

        try {
            new SerialBlob((Blob) null);
            fail("should throw SQLException");
        } catch (SQLException e) {
            // expected
        }
    }
View Full Code Here

        }
    }

    public void testConstructor$B() throws Exception {
        byte[] buf = new byte[8];
        SerialBlob serialBlob = new SerialBlob(buf);
        assertEquals(8, serialBlob.length());

        try {
            new SerialBlob((byte[]) null);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of javax.sql.rowset.serial.SerialBlob

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.