本文整理了Java中org.springframework.jdbc.core.JdbcTemplate.queryForLong()
方法的一些代码示例,展示了JdbcTemplate.queryForLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JdbcTemplate.queryForLong()
方法的具体详情如下:
包路径:org.springframework.jdbc.core.JdbcTemplate
类名称:JdbcTemplate
方法名:queryForLong
暂无
代码示例来源:origin: snakerflow/snakerflow
public Object queryCount(String sql, Object... args) {
return template.queryForLong(sql, args);
}
代码示例来源:origin: vonzhou/SpringInAction3
private long queryForIdentity() {
return getJdbcTemplate().queryForLong("call identity()");
}
代码示例来源:origin: ch.inftec.ju/ju-dbutil
/**
* Sets the nextVal of an Oracle sequence.
* <p>
* Only works with sequences that have an increment of +1.
* @param sequenceName Sequence name
* @param nextVal Value that should be yielded by next NEXVAL call
*/
public void oracleSequenceSetNextVal(String sequenceName, long nextVal) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
Long currentValue = jdbcTemplate.queryForLong(String.format("SELECT %s.NEXTVAL from dual", sequenceName));
Long increment = nextVal - currentValue - 1;
jdbcTemplate.execute(String.format("ALTER SEQUENCE %s INCREMENT BY %d", sequenceName, increment));
jdbcTemplate.execute(String.format("SELECT %s.NEXTVAL from dual", sequenceName));
jdbcTemplate.execute(String.format("ALTER SEQUENCE %s INCREMENT BY 1", sequenceName));
}
}
代码示例来源:origin: org.acegisecurity/acegi-security
/**
* Deletes a single row from acl_object_identity that is associated with the presented ObjectIdentity. In
* addition, deletes the corresponding row from acl_class if there are no more entries in acl_object_identity that
* use that particular acl_class. This keeps the acl_class table reasonably small.
*
* @param oid to delete the acl_object_identity (and clean up acl_class for that class name if appropriate)
*/
protected void deleteObjectIdentityAndOptionallyClass(ObjectIdentity oid) {
// Delete the acl_object_identity row
jdbcTemplate.update(deleteObjectIdentityByPrimaryKey, new Object[] {retrieveObjectIdentityPrimaryKey(oid)});
// Delete the acl_class row, assuming there are no other references to it in acl_object_identity
Object[] className = {oid.getJavaType().getName()};
long numObjectIdentities = jdbcTemplate.queryForLong(selectCountObjectIdentityRowsForParticularClassNameString,
className);
if (numObjectIdentities == 0) {
// No more rows
jdbcTemplate.update(deleteClassByClassNameString, className);
}
}
代码示例来源:origin: org.acegisecurity/acegi-security
/**
* Retrieves the primary key from the acl_object_identity table for the passed ObjectIdentity. Unlike some
* other methods in this implementation, this method will NOT create a row (use {@link
* #createObjectIdentity(ObjectIdentity, Sid)} instead).
*
* @param oid to find
*
* @return the object identity or null if not found
*/
protected Long retrieveObjectIdentityPrimaryKey(ObjectIdentity oid) {
try {
return new Long(jdbcTemplate.queryForLong(selectObjectIdentityPrimaryKey,
new Object[] {oid.getJavaType().getName(), oid.getIdentifier()}));
} catch (DataAccessException notFound) {
return null;
}
}
代码示例来源:origin: org.acegisecurity/acegi-security
/**
* Retrieves the primary key from acl_class, creating a new row if needed and the allowCreate property is
* true.
*
* @param clazz to find or create an entry for (this implementation uses the fully-qualified class name String)
* @param allowCreate true if creation is permitted if not found
*
* @return the primary key or null if not found
*/
protected Long createOrRetrieveClassPrimaryKey(Class clazz, boolean allowCreate) {
List classIds = jdbcTemplate.queryForList(selectClassPrimaryKey, new Object[] {clazz.getName()}, Long.class);
Long classId = null;
if (classIds.isEmpty()) {
if (allowCreate) {
classId = null;
jdbcTemplate.update(insertClass, new Object[] {clazz.getName()});
Assert.isTrue(TransactionSynchronizationManager.isSynchronizationActive(),
"Transaction must be running");
classId = new Long(jdbcTemplate.queryForLong(identityQuery));
}
} else {
classId = (Long) classIds.iterator().next();
}
return classId;
}
代码示例来源:origin: acogoluegnes/Spring-Batch-Workshop
@Override
public void write(List<? extends Contact> items) throws Exception {
for(Contact item : items) {
Long id = jdbcTemplate.queryForLong("select contact_seq.nextval from dual");
jdbcTemplate.update(
"insert into contact (id,firstname,lastname,birth) values (?,?,?,?)",
id,item.getFirstname(),item.getLastname(),item.getBirth()
);
}
}
代码示例来源:origin: acogoluegnes/Spring-Batch-Workshop
@Override
public void write(List<? extends Contact> items) throws Exception {
for(Contact item : items) {
Long id = jdbcTemplate.queryForLong("select contact_seq.nextval from dual");
jdbcTemplate.update(
"insert into contact (id,firstname,lastname,birth) values (?,?,?,?)",
id,item.getFirstname(),item.getLastname(),item.getBirth()
);
}
}
代码示例来源:origin: org.acegisecurity/acegi-security
Assert.isTrue(TransactionSynchronizationManager.isSynchronizationActive(),
"Transaction must be running");
sidId = new Long(jdbcTemplate.queryForLong(identityQuery));
代码示例来源:origin: io.openscore/score-data-impl
private boolean shouldBeRolled(PartitionGroup partitionGroup){
if (partitionGroup.getTimeThreshold() != -1){
long lastRoll = System.currentTimeMillis()-partitionGroup.getLastRollTime();
if (logger.isDebugEnabled()) logger.debug("Partition group [" + partitionGroup.getName() + "] was rolled before " + lastRoll + " ms");
if (lastRoll > partitionGroup.getTimeThreshold()){
if (logger.isInfoEnabled()) logger.info("Partition group [" + partitionGroup.getName() + "] has reached a time threshold and will be rolled");
return true;
} else if (logger.isDebugEnabled()){
logger.debug("Time threshold wasn't reached -> timeThreshold-lastRoll = " + (partitionGroup.getTimeThreshold()-lastRoll) + " ms");
}
}
if (partitionGroup.getSizeThreshold() != -1){
long partitionSize = jdbcTemplate.queryForLong(SQL("select count(*) from " + table(partitionGroup)));
if (logger.isDebugEnabled()) logger.debug("Partition group [" + partitionGroup.getName() + "]: active partition=" + partitionGroup.getActivePartition() + ", size=" + partitionSize);
if (partitionSize >= partitionGroup.getSizeThreshold()){
if (logger.isInfoEnabled()) logger.info("Partition group [" + partitionGroup.getName() + "] has reached a records limit and will be rolled");
return true;
}
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!