Java Code Examples for java.sql.PreparedStatement.setBinaryStream()

The following are Jave code examples for showing how to use setBinaryStream() of the java.sql.PreparedStatement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: asura   File: PointbaseDelegate.java   View Source Code Vote up 6 votes
/**
 * <p>
 * Update a calendar.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param calendarName
 *          the name for the new calendar
 * @param calendar
 *          the calendar
 * @return the number of rows updated
 * @throws IOException
 *           if there were problems serializing the calendar
 */
public int updateCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    //log.debug( "Updating calendar " + calendarName + " : " + calendar );
    ByteArrayOutputStream baos = serializeObject(calendar);
    byte buf[] = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(UPDATE_CALENDAR));
        ps.setBinaryStream(1, bais, buf.length);
        ps.setString(2, calendarName);

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
 
Example 2
Project: alfresco-core   File: SerializableTypeHandler.java   View Source Code Vote up 6 votes
public void setParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException
{
    if (parameter == null)
    {
        ps.setNull(i, SerializableTypeHandler.serializableType);
    }
    else
    {
        try
        {
            ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(parameter);
            byte[] bytes = baos.toByteArray();
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            ps.setBinaryStream(i, bais, bytes.length);
        }
        catch (Throwable e)
        {
            throw new SerializationException(e);
        }
    }
}
 
Example 3
Project: jaffa-framework   File: TypeDefs.java   View Source Code Vote up 6 votes
/** Sets a parameter in the PreparedStatement.
 * @param engineType The engine type as defined in init.xml
 * @param pstmt The PreparedStatement.
 * @param parameterIndex The index of the parameter that is to be set.
 * @param value The object to be assigned to the parameter.
 * @throws SQLException if a database access error occurs.
 */
public void setAppObject(PreparedStatement pstmt, int parameterIndex, Object value, String engineType)
throws SQLException {
    if (value != null) {
        if (!(value instanceof byte[]))
            value = DataTypeMapper.instance().map(value, byte[].class);
        if ("oracle".equalsIgnoreCase(engineType) && !supportsStdLob(pstmt)) {
            Blob blob = createBlob(pstmt.getConnection(), (byte[]) value);
            pstmt.setBlob(parameterIndex, blob);
        } else {
            byte[] bytes = (byte[]) value;
            InputStream stream = new BufferedInputStream(new ByteArrayInputStream(bytes));
            pstmt.setBinaryStream(parameterIndex, stream, bytes.length);
        }
    } else
        pstmt.setNull(parameterIndex, getSqlType(Defaults.BLOB, engineType));
}
 
Example 4
Project: lams   File: PointbaseDelegate.java   View Source Code Vote up 6 votes
/**
 * <p>
 * Update the job data map for the given job.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param job
 *          the job to update
 * @return the number of rows updated
 */
@Override           
public int updateJobData(Connection conn, JobDetail job)
    throws IOException, SQLException {
    //log.debug( "Updating Job Data for Job " + job );
    ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());
    int len = baos.toByteArray().length;
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(UPDATE_JOB_DATA));
        ps.setBinaryStream(1, bais, len);
        ps.setString(2, job.getKey().getName());
        ps.setString(3, job.getKey().getGroup());

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
 
Example 5
Project: lams   File: PointbaseDelegate.java   View Source Code Vote up 6 votes
/**
 * <p>
 * Insert a new calendar.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param calendarName
 *          the name for the new calendar
 * @param calendar
 *          the calendar
 * @return the number of rows inserted
 * @throws IOException
 *           if there were problems serializing the calendar
 */
@Override           
public int insertCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    //log.debug( "Inserting Calendar " + calendarName + " : " + calendar
    // );
    ByteArrayOutputStream baos = serializeObject(calendar);
    byte buf[] = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(INSERT_CALENDAR));
        ps.setString(1, calendarName);
        ps.setBinaryStream(2, bais, buf.length);

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
 
Example 6
Project: lams   File: PointbaseDelegate.java   View Source Code Vote up 6 votes
/**
 * <p>
 * Update a calendar.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param calendarName
 *          the name for the new calendar
 * @param calendar
 *          the calendar
 * @return the number of rows updated
 * @throws IOException
 *           if there were problems serializing the calendar
 */
@Override           
public int updateCalendar(Connection conn, String calendarName,
        Calendar calendar) throws IOException, SQLException {
    //log.debug( "Updating calendar " + calendarName + " : " + calendar );
    ByteArrayOutputStream baos = serializeObject(calendar);
    byte buf[] = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    PreparedStatement ps = null;

    try {
        ps = conn.prepareStatement(rtp(UPDATE_CALENDAR));
        ps.setBinaryStream(1, bais, buf.length);
        ps.setString(2, calendarName);

        return ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }
}
 
Example 7
Project: lams   File: ByteArrayBlobType.java   View Source Code Vote up 6 votes
protected void set(PreparedStatement st, Object value, int index, SessionImplementor session) throws SQLException {
	if ( value == null ) {
		st.setNull( index, sqlTypes( null )[0] );
	}
	else {
		byte[] toSet = unWrap( value );
		final boolean useInputStream = session.getFactory().getDialect().useInputStreamToInsertBlob();

		if ( useInputStream ) {
			st.setBinaryStream( index, new ByteArrayInputStream( toSet ), toSet.length );
		}
		else {
			st.setBlob( index, Hibernate.getLobCreator( session ).createBlob( toSet ) );
		}
	}
}
 
Example 8
Project: the-vigilantes   File: PooledConnectionRegressionTest.java   View Source Code Vote up 5 votes
/**
 * Tests that PacketTooLargeException doesn't clober the connection.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testPacketTooLargeException() throws Exception {
    final ConnectionEventListener conListener = new ConnectionListener();
    PooledConnection pc = null;

    pc = this.cpds.getPooledConnection();

    pc.addConnectionEventListener(conListener);

    createTable("testPacketTooLarge", "(field1 LONGBLOB)");

    Connection connFromPool = pc.getConnection();
    PreparedStatement pstmtFromPool = ((ConnectionWrapper) connFromPool).clientPrepare("INSERT INTO testPacketTooLarge VALUES (?)");

    this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'max_allowed_packet'");
    this.rs.next();

    int maxAllowedPacket = this.rs.getInt(2);

    int numChars = (int) (maxAllowedPacket * 1.2);

    pstmtFromPool.setBinaryStream(1, new BufferedInputStream(new FileInputStream(newTempBinaryFile("testPacketTooLargeException", numChars))), numChars);

    try {
        pstmtFromPool.executeUpdate();
        fail("Expecting PacketTooLargeException");
    } catch (PacketTooBigException ptbe) {
        // We're expecting this one...
    }

    // This should still work okay, even though the last query on the same connection didn't...
    this.rs = connFromPool.createStatement().executeQuery("SELECT 1");

    assertTrue(this.connectionErrorEventCount == 0);
    assertTrue(this.closeEventCount == 0);
}
 
Example 9
Project: jaffa-framework   File: FormDataWrapper.java   View Source Code Vote up 5 votes
private void addFormTemplates(Connection connection)
throws Exception {
    //1=FORM_ID, TEMPLATE_DATA, LAYOUT_DATA
    String sql = "insert into J_FORM_TEMPLATES values (?,?,?)";
    PreparedStatement pstmnt = connection.prepareStatement(sql);
    
    // Create first record 
    pstmnt.setLong(1, 1000000);
    URL u = URLHelper.newExtendedURL(PDF_TEMPLATE);
    InputStream is = u.openStream();
    pstmnt.setBinaryStream(2,is,is.available());
    u = URLHelper.newExtendedURL(PDF_TEMPLATE+".csv");
    is = u.openStream();
    pstmnt.setBinaryStream(3,is,is.available());
    pstmnt.execute();
    pstmnt.clearParameters();

    // Create second record 
    pstmnt.setLong(1, 1000001);
    u = URLHelper.newExtendedURL(VELOCITY_TEMPLATE);
    is = u.openStream();
    pstmnt.setBinaryStream(2,is,is.available());
    pstmnt.setObject(3,null);
    pstmnt.execute();
    pstmnt.clearParameters();

    // Create third record 
    pstmnt.setLong(1, 1000002);
    u = URLHelper.newExtendedURL(PDF_TEMPLATE3);
    is = u.openStream();
    pstmnt.setBinaryStream(2,is,is.available());
    u = URLHelper.newExtendedURL(PDF_TEMPLATE3+".csv");
    is = u.openStream();
    pstmnt.setBinaryStream(3,is,is.available());
    pstmnt.execute();
    pstmnt.clearParameters();

    pstmnt.close();
}
 
Example 10
Project: lams   File: DefaultLobHandler.java   View Source Code Vote up 5 votes
@Override
public void setBlobAsBinaryStream(
		PreparedStatement ps, int paramIndex, InputStream binaryStream, int contentLength)
		throws SQLException {

	if (streamAsLob) {
		if (binaryStream != null) {
			ps.setBlob(paramIndex, binaryStream, contentLength);
		}
		else {
			ps.setBlob(paramIndex, (Blob) null);
		}
	}
	else if (wrapAsLob) {
		if (binaryStream != null) {
			ps.setBlob(paramIndex, new PassThroughBlob(binaryStream, contentLength));
		}
		else {
			ps.setBlob(paramIndex, (Blob) null);
		}
	}
	else {
		ps.setBinaryStream(paramIndex, binaryStream, contentLength);
	}
	if (logger.isDebugEnabled()) {
		logger.debug(binaryStream != null ? "Set binary stream for BLOB with length " + contentLength :
				"Set BLOB to null");
	}
}
 
Example 11
Project: jaffa-framework   File: TypeDefs.java   View Source Code Vote up 5 votes
/** Sets a parameter in the PreparedStatement.
 * @param engineType The engine type as defined in init.xml
 * @param pstmt The PreparedStatement.
 * @param parameterIndex The index of the parameter that is to be set.
 * @param value The object to be assigned to the parameter.
 * @throws SQLException if a database access error occurs.
 */
public void setAppObject(PreparedStatement pstmt, int parameterIndex, Object value, String engineType)
throws SQLException {
    if (value != null) {
        if (!(value instanceof byte[]))
            value = DataTypeMapper.instance().map(value, byte[].class);
        byte[] bytes = (byte[]) value;
        InputStream stream = new BufferedInputStream(new ByteArrayInputStream(bytes));
        pstmt.setBinaryStream(parameterIndex, stream, bytes.length);
    } else
        pstmt.setNull(parameterIndex, getSqlType(Defaults.LONG_RAW, engineType));
}
 
Example 12
Project: lams   File: BlobTypeDescriptor.java   View Source Code Vote up 5 votes
@Override
public <X> BasicBinder<X> getBlobBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
	return new BasicBinder<X>( javaTypeDescriptor, this ) {
		@Override
		protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
				throws SQLException {
			final BinaryStream binaryStream = javaTypeDescriptor.unwrap(
					value,
					BinaryStream.class,
					options
			);
			st.setBinaryStream( index, binaryStream.getInputStream(), binaryStream.getLength() );
		}
	};
}
 
Example 13
Project: lams   File: AbstractBynaryType.java   View Source Code Vote up 5 votes
public void set(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
	byte[] internalValue = toInternalFormat( value );
	if ( Environment.useStreamsForBinary() ) {
		st.setBinaryStream( index, new ByteArrayInputStream( internalValue ), internalValue.length );
	}
	else {
		st.setBytes( index, internalValue );
	}
}
 
Example 14
Project: BibliotecaPS   File: PooledConnectionRegressionTest.java   View Source Code Vote up 5 votes
/**
 * Tests that PacketTooLargeException doesn't clober the connection.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testPacketTooLargeException() throws Exception {
    final ConnectionEventListener conListener = new ConnectionListener();
    PooledConnection pc = null;

    pc = this.cpds.getPooledConnection();

    pc.addConnectionEventListener(conListener);

    createTable("testPacketTooLarge", "(field1 LONGBLOB)");

    Connection connFromPool = pc.getConnection();
    PreparedStatement pstmtFromPool = ((ConnectionWrapper) connFromPool).clientPrepare("INSERT INTO testPacketTooLarge VALUES (?)");

    this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'max_allowed_packet'");
    this.rs.next();

    int maxAllowedPacket = this.rs.getInt(2);

    int numChars = (int) (maxAllowedPacket * 1.2);

    pstmtFromPool.setBinaryStream(1, new BufferedInputStream(new FileInputStream(newTempBinaryFile("testPacketTooLargeException", numChars))), numChars);

    try {
        pstmtFromPool.executeUpdate();
        fail("Expecting PacketTooLargeException");
    } catch (PacketTooBigException ptbe) {
        // We're expecting this one...
    }

    // This should still work okay, even though the last query on the same connection didn't...
    this.rs = connFromPool.createStatement().executeQuery("SELECT 1");

    assertTrue(this.connectionErrorEventCount == 0);
    assertTrue(this.closeEventCount == 0);
}
 
Example 15
Project: unitimes   File: XmlBlobType.java   View Source Code Vote up 5 votes
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
    if (value == null) {
        ps.setNull(index, sqlTypes()[0]);
    } else {
        try {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(new GZIPOutputStream(bytes),OutputFormat.createCompactFormat());
            writer.write((Document)value);
            writer.flush(); writer.close();
            ps.setBinaryStream(index, new ByteArrayInputStream(bytes.toByteArray(),0,bytes.size()), bytes.size());
        } catch (IOException e) {
            throw new HibernateException(e.getMessage(),e);
        }
    }
}
 
Example 16
Project: asura   File: PointbaseDelegate.java   View Source Code Vote up 5 votes
/**
 * <p>
 * Insert the job detail record.
 * </p>
 * 
 * @param conn
 *          the DB Connection
 * @param job
 *          the job to insert
 * @return number of rows inserted
 * @throws IOException
 *           if there were problems serializing the JobDataMap
 */
public int insertJobDetail(Connection conn, JobDetail job)
    throws IOException, SQLException {
    //log.debug( "Inserting JobDetail " + job );
    ByteArrayOutputStream baos = serializeJobData(job.getJobDataMap());
    int len = baos.toByteArray().length;
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());

    PreparedStatement ps = null;

    int insertResult = 0;

    try {
        ps = conn.prepareStatement(rtp(INSERT_JOB_DETAIL));
        ps.setString(1, job.getName());
        ps.setString(2, job.getGroup());
        ps.setString(3, job.getDescription());
        ps.setString(4, job.getJobClass().getName());
        setBoolean(ps, 5, job.isDurable());
        setBoolean(ps, 6, job.isVolatile());
        setBoolean(ps, 7, job.isStateful());
        setBoolean(ps, 8, job.requestsRecovery());
        ps.setBinaryStream(9, bais, len);

        insertResult = ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }

    if (insertResult > 0) {
        String[] jobListeners = job.getJobListenerNames();
        for (int i = 0; jobListeners != null && i < jobListeners.length; i++) {
            insertJobListener(conn, job, jobListeners[i]);
        }
    }

    return insertResult;
}
 
Example 17
Project: asura   File: PointbaseDelegate.java   View Source Code Vote up 5 votes
public int updateTrigger(Connection conn, Trigger trigger, String state,
        JobDetail jobDetail) throws SQLException, IOException {

    ByteArrayOutputStream baos = serializeJobData(trigger.getJobDataMap());
    int len = baos.toByteArray().length;
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            
    PreparedStatement ps = null;

    int insertResult = 0;


    try {
        ps = conn.prepareStatement(rtp(UPDATE_TRIGGER));
            
        ps.setString(1, trigger.getJobName());
        ps.setString(2, trigger.getJobGroup());
        setBoolean(ps, 3, trigger.isVolatile());
        ps.setString(4, trigger.getDescription());
        long nextFireTime = -1;
        if (trigger.getNextFireTime() != null) {
            nextFireTime = trigger.getNextFireTime().getTime();
        }
        ps.setBigDecimal(5, new BigDecimal(String.valueOf(nextFireTime)));
        long prevFireTime = -1;
        if (trigger.getPreviousFireTime() != null) {
            prevFireTime = trigger.getPreviousFireTime().getTime();
        }
        ps.setBigDecimal(6, new BigDecimal(String.valueOf(prevFireTime)));
        ps.setString(7, state);
        if (trigger instanceof SimpleTrigger && ((SimpleTrigger)trigger).hasAdditionalProperties() == false ) {
            //                updateSimpleTrigger(conn, (SimpleTrigger)trigger);
            ps.setString(8, TTYPE_SIMPLE);
        } else if (trigger instanceof CronTrigger && ((CronTrigger)trigger).hasAdditionalProperties() == false ) {
            //                updateCronTrigger(conn, (CronTrigger)trigger);
            ps.setString(8, TTYPE_CRON);
        } else {
            //                updateBlobTrigger(conn, trigger);
            ps.setString(8, TTYPE_BLOB);
        }
        ps.setBigDecimal(9, new BigDecimal(String.valueOf(trigger
                .getStartTime().getTime())));
        long endTime = 0;
        if (trigger.getEndTime() != null) {
            endTime = trigger.getEndTime().getTime();
        }
        ps.setBigDecimal(10, new BigDecimal(String.valueOf(endTime)));
        ps.setString(11, trigger.getCalendarName());
        ps.setInt(12, trigger.getMisfireInstruction());
        
        ps.setInt(13, trigger.getPriority());
        ps.setBinaryStream(14, bais, len);
        ps.setString(15, trigger.getName());
        ps.setString(16, trigger.getGroup());

        insertResult = ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }

    if (insertResult > 0) {
        deleteTriggerListeners(conn, trigger.getName(), trigger.getGroup());

        String[] trigListeners = trigger.getTriggerListenerNames();
        for (int i = 0; trigListeners != null && i < trigListeners.length; i++) {
            insertTriggerListener(conn, trigger, trigListeners[i]);
        }
    }

    return insertResult;
}
 
Example 18
Project: asura   File: PointbaseDelegate.java   View Source Code Vote up 5 votes
public int insertTrigger(Connection conn, Trigger trigger, String state,
        JobDetail jobDetail) throws SQLException, IOException {

    ByteArrayOutputStream baos = serializeJobData(trigger.getJobDataMap());
    int len = baos.toByteArray().length;
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    
    PreparedStatement ps = null;

    int insertResult = 0;

    try {
        ps = conn.prepareStatement(rtp(INSERT_TRIGGER));
        ps.setString(1, trigger.getName());
        ps.setString(2, trigger.getGroup());
        ps.setString(3, trigger.getJobName());
        ps.setString(4, trigger.getJobGroup());
        setBoolean(ps, 5, trigger.isVolatile());
        ps.setString(6, trigger.getDescription());
        ps.setBigDecimal(7, new BigDecimal(String.valueOf(trigger
                .getNextFireTime().getTime())));
        long prevFireTime = -1;
        if (trigger.getPreviousFireTime() != null) {
            prevFireTime = trigger.getPreviousFireTime().getTime();
        }
        ps.setBigDecimal(8, new BigDecimal(String.valueOf(prevFireTime)));
        ps.setString(9, state);
        if (trigger instanceof SimpleTrigger && ((SimpleTrigger)trigger).hasAdditionalProperties() == false ) {
            ps.setString(10, TTYPE_SIMPLE);
        } else if (trigger instanceof CronTrigger && ((CronTrigger)trigger).hasAdditionalProperties() == false ) {
            ps.setString(10, TTYPE_CRON);
        } else {
            ps.setString(10, TTYPE_BLOB);
        }
        ps.setBigDecimal(11, new BigDecimal(String.valueOf(trigger
                .getStartTime().getTime())));
        long endTime = 0;
        if (trigger.getEndTime() != null) {
            endTime = trigger.getEndTime().getTime();
        }
        ps.setBigDecimal(12, new BigDecimal(String.valueOf(endTime)));
        ps.setString(13, trigger.getCalendarName());
        ps.setInt(14, trigger.getMisfireInstruction());
        ps.setBinaryStream(15, bais, len);
        ps.setInt(16, trigger.getPriority());
        
        insertResult = ps.executeUpdate();
    } finally {
        closeStatement(ps);
    }

    if (insertResult > 0) {
        String[] trigListeners = trigger.getTriggerListenerNames();
        for (int i = 0; trigListeners != null && i < trigListeners.length; i++) {
            insertTriggerListener(conn, trigger, trigListeners[i]);
        }
    }

    return insertResult;
}
 
Example 19
Project: lams   File: PointbaseDelegate.java   View Source Code Vote up 4 votes
@Override
public int insertTrigger(Connection conn, OperableTrigger trigger, String state,
        JobDetail jobDetail) throws SQLException, IOException {

    ByteArrayOutputStream baos = serializeJobData(trigger.getJobDataMap());
    int len = baos.toByteArray().length;
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    
    PreparedStatement ps = null;

    int insertResult = 0;

    try {
        ps = conn.prepareStatement(rtp(INSERT_TRIGGER));
        ps.setString(1, trigger.getKey().getName());
        ps.setString(2, trigger.getKey().getGroup());
        ps.setString(3, trigger.getJobKey().getName());
        ps.setString(4, trigger.getJobKey().getGroup());
        ps.setString(5, trigger.getDescription());
        ps.setBigDecimal(6, new BigDecimal(String.valueOf(trigger
                .getNextFireTime().getTime())));
        long prevFireTime = -1;
        if (trigger.getPreviousFireTime() != null) {
            prevFireTime = trigger.getPreviousFireTime().getTime();
        }
        ps.setBigDecimal(7, new BigDecimal(String.valueOf(prevFireTime)));
        ps.setString(8, state);
        
        TriggerPersistenceDelegate tDel = findTriggerPersistenceDelegate(trigger);
        
        String type = TTYPE_BLOB;
        if(tDel != null)
            type = tDel.getHandledTriggerTypeDiscriminator();
        ps.setString(9, type);
        
        ps.setBigDecimal(10, new BigDecimal(String.valueOf(trigger
                .getStartTime().getTime())));
        long endTime = 0;
        if (trigger.getEndTime() != null) {
            endTime = trigger.getEndTime().getTime();
        }
        ps.setBigDecimal(11, new BigDecimal(String.valueOf(endTime)));
        ps.setString(12, trigger.getCalendarName());
        ps.setInt(13, trigger.getMisfireInstruction());
        ps.setBinaryStream(14, bais, len);
        ps.setInt(15, trigger.getPriority());
        
        insertResult = ps.executeUpdate();
        
        if(tDel == null)
            insertBlobTrigger(conn, trigger);
        else
            tDel.insertExtendedTriggerProperties(conn, trigger, state, jobDetail);
                    
    } finally {
        closeStatement(ps);
    }

    return insertResult;
}
 
Example 20
Project: lams   File: PointbaseDelegate.java   View Source Code Vote up 4 votes
@Override           
public int updateTrigger(Connection conn, OperableTrigger trigger, String state,
        JobDetail jobDetail) throws SQLException, IOException {

    ByteArrayOutputStream baos = serializeJobData(trigger.getJobDataMap());
    int len = baos.toByteArray().length;
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            
    PreparedStatement ps = null;

    int insertResult = 0;


    try {
        ps = conn.prepareStatement(rtp(UPDATE_TRIGGER));
            
        ps.setString(1, trigger.getJobKey().getName());
        ps.setString(2, trigger.getJobKey().getGroup());
        ps.setString(3, trigger.getDescription());
        long nextFireTime = -1;
        if (trigger.getNextFireTime() != null) {
            nextFireTime = trigger.getNextFireTime().getTime();
        }
        ps.setBigDecimal(4, new BigDecimal(String.valueOf(nextFireTime)));
        long prevFireTime = -1;
        if (trigger.getPreviousFireTime() != null) {
            prevFireTime = trigger.getPreviousFireTime().getTime();
        }
        ps.setBigDecimal(5, new BigDecimal(String.valueOf(prevFireTime)));
        ps.setString(6, state);
        
        TriggerPersistenceDelegate tDel = findTriggerPersistenceDelegate(trigger);
        
        String type = TTYPE_BLOB;
        if(tDel != null)
            type = tDel.getHandledTriggerTypeDiscriminator();

        ps.setString(7, type);
        
        ps.setBigDecimal(8, new BigDecimal(String.valueOf(trigger
                .getStartTime().getTime())));
        long endTime = 0;
        if (trigger.getEndTime() != null) {
            endTime = trigger.getEndTime().getTime();
        }
        ps.setBigDecimal(9, new BigDecimal(String.valueOf(endTime)));
        ps.setString(10, trigger.getCalendarName());
        ps.setInt(11, trigger.getMisfireInstruction());
        
        ps.setInt(12, trigger.getPriority());
        ps.setBinaryStream(13, bais, len);
        ps.setString(14, trigger.getKey().getName());
        ps.setString(15, trigger.getKey().getGroup());

        insertResult = ps.executeUpdate();
        
        if(tDel == null)
            updateBlobTrigger(conn, trigger);
        else
            tDel.updateExtendedTriggerProperties(conn, trigger, state, jobDetail);
        
    } finally {
        closeStatement(ps);
    }

    return insertResult;
}