本文整理匯總了Java中org.springframework.jdbc.core.JdbcOperations類的典型用法代碼示例。如果您正苦於以下問題:Java JdbcOperations類的具體用法?Java JdbcOperations怎麽用?Java JdbcOperations使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JdbcOperations類屬於org.springframework.jdbc.core包,在下文中一共展示了JdbcOperations類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTargetRepository
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
@Override
protected Object getTargetRepository(RepositoryInformation metadata) {
entityClass = metadata.getDomainType();
@SuppressWarnings("rawtypes")
ReflectionJdbcRepository repository = getTargetRepositoryViaReflection(metadata, entityClass);
repository.setDataSource(datasource);
repository.afterPropertiesSet();
this.repository = repository;
generator = SqlGeneratorFactory.getInstance().getGenerator(datasource);
template = new NamedParameterJdbcTemplate((JdbcOperations) extractRepositoryField(repository, FIELD_JDBC_OPS));
rowMapper = extractRepositoryField(repository, FIELD_ROWMAPPER);
tableDescription = extractRepositoryField(repository, FIELD_TABLE_DESCRIPTION);
return repository;
}
示例2: should_return_external_executor_runner
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
@Test
public void should_return_external_executor_runner() throws Exception {
QueueConsumer queueConsumer = mock(QueueConsumer.class);
QueueSettings settings = QueueSettings.builder().withBetweenTaskTimeout(Duration.ZERO).withNoTaskTimeout(Duration.ZERO)
.withProcessingMode(ProcessingMode.USE_EXTERNAL_EXECUTOR).build();
QueueLocation location = QueueLocation.builder().withTableName("testTable")
.withQueueId(new QueueId("testQueue")).build();
when(queueConsumer.getQueueConfig()).thenReturn(new QueueConfig(location, settings));
QueueRunner queueRunner = QueueRunner.Factory.createQueueRunner(queueConsumer,
new QueueDao(new QueueShardId("s1"), mock(JdbcOperations.class), mock(TransactionOperations.class)),
mock(TaskLifecycleListener.class),
mock(Executor.class));
assertThat(queueRunner, CoreMatchers.instanceOf(QueueRunnerInExternalExecutor.class));
}
示例3: should_return_separate_transactions_runner
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
@Test
public void should_return_separate_transactions_runner() throws Exception {
QueueConsumer queueConsumer = mock(QueueConsumer.class);
QueueSettings settings = QueueSettings.builder().withBetweenTaskTimeout(Duration.ZERO).withNoTaskTimeout(Duration.ZERO)
.withProcessingMode(ProcessingMode.SEPARATE_TRANSACTIONS).build();
QueueLocation location = QueueLocation.builder().withTableName("testTable")
.withQueueId(new QueueId("testQueue")).build();
when(queueConsumer.getQueueConfig()).thenReturn(new QueueConfig(location, settings));
QueueRunner queueRunner = QueueRunner.Factory.createQueueRunner(queueConsumer,
new QueueDao(new QueueShardId("s1"), mock(JdbcOperations.class), mock(TransactionOperations.class)),
mock(TaskLifecycleListener.class),
null);
assertThat(queueRunner, CoreMatchers.instanceOf(QueueRunnerInSeparateTransactions.class));
}
示例4: should_return_wrap_in_transaction_runner
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
@Test
public void should_return_wrap_in_transaction_runner() throws Exception {
QueueConsumer queueConsumer = mock(QueueConsumer.class);
QueueSettings settings = QueueSettings.builder().withBetweenTaskTimeout(Duration.ZERO).withNoTaskTimeout(Duration.ZERO)
.withProcessingMode(ProcessingMode.WRAP_IN_TRANSACTION).build();
QueueLocation location = QueueLocation.builder().withTableName("testTable")
.withQueueId(new QueueId("testQueue")).build();
when(queueConsumer.getQueueConfig()).thenReturn(new QueueConfig(location, settings));
QueueRunner queueRunner = QueueRunner.Factory.createQueueRunner(queueConsumer,
new QueueDao(new QueueShardId("s1"), mock(JdbcOperations.class), mock(TransactionOperations.class)),
mock(TaskLifecycleListener.class),
null);
assertThat(queueRunner, CoreMatchers.instanceOf(QueueRunnerInTransaction.class));
}
示例5: executeBatchUpdateWithNamedParameters
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
public static int[] executeBatchUpdateWithNamedParameters(final ParsedSql parsedSql,
final SqlParameterSource[] batchArgs, JdbcOperations jdbcOperations) {
if (batchArgs.length <= 0) {
return new int[] {0};
}
String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, batchArgs[0]);
return jdbcOperations.batchUpdate(
sqlToUse,
new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null);
int[] columnTypes = NamedParameterUtils.buildSqlTypeArray(parsedSql, batchArgs[i]);
setStatementParameters(values, ps, columnTypes);
}
@Override
public int getBatchSize() {
return batchArgs.length;
}
});
}
示例6: getMapList
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
/**
* return a map of the objects, divided into their transactions indexes.
*
* @param jdbcOperations
* the jdbc operations to use.
* @param sqlKey
* the sql key to use.
* @param sqlArgsBaList
* the byte arrays to use for SQL arguments.
* @param mapToObject
* the mapToObject to use.
* @param <T>
* the object type to use.
* @return a map of the objects, divided into their transactions indexes.
*/
private <T> Map<Integer, List<T>> getMapList(final JdbcOperations jdbcOperations, final String sqlKey,
final AbstractMapToObject<T> mapToObject, final byte[]... sqlArgsBaList) {
final String sql = getSql(sqlKey);
final List<Map<String, Object>> mapList = jdbcOperations.queryForList(sql, (Object[]) sqlArgsBaList);
final Map<Integer, List<T>> tMapList = new TreeMap<>();
for (final Map<String, Object> map : mapList) {
final byte[] transactionIndexBa = (byte[]) map.get(TRANSACTION_INDEX);
final T t = mapToObject.toObject(map);
final int transactionIndex = getTransactionIndex(transactionIndexBa);
if (!tMapList.containsKey(transactionIndex)) {
tMapList.put(transactionIndex, new ArrayList<>());
}
tMapList.get(transactionIndex).add(t);
}
return tMapList;
}
示例7: getTransactionInputsWithIndex
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
/**
* gets the inputs for each transaction in the block, and adds them to the
* transaction.
*
* @param block
* the block to use
* @param jdbcOperations
* the jdbc operations to use.
* @param blockIndexBa
* the block index to use.
*/
private void getTransactionInputsWithIndex(final Block block, final JdbcOperations jdbcOperations,
final byte[] blockIndexBa) {
final Map<Integer, List<CoinReference>> inputsMap = getMapList(jdbcOperations,
"getTransactionInputsWithBlockIndex", new CoinReferenceMapToObject(), blockIndexBa);
for (final int txIx : inputsMap.keySet()) {
final List<CoinReference> inputs = inputsMap.get(txIx);
if (txIx >= block.getTransactionList().size()) {
throw new RuntimeException(
"txIx \"" + txIx + "\" exceeds txList.size \"" + block.getTransactionList().size()
+ "\" for block index \"" + block.getIndexAsLong() + "\" hash \"" + block.hash + "\"");
} else {
block.getTransactionList().get(txIx).inputs.addAll(inputs);
}
}
}
示例8: DefaultCalendarService
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
@Autowired
public DefaultCalendarService(final EventDao eventDao,
final CalendarUserDao userDao,
final JdbcOperations jdbcOperations,
final PasswordEncoder passwordEncoder) {
if (eventDao == null) {
throw new IllegalArgumentException("eventDao cannot be null");
}
if (userDao == null) {
throw new IllegalArgumentException("userDao cannot be null");
}
if (jdbcOperations == null) {
throw new IllegalArgumentException("jdbcOperations cannot be null");
}
if (passwordEncoder == null) {
throw new IllegalArgumentException("passwordEncoder cannot be null");
}
this.eventDao = eventDao;
this.userDao = userDao;
this.jdbcOperations = jdbcOperations;
this.passwordEncoder = passwordEncoder;
}
示例9: DefaultCalendarService
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
@Autowired
public DefaultCalendarService(final EventDao eventDao,
final CalendarUserDao userDao,
final JdbcOperations jdbcOperations) {
if (eventDao == null) {
throw new IllegalArgumentException("eventDao cannot be null");
}
if (userDao == null) {
throw new IllegalArgumentException("userDao cannot be null");
}
if (jdbcOperations == null) {
throw new IllegalArgumentException("jdbcOperations cannot be null");
}
this.eventDao = eventDao;
this.userDao = userDao;
this.jdbcOperations = jdbcOperations;
}
示例10: addVersions
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
/**
* Add the given versions to the given project
*
* @param dataSource
* The data source of JIRA database.
* @param jira
* the JIRA project identifier.
* @param versions
* the version names to add
* @return the {@link Map} where value is the created version identifier.
*/
public Map<String, Integer> addVersions(final DataSource dataSource, final int jira,
final Collection<String> versions) {
final Map<String, Integer> result = new HashMap<>();
final JdbcOperations jdbcTemplate = new JdbcTemplate(dataSource);
int nextId = prepareForNextId(dataSource, VERSION_NODE, versions.size());
int nextSequence = getNextVersionSequence(jira, jdbcTemplate);
for (final String version : versions) {
jdbcTemplate.update("INSERT INTO projectversion (ID,PROJECT,vname,SEQUENCE) values(?,?,?,?)", nextId, jira,
version, nextSequence);
result.put(version, nextId);
nextId++;
nextSequence++;
}
return result;
}
示例11: getCurrentSequence
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
/**
* Return current sequence.
*/
protected int getCurrentSequence(final String sequenceName, final JdbcOperations jdbcTemplate) {
final Long currentSequence;
final List<Long> sequence = jdbcTemplate
.queryForList("SELECT SEQ_ID FROM SEQUENCE_VALUE_ITEM WHERE SEQ_NAME = ?", Long.class, sequenceName);
if (sequence.isEmpty()) {
// New sequence, start from an arbitrary sequence to be sure JIRA
// does not fill it
currentSequence = 10000L;
jdbcTemplate.update("INSERT INTO SEQUENCE_VALUE_ITEM (SEQ_NAME,SEQ_ID) values(?,?)", sequenceName,
currentSequence);
} else {
currentSequence = sequence.get(0);
}
return currentSequence.intValue();
}
示例12: testPrepareForNextIdConcurrent
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
@Test
public void testPrepareForNextIdConcurrent() throws Exception {
final JiraUpdateDao dao = new JiraUpdateDao() {
private boolean mock = true;
@Override
protected int getCurrentSequence(final String sequenceName, final JdbcOperations jdbcTemplate) {
if (mock) {
mock = false;
return -10000;
}
return super.getCurrentSequence(sequenceName, jdbcTemplate);
}
};
Assert.assertEquals(10100, dao.prepareForNextId(datasource, "ChangeGroup", 2000));
}
示例13: addIssues
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
/**
* Indicate the installation and activation of "script runner" plug-in.
*
* @param dataSource
* The data source of JIRA database.
* @param jira
* the JIRA project identifier.
* @param issues
* The issues to add. The ID property of each inserted issue is
* also updated in these objects.
* @param workflowStepMapping
* the {@link Map} linking type identifier to a {@link Map}
* linking status name to steps.
*/
public void addIssues(final DataSource dataSource, final int jira, final List<JiraIssueRow> issues,
final Map<Integer, Workflow> workflowStepMapping) {
final JdbcOperations jdbcTemplate = new JdbcTemplate(dataSource);
int nextId = prepareForNextId(dataSource, ISSUE_NODE, issues.size());
reserveProjectCounter(dataSource, jira, issues);
int nextCurrentStepId = prepareForNextId(dataSource, "OSCurrentStep", issues.size());
int nextWfEntryId = prepareForNextId(dataSource, "OSWorkflowEntry", issues.size());
int counter = 0;
for (final JiraIssueRow issueRow : issues) {
issueRow.setId(nextId);
log.info("Inserting issue {}-{}({}) {}/{}", issueRow.getPkey(), issueRow.getIssueNum(), issueRow.getId(),
counter, issues.size());
Workflow workflow = workflowStepMapping.get(issueRow.getType());
if (workflow == null) {
workflow = workflowStepMapping.get(0);
}
addIssue(jira, jdbcTemplate, nextId, nextCurrentStepId, nextWfEntryId, issueRow, workflow);
nextId++;
nextWfEntryId++;
nextCurrentStepId++;
counter++;
}
}
示例14: addIssue
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
/**
* Add an issue, workflow entry, corresponding step of current status and link author to this issue (user activity
* dashboard)
*/
private void addIssue(final int jira, final JdbcOperations jdbcTemplate, final int nextId, final int nextCurrentStepId, final int nextWfEntryId,
final JiraIssueRow issueRow, final Workflow workflow) {
final INamableBean<Integer> workflowStep = workflow.getStatusToSteps().get(issueRow.getStatusText());
// Insert workflow activity
jdbcTemplate.update("INSERT INTO OS_WFENTRY (ID,NAME,STATE) values(?,?,?)", nextWfEntryId, workflow.getName(), 1);
jdbcTemplate.update("INSERT INTO OS_CURRENTSTEP (ID,ENTRY_ID,STEP_ID,ACTION_ID,START_DATE,STATUS) values(?,?,?,?,?,?)", nextCurrentStepId,
nextWfEntryId, workflowStep.getId(), 0, issueRow.getCreated(), workflowStep.getName());
// Insert issue
jdbcTemplate.update(
"INSERT INTO jiraissue"
+ " (ID,issuenum,WATCHES,VOTES,PROJECT,REPORTER,ASSIGNEE,CREATOR,issuetype,SUMMARY,DESCRIPTION,PRIORITY,RESOLUTION,RESOLUTIONDATE,"
+ "issuestatus,CREATED,UPDATED,WORKFLOW_ID,DUEDATE) values(?,?,1,0,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
nextId, issueRow.getIssueNum(), jira, issueRow.getReporter(), issueRow.getAssignee(), issueRow.getAuthor(), issueRow.getType(),
issueRow.getSummary(), issueRow.getDescription(), issueRow.getPriority(), issueRow.getResolution(), issueRow.getResolutionDate(),
issueRow.getStatus(), issueRow.getCreated(), issueRow.getUpdated(), nextWfEntryId, issueRow.getDueDate());
// Add user relation
jdbcTemplate.update("INSERT INTO userassociation (SOURCE_NAME,SINK_NODE_ID,SINK_NODE_ENTITY,ASSOCIATION_TYPE,CREATED) values(?,?,?,?,?)",
issueRow.getAuthor(), nextId, "Issue", "WatchIssue", issueRow.getUpdated());
}
示例15: OAuth2Configuration
import org.springframework.jdbc.core.JdbcOperations; //導入依賴的package包/類
public OAuth2Configuration(ResourceLoader resourceLoader, OpenIdProviderProperties properties,
ObjectProvider<JdbcOperations> jdbcOperations, ObjectProvider<AuthenticationManager> authenticationManager,
ObjectProvider<HazelcastInstance> hazelcastInstance) {
this.resourceLoader = resourceLoader;
this.properties = properties;
this.jdbcOperations = jdbcOperations.getObject();
this.authenticationManager = authenticationManager.getObject();
this.hazelcastInstance = hazelcastInstance.getObject();
}