Java Code Examples for org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer

The following examples show how to use org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testMySQLMaxValueIncrementer() throws SQLException {
	given(dataSource.getConnection()).willReturn(connection);
	given(connection.createStatement()).willReturn(statement);
	given(statement.executeQuery("select last_insert_id()")).willReturn(resultSet);
	given(resultSet.next()).willReturn(true);
	given(resultSet.getLong(1)).willReturn(2L, 4L);

	MySQLMaxValueIncrementer incrementer = new MySQLMaxValueIncrementer();
	incrementer.setDataSource(dataSource);
	incrementer.setIncrementerName("myseq");
	incrementer.setColumnName("seq");
	incrementer.setCacheSize(2);
	incrementer.setPaddingLength(1);
	incrementer.afterPropertiesSet();

	assertEquals(1, incrementer.nextIntValue());
	assertEquals(2, incrementer.nextLongValue());
	assertEquals("3", incrementer.nextStringValue());
	assertEquals(4, incrementer.nextLongValue());

	verify(statement, times(2)).executeUpdate("update myseq set seq = last_insert_id(seq + 2)");
	verify(resultSet, times(2)).close();
	verify(statement, times(2)).close();
	verify(connection, times(2)).close();
}
 
Example 2
@Test
public void testMySQLMaxValueIncrementer() throws SQLException {
	given(dataSource.getConnection()).willReturn(connection);
	given(connection.createStatement()).willReturn(statement);
	given(statement.executeQuery("select last_insert_id()")).willReturn(resultSet);
	given(resultSet.next()).willReturn(true);
	given(resultSet.getLong(1)).willReturn(2L, 4L);

	MySQLMaxValueIncrementer incrementer = new MySQLMaxValueIncrementer();
	incrementer.setDataSource(dataSource);
	incrementer.setIncrementerName("myseq");
	incrementer.setColumnName("seq");
	incrementer.setCacheSize(2);
	incrementer.setPaddingLength(1);
	incrementer.afterPropertiesSet();

	assertEquals(1, incrementer.nextIntValue());
	assertEquals(2, incrementer.nextLongValue());
	assertEquals("3", incrementer.nextStringValue());
	assertEquals(4, incrementer.nextLongValue());

	verify(statement, times(2)).executeUpdate("update myseq set seq = last_insert_id(seq + 2)");
	verify(resultSet, times(2)).close();
	verify(statement, times(2)).close();
	verify(connection, times(2)).close();
}
 
Example 3
@Test
public void testMySQLMaxValueIncrementer() throws SQLException {
	given(dataSource.getConnection()).willReturn(connection);
	given(connection.createStatement()).willReturn(statement);
	given(statement.executeQuery("select last_insert_id()")).willReturn(resultSet);
	given(resultSet.next()).willReturn(true);
	given(resultSet.getLong(1)).willReturn(2L, 4L);

	MySQLMaxValueIncrementer incrementer = new MySQLMaxValueIncrementer();
	incrementer.setDataSource(dataSource);
	incrementer.setIncrementerName("myseq");
	incrementer.setColumnName("seq");
	incrementer.setCacheSize(2);
	incrementer.setPaddingLength(1);
	incrementer.afterPropertiesSet();

	assertEquals(1, incrementer.nextIntValue());
	assertEquals(2, incrementer.nextLongValue());
	assertEquals("3", incrementer.nextStringValue());
	assertEquals(4, incrementer.nextLongValue());

	verify(statement, times(2)).executeUpdate("update myseq set seq = last_insert_id(seq + 2)");
	verify(resultSet, times(2)).close();
	verify(statement, times(2)).close();
	verify(connection, times(2)).close();
}
 
Example 4
@Test
public void testMySQLMaxValueIncrementer() throws SQLException {
	given(dataSource.getConnection()).willReturn(connection);
	given(connection.createStatement()).willReturn(statement);
	given(statement.executeUpdate("update myseq set seq = last_insert_id(seq + 2)")).willReturn(1);
	given(statement.executeQuery("select last_insert_id()")).willReturn(resultSet);
	given(resultSet.next()).willReturn(true);
	given(resultSet.getLong(1)).willReturn(2L, 4L);

	MySQLMaxValueIncrementer incrementer = new MySQLMaxValueIncrementer();
	incrementer.setDataSource(dataSource);
	incrementer.setIncrementerName("myseq");
	incrementer.setColumnName("seq");
	incrementer.setCacheSize(2);
	incrementer.setPaddingLength(1);
	incrementer.afterPropertiesSet();

	assertEquals(1, incrementer.nextIntValue());
	assertEquals(2, incrementer.nextLongValue());
	assertEquals("3", incrementer.nextStringValue());
	assertEquals(4, incrementer.nextLongValue());

	verify(resultSet, times(2)).close();
	verify(statement, times(2)).close();
	verify(connection, times(2)).close();
}
 
Example 5
Source Project: openemm   Source File: BIRTDataSet.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
protected int getNextTmpID() {
	try {
		if (isOracleDB()) {
			return selectInt(logger, "SELECT birt_report_tmp_tbl_seq.NEXTVAL FROM DUAL");
		} else {
			return new MySQLMaxValueIncrementer(getDataSource(), "birt_report_tmp_tbl_seq", "value").nextIntValue();
		}
	} catch (Exception e) {
		logger.error("Could not get next tmpID from database ! ", e);
		return -1;
	}
}
 
Example 6
Source Project: nextreports-server   Source File: MySqlAuditor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public int getNextEventId() {
	return new MySQLMaxValueIncrementer(getDataSource(), "NS_AUDIT_SEQ", "EVENT_ID").nextIntValue();
}