Java 类org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations 实例源码

项目:spring-data-jdbc-template    文件:JdbcTemplateRepositoryQuery.java   
@Override
public Object execute(Object[] parameters) {
    NamedParameterJdbcOperations jdbcTemplate = BeanFactoryUtils.getBeanByNameOrType(beanFactory,
            configuration.getOperationsBeanName(), NamedParameterJdbcOperations.class);

    Map<String, Object> paramMap = new HashMap<>();
    for (int i = 0; i < parameters.length; i++) {
        Parameter param = queryMethod.getParameters().getParameter(i);
        paramMap.put(param.getName(), convertValue(parameters[i], param.getType()));
    }

    Class<?> resultType = queryMethod.getReturnedObjectType();

    if (queryMethod.isModifyingQuery()) {
        return jdbcTemplate.update(getQuery(), paramMap);
    } else {
        return jdbcTemplate.query(getQuery(), paramMap, getRowMapper(this.queryMethod, resultType));
    }
}
项目:oma-riista-web    文件:CopyZoneGeometryQueries.java   
public CopyZoneGeometryQueries(final NamedParameterJdbcOperations jdbcOperations) {
    this.jdbcOperations = jdbcOperations;

    final String palstaFields = Joiner.on(", ").join(ZONE_PALSTA_FIELDS);
    final String featureFields = Joiner.on(", ").join(ZONE_FEATURE_FIELDS);

    this.copyZonePalstaSql = "INSERT INTO zone_palsta (zone_id, " + palstaFields + ")" +
            " SELECT :to_zone_id, " + palstaFields +
            " FROM zone_palsta" +
            " WHERE zone_id = :from_zone_id";

    copyZoneFeatureSql = "INSERT INTO zone_feature (zone_id, " + featureFields + ")" +
            " SELECT :to_zone_id, " + featureFields +
            " FROM zone_feature" +
            " WHERE zone_id = :from_zone_id";
}
项目:jdbc    文件:JdbcSinkIntegrationTests.java   
@Test
public void testInsertion() {
    NamedParameterJdbcOperations namedParameterJdbcOperations = new NamedParameterJdbcTemplate(jdbcOperations);
    Map<String, Object> mapA = new HashMap<>();
    mapA.put("a", "hello1");
    mapA.put("b", 42);
    Map<String, Object> mapB = new HashMap<>();
    mapB.put("a", "hello2");
    mapB.put("b", null);
    Map<String, Object> mapC = new HashMap<>();
    mapC.put("a", "hello3");
    channels.input().send(MessageBuilder.withPayload(mapA).build());
    channels.input().send(MessageBuilder.withPayload(mapB).build());
    channels.input().send(MessageBuilder.withPayload(mapC).build());
    Assert.assertThat(namedParameterJdbcOperations.queryForObject(
            "select count(*) from messages where a = :a and b = :b", mapA, Integer.class), is(1));
    Assert.assertThat(namedParameterJdbcOperations.queryForObject(
            "select count(*) from messages where a = :a and b IS NULL", mapB, Integer.class), is(1));
    Assert.assertThat(namedParameterJdbcOperations.queryForObject(
            "select count(*) from messages where a = :a and b IS NULL", mapC, Integer.class), is(1));
}
项目:spring-cloud-stream-app-starters    文件:JdbcSinkIntegrationTests.java   
@Test
public void testInsertion() {
    NamedParameterJdbcOperations namedParameterJdbcOperations = new NamedParameterJdbcTemplate(jdbcOperations);
    Map<String, Object> mapA = new HashMap<>();
    mapA.put("a", "hello1");
    mapA.put("b", 42);
    Map<String, Object> mapB = new HashMap<>();
    mapB.put("a", "hello2");
    mapB.put("b", null);
    Map<String, Object> mapC = new HashMap<>();
    mapC.put("a", "hello3");
    channels.input().send(MessageBuilder.withPayload(mapA).build());
    channels.input().send(MessageBuilder.withPayload(mapB).build());
    channels.input().send(MessageBuilder.withPayload(mapC).build());
    Assert.assertThat(namedParameterJdbcOperations.queryForObject(
            "select count(*) from messages where a = :a and b = :b", mapA, Integer.class), is(1));
    Assert.assertThat(namedParameterJdbcOperations.queryForObject(
            "select count(*) from messages where a = :a and b IS NULL", mapB, Integer.class), is(1));
    Assert.assertThat(namedParameterJdbcOperations.queryForObject(
            "select count(*) from messages where a = :a and b IS NULL", mapC, Integer.class), is(1));
}
项目:FinanceAnalytics    文件:DbFunctionCostsMaster.java   
@Override
public FunctionCostsDocument load(final String configuration, final String functionId, Instant versionAsOf) {
  s_logger.debug("load: {} {}", configuration, functionId);
  if (versionAsOf == null) {
    versionAsOf = Instant.now(getClock());
  }
  final DbMapSqlParameterSource args = new DbMapSqlParameterSource()
    .addValue("configuration", configuration.trim())
    .addValue("function", functionId.trim())
    .addTimestamp("version_instant", versionAsOf)
    .addValue("paging_offset", 0)
    .addValue("paging_fetch", 1);
  final FunctionCostsDocumentExtractor extractor = new FunctionCostsDocumentExtractor();
  final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
  final String sql = getElSqlBundle().getSql("GetCosts", args);
  final List<FunctionCostsDocument> docs = namedJdbc.query(sql, args, extractor);
  return docs.isEmpty() ? null : docs.get(0);
}
项目:FinanceAnalytics    文件:DbPositionMaster.java   
/**
 * Gets a trade by searching for the latest version of an object identifier.
 * 
 * @param uniqueId the unique identifier, not null
 * @param versionAsOf the instant to fetch, not null
 * @param correctedTo the instant to fetch, not null
 * @return the trade, null if not found
 */
protected ManageableTrade getTradeByInstants(final UniqueId uniqueId, final Instant versionAsOf, final Instant correctedTo) {
  s_logger.debug("getTradeByLatest {}", uniqueId);
  final Instant now = now();
  final DbMapSqlParameterSource args = createParameterSource().addValue("trade_oid", extractOid(uniqueId))
      .addTimestamp("version_as_of_instant", Objects.firstNonNull(versionAsOf, now))
      .addTimestamp("corrected_to_instant", Objects.firstNonNull(correctedTo, now));
  final PositionDocumentExtractor extractor = new PositionDocumentExtractor();
  final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
  final String sql = getElSqlBundle().getSql("GetTradeByOidInstants", args);
  final List<PositionDocument> docs = namedJdbc.query(sql, args, extractor);
  if (docs.isEmpty()) {
    throw new DataNotFoundException("Trade not found: " + uniqueId);
  }
  return docs.get(0).getPosition().getTrades().get(0); // SQL loads desired trade as only trade
}
项目:FinanceAnalytics    文件:AbstractDocumentDbMaster.java   
/**
 * Performs a standard get by object identifier at instants.
 *
 * @param objectId  the object identifier, not null
 * @param versionCorrection  the version-correction locator, not null
 * @param extractor  the extractor to use, not null
 * @param masterName  a name describing the contents of the master for an error message, not null
 * @return the document, null if not found
 */
protected D doGetByOidInstants(
  final ObjectIdentifiable objectId, final VersionCorrection versionCorrection,
  final ResultSetExtractor<List<D>> extractor, final String masterName) {
  ArgumentChecker.notNull(objectId, "oid");
  ArgumentChecker.notNull(versionCorrection, "versionCorrection");
  ArgumentChecker.notNull(extractor, "extractor");
  s_logger.debug("getByOidInstants {}", objectId);

  Timer.Context context = _getByOidInstantsTimer.time();
  try {
    final VersionCorrection vc = (versionCorrection.containsLatest() ? versionCorrection.withLatestFixed(now()) : versionCorrection);
    final DbMapSqlParameterSource args = argsGetByOidInstants(objectId, vc);
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final String sql = getElSqlBundle().getSql("GetByOidInstants", args);
    final List<D> docs = namedJdbc.query(sql, args, extractor);
    if (docs.isEmpty()) {
      throw new DataNotFoundException(masterName + " not found: " + objectId);
    }
    return docs.get(0);
  } finally {
    context.stop();
  }
}
项目:FinanceAnalytics    文件:AbstractDocumentDbMaster.java   
/**
 * Performs a standard get by versioned unique identifier.
 *
 * @param uniqueId  the versioned unique identifier, not null
 * @param extractor  the extractor to use, not null
 * @param masterName  a name describing the contents of the master for an error message, not null
 * @return the document, null if not found
 */
protected D doGetById(final UniqueId uniqueId, final ResultSetExtractor<List<D>> extractor, final String masterName) {
  ArgumentChecker.notNull(uniqueId, "uniqueId");
  ArgumentChecker.notNull(extractor, "extractor");
  s_logger.debug("getById {}", uniqueId);

  Timer.Context context = _getByIdTimer.time();
  try {
    final DbMapSqlParameterSource args = argsGetById(uniqueId);
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final String sql = getElSqlBundle().getSql("GetById", args);
    final List<D> docs = namedJdbc.query(sql, args, extractor);
    if (docs.isEmpty()) {
      throw new DataNotFoundException(masterName + " not found: " + uniqueId);
    }
    return docs.get(0);
  } finally {
    context.stop();
  }
}
项目:FinanceAnalytics    文件:AbstractDocumentDbMaster.java   
/**
 * Searches for documents with paging.
 *
 * @param <T>  the type of the document
 * @param pagingRequest  the paging request, not null
 * @param sql  the array of SQL, query and count, not null
 * @param args  the query arguments, not null
 * @param extractor  the extractor of results, not null
 * @param result  the object to populate, not null
 */
protected <T extends AbstractDocument> void searchWithPaging(
    final PagingRequest pagingRequest, final String[] sql, final DbMapSqlParameterSource args,
    final ResultSetExtractor<List<T>> extractor, final AbstractDocumentsResult<T> result) {
  s_logger.debug("with args {}", args);

  final NamedParameterJdbcOperations namedJdbc = getJdbcTemplate();
  if (pagingRequest.equals(PagingRequest.ALL)) {
    result.getDocuments().addAll(namedJdbc.query(sql[0], args, extractor));
    result.setPaging(Paging.of(pagingRequest, result.getDocuments()));
  } else {
    s_logger.debug("executing sql {}", sql[1]);
    final int count = namedJdbc.queryForObject(sql[1], args, Integer.class);
    result.setPaging(Paging.of(pagingRequest, count));
    if (count > 0 && pagingRequest.equals(PagingRequest.NONE) == false) {
      s_logger.debug("executing sql {}", sql[0]);
      result.getDocuments().addAll(namedJdbc.query(sql[0], args, extractor));
    }
  }
}
项目:FinanceAnalytics    文件:DbPortfolioMaster.java   
/**
 * Gets a node by searching for the latest version of an object identifier.
 * 
 * @param uniqueId the unique identifier, not null
 * @param versionAsOf the instant to fetch, not null
 * @param correctedTo the instant to fetch, not null
 * @return the node, null if not found
 */
protected ManageablePortfolioNode getNodeByInstants(final UniqueId uniqueId, final Instant versionAsOf, final Instant correctedTo) {
  s_logger.debug("getNodeByLatest {}", uniqueId);
  final Instant now = now();
  final DbMapSqlParameterSource args = createParameterSource()
      .addValue("node_oid", extractOid(uniqueId))
      .addTimestamp("version_as_of_instant", Objects.firstNonNull(versionAsOf, now))
      .addTimestamp("corrected_to_instant", Objects.firstNonNull(correctedTo, now));
  final PortfolioDocumentExtractor extractor = new PortfolioDocumentExtractor(true, false);
  final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
  final String sql = getElSqlBundle().getSql("GetNodeByOidInstants", args);
  final List<PortfolioDocument> docs = namedJdbc.query(sql, args, extractor);
  if (docs.isEmpty()) {
    throw new DataNotFoundException("Node not found: " + uniqueId);
  }
  return docs.get(0).getPortfolio().getRootNode(); // SQL loads desired node in place of the root node
}
项目:FinanceAnalytics    文件:AbstractDbUserMaster.java   
/**
 * Convert a name to an object identifier.
 * <p>
 * If an object is renamed, the old name remains as an alias.
 * The separate name resolution handles that case.
 * 
 * @param name  the name, not null
 * @param onDeleted  how to handle deletion
 * @return the object identifier, null if not found
 */
ObjectId lookupName(String name, OnDeleted onDeleted) {
  ArgumentChecker.notNull(name, "name");
  try (Timer.Context context = _lookupNameTimer.time()) {
    final DbMapSqlParameterSource args = createParameterSource()
      .addValue("name_ci", caseInsensitive(name));
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final String sql = getElSqlBundle().getSql("GetIdByName", args);
    SqlRowSet rowSet = namedJdbc.queryForRowSet(sql, args);
    if (rowSet.next() == false) {
      throw new DataNotFoundException("Name not found: " + name);
    }
    String deleted = rowSet.getString("DELETED");
    if (deleted.equals("Y")) {
      if (onDeleted == OnDeleted.RETURN_NULL) {
        return null;
      } else if (onDeleted == OnDeleted.EXCEPTION) {
        throw new DataNotFoundException("Name not found: " + name);
      }
    }
    return createObjectId(rowSet.getLong("DOC_ID")).getObjectId();
  }
}
项目:FinanceAnalytics    文件:DbHistoricalTimeSeriesDataPointsWorker.java   
/**
 * Resolves an object identifier to a unique identifier.
 * 
 * @param objectId  the time-series object identifier, not null
 * @param versionCorrection  the version-correction locator to search at, not null
 * @return the time-series, not null
 */
protected UniqueId resolveObjectId(ObjectIdentifiable objectId, VersionCorrection versionCorrection) {
  ArgumentChecker.notNull(objectId, "objectId");
  ArgumentChecker.notNull(versionCorrection, "versionCorrection");
  checkScheme(objectId);
  final long oid = extractOid(objectId);
  versionCorrection = versionCorrection.withLatestFixed(now());
  final DbMapSqlParameterSource args = createParameterSource()
    .addValue("doc_oid", oid)
    .addTimestamp("version_as_of_instant", versionCorrection.getVersionAsOf())
    .addTimestamp("corrected_to_instant", versionCorrection.getCorrectedTo());
  final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
  final UniqueIdExtractor extractor = new UniqueIdExtractor(oid);
  final String sql = getElSqlBundle().getSql("SelectUniqueIdByVersionCorrection", args);
  final UniqueId uniqueId = namedJdbc.query(sql, args, extractor);
  if (uniqueId == null) {
    throw new DataNotFoundException("Unable to find time-series: " + objectId.getObjectId());
  }
  return uniqueId;
}
项目:spring-data-jdbc    文件:JdbcQueryLookupStrategy.java   
/**
 * Creates a new {@link AbstractQueryLookupStrategy}.
 *
 * @param em
 * @param extractor
 * @param evaluationContextProvider
 */
public AbstractQueryLookupStrategy(SqlGenerator generator, NamedParameterJdbcOperations template, RowMapper rowMapper,
                                   TableDescription tableDescription) {
    this.generator = generator;
    this.template = template;
    this.rowMapper = rowMapper;
    this.tableDescription = tableDescription;
}
项目:spring-data-jdbc    文件:JdbcAnnotatedRepositoryQuery.java   
public JdbcAnnotatedRepositoryQuery(QueryMethod method, NamedParameterJdbcOperations template, String query, RowMapper rowMapper,
                                    Strategy strategy, List<String> parametersNames) {
    this.method = method;
    this.query = query;
    this.template = template;
    this.rowMapper = rowMapper;
    this.parametersNames = parametersNames;

    LOGGER.debug("applying strategy {}", strategy.name());

    switch (strategy) {
        case COLLECTION_QUERY:
            this.strategy = new CollectionQueryJdbcRepositoryStrategy();
            break;
        case COUNT:
            this.strategy = new CountJdbcRepositoryStrategy();
            break;
        case SINGLE_QUERY:
            this.strategy = new SingleQueryJdbcRepositoryStrategy();
            break;
        case UPDATE_QUERY:
            this.strategy = new UpdatetJdbcRepositoryStrategy();
            break;
        case PAGE_QUERY:
            this.strategy = new PageJdbcRepositoryStrategy();
            break;
        case EXISTS_QUERY:
            this.strategy = new ExistsJdbcRepositoryStrategy();
            break;
        default:
            throw new IllegalArgumentException("Unkwnown strategy provided");
    }

}
项目:spring-data-jdbc    文件:JdbcAnnotatedRepositoryQueryCreator.java   
public JdbcAnnotatedRepositoryQueryCreator(JdbcQueryMethod method, SqlGenerator builder,
                                           NamedParameterJdbcOperations template, TableDescription tableDescription,
                                           @SuppressWarnings("rawtypes")
                                                   RowMapper rowMapper) {
    this.method = method;
    this.builder = builder;
    this.template = template;
    this.rowMapper = rowMapper;
    this.tableDescription = tableDescription;
    this.strategy = chooseStrategy(method);
    prepareQuery(method);
}
项目:spring-data-jdbc    文件:JdbcByNameRepositoryQuery.java   
public JdbcByNameRepositoryQuery(QueryMethod method, NamedParameterJdbcOperations template, String query, RowMapper rowMapper,
                                 LookupStrategy lookupStrategy, List<ParameterProperties> parameterProperties) {
    this.method = method;
    this.query = query;
    this.template = template;
    this.rowMapper = rowMapper;

    LOGGER.debug("applying lookupStrategy {}", lookupStrategy.name());

    this.strategy = JdbcRepositoryExecutionStrategyFactory.chooseStrategy(lookupStrategy);
    processMethodParameters(parameterProperties);


}
项目:spring-data-jdbc    文件:JdbcByNameRepositoryQueryCreator.java   
public JdbcByNameRepositoryQueryCreator(JdbcQueryMethod method, PartTree tree, SqlGenerator builder,
                                        NamedParameterJdbcOperations template, TableDescription tableDescription,
                                        @SuppressWarnings("rawtypes")
                                                RowMapper rowMapper) {
    super(tree, ReflectionMethodsUtils.generateParameters(method));
    this.tree = tree;
    this.method = method;
    this.builder = builder;
    this.template = template;
    this.rowMapper = rowMapper;
    this.tableDescription = tableDescription;
    this.lookupStrategy = LookupStrategyFactory.chooseStrategy(tree, method);
}
项目:spring-data-jdbc-template    文件:SimpleJdbcUpdate.java   
private SimpleJdbcUpdate(NamedParameterJdbcOperations namedParameterJdbcOperations, Class<?> entityClass,
        String tableName, Collection<String> columnNames, Collection<String> generatedKeyNames) {
    this.namedParameterJdbcOperations = namedParameterJdbcOperations;
    this.jdbcTemplate = (JdbcTemplate) namedParameterJdbcOperations.getJdbcOperations();
    this.tableMetaDataContext.setNativeJdbcExtractor(jdbcTemplate.getNativeJdbcExtractor());
    this.entityClass = entityClass;
    this.tableName = tableName;
    this.columnNames = Collections.unmodifiableList(new ArrayList<>(columnNames));
    this.generatedKeyNames = Collections.unmodifiableList(new ArrayList<>(generatedKeyNames));

    initMetaData();
}
项目:oma-riista-web    文件:JdbcTemplateEnhancer.java   
public static NamedParameterJdbcOperations wrap(final NamedParameterJdbcOperations jdbcOperations) {
    final Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(NamedParameterJdbcOperations.class);
    enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> {
        final Stopwatch sw = Stopwatch.createStarted();

        try {
            final String methodName = method.getName();

            if (methodName.startsWith("query")
                    || methodName.startsWith("batchUpdate")
                    || methodName.startsWith("update")) {
                logSqlQuery(args);

                final Object result = method.invoke(jdbcOperations, args);

                if (sw.elapsed(TimeUnit.SECONDS) > 5) {
                    LOG.warn("SQL execution took too long {}", sw);
                }

                return result;
            }

            return method.invoke(jdbcOperations, args);

        } catch (InvocationTargetException e) {
            throw e.getTargetException();
        }
    });

    return (NamedParameterJdbcOperations) enhancer.create();
}
项目:oma-riista-web    文件:JdbcTemplateUtils.java   
public static <T> T queryForSingleValue(final String sql,
                                        final T defaultValue,
                                        final NamedParameterJdbcOperations template,
                                        final SqlParameterSource paramSource,
                                        final Class<T> requiredType) {
    final List<T> listResult = template.queryForList(sql, paramSource, requiredType);
    return Iterables.getFirst(listResult, defaultValue);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:DataSourceAutoConfigurationTests.java   
@Test
public void testNamedParameterJdbcTemplateExists() throws Exception {
    this.context.register(DataSourceAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(NamedParameterJdbcOperations.class)).isNotNull();
}
项目:spring-boot-concourse    文件:DataSourceAutoConfigurationTests.java   
@Test
public void testNamedParameterJdbcTemplateExists() throws Exception {
    this.context.register(DataSourceAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(NamedParameterJdbcOperations.class)).isNotNull();
}
项目:FinanceAnalytics    文件:DbFunctionCostsMaster.java   
public int getSchemaVersion() {
  final DbMapSqlParameterSource args = new DbMapSqlParameterSource().addValue("version_key", "schema_patch");
  final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
  final String sql = getElSqlBundle().getSql("GetSchemaVersion", args);
  String version = namedJdbc.queryForObject(sql, args, String.class);
  return Integer.parseInt(version);
}
项目:FinanceAnalytics    文件:DbPositionMaster.java   
/**
 * Gets a trade by identifier.
 * 
 * @param uniqueId the unique identifier, not null
 * @return the trade, null if not found
 */
protected ManageableTrade getTradeById(final UniqueId uniqueId) {
  s_logger.debug("getTradeById {}", uniqueId);
  final DbMapSqlParameterSource args = createParameterSource().addValue("trade_id", extractRowId(uniqueId));
  final PositionDocumentExtractor extractor = new PositionDocumentExtractor();
  final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
  final String sql = getElSqlBundle().getSql("GetTradeById", args);
  final List<PositionDocument> docs = namedJdbc.query(sql, args, extractor);
  if (docs.isEmpty()) {
    throw new DataNotFoundException("Trade not found: " + uniqueId);
  }
  return docs.get(0).getPosition().getTrades().get(0); // SQL loads desired trade as only trade
}
项目:FinanceAnalytics    文件:DbPortfolioMaster.java   
/**
 * Gets a node by identifier.
 * 
 * @param uniqueId the unique identifier, not null
 * @return the node, null if not found
 */
protected ManageablePortfolioNode getNodeById(final UniqueId uniqueId) {
  s_logger.debug("getNodeById {}", uniqueId);
  final DbMapSqlParameterSource args = createParameterSource()
      .addValue("node_id", extractRowId(uniqueId));
  final PortfolioDocumentExtractor extractor = new PortfolioDocumentExtractor(true, false);
  final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
  final String sql = getElSqlBundle().getSql("GetNodeById", args);
  final List<PortfolioDocument> docs = namedJdbc.query(sql, args, extractor);
  if (docs.isEmpty()) {
    throw new DataNotFoundException("Node not found: " + uniqueId);
  }
  return docs.get(0).getPortfolio().getRootNode(); // SQL loads desired node in place of the root node
}
项目:FinanceAnalytics    文件:DbRoleMaster.java   
private RoleSearchResult doSearch(RoleSearchRequest request) {
  PagingRequest pagingRequest = request.getPagingRequest();
  // setup args
  final DbMapSqlParameterSource args = createParameterSource()
    .addValueNullIgnored("role_name_ci", caseInsensitive(getDialect().sqlWildcardAdjustValue(request.getRoleName())))
    .addValueNullIgnored("assoc_user", request.getAssociatedUser())
    .addValueNullIgnored("assoc_perm", request.getAssociatedPermission())
    .addValueNullIgnored("assoc_role", request.getAssociatedRole());
  if (request.getObjectIds() != null) {
    StringBuilder buf = new StringBuilder(request.getObjectIds().size() * 10);
    for (ObjectId objectId : request.getObjectIds()) {
      checkScheme(objectId);
      buf.append(extractOid(objectId)).append(", ");
    }
    buf.setLength(buf.length() - 2);
    args.addValue("sql_search_object_ids", buf.toString());
  }
  args.addValue("sort_order", ORDER_BY_MAP.get(request.getSortOrder()));
  args.addValue("paging_offset", pagingRequest.getFirstItem());
  args.addValue("paging_fetch", pagingRequest.getPagingSize());
  // search
  String[] sql = {getElSqlBundle().getSql("Search", args), getElSqlBundle().getSql("SearchCount", args)};
  final NamedParameterJdbcOperations namedJdbc = getJdbcTemplate();
  Paging paging;
  List<ManageableRole> results = new ArrayList<>();
  if (pagingRequest.equals(PagingRequest.ALL)) {
    paging = Paging.of(pagingRequest, results);
    results.addAll(namedJdbc.query(sql[0], args, new RoleExtractor()));
  } else {
    s_logger.debug("executing sql {}", sql[1]);
    final int count = namedJdbc.queryForObject(sql[1], args, Integer.class);
    paging = Paging.of(pagingRequest, count);
    if (count > 0 && pagingRequest.equals(PagingRequest.NONE) == false) {
      s_logger.debug("executing sql {}", sql[0]);
      results.addAll(namedJdbc.query(sql[0], args, new RoleExtractor()));
    }
  }
  return new RoleSearchResult(paging, results);
}
项目:FinanceAnalytics    文件:AbstractDbUserMaster.java   
/**
 * Checks if a name exists already.
 * 
 * @param name  the name, not null
 * @return true if exists
 */
boolean doNameExists(String name) {
  ArgumentChecker.notNull(name, "name");
  try (Timer.Context context = _lookupNameTimer.time()) {
    final DbMapSqlParameterSource args = createParameterSource()
      .addValue("name_ci", caseInsensitive(name));
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final String sql = getElSqlBundle().getSql("GetIdByName", args);
    SqlRowSet rowSet = namedJdbc.queryForRowSet(sql, args);
    return rowSet.next();
  }
}
项目:FinanceAnalytics    文件:AbstractDbUserMaster.java   
T doGetById(ObjectId objectId, ResultSetExtractor<List<T>> extractor) {
  try (Timer.Context context = _getByIdTimer.time()) {
    final long oid = extractOid(objectId);
    final DbMapSqlParameterSource args = createParameterSource()
      .addValue("doc_id", oid);
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final String sql = getElSqlBundle().getSql("GetById", args);
    final List<T> users = namedJdbc.query(sql, args, extractor);
    if (users.isEmpty()) {
      throw new DataNotFoundException("Identifier not found: " + objectId);
    }
    return users.get(0);
  }
}
项目:FinanceAnalytics    文件:AbstractDbUserMaster.java   
/**
 * Checks if a user exists already.
 * 
 * @param objectId  the user identifier, not null
 * @return true if exists
 */
boolean idExists(ObjectId objectId) {
  final long oid = extractOid(objectId);
  final DbMapSqlParameterSource args = createParameterSource()
    .addValue("doc_id", oid);
  final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
  final String sql = getElSqlBundle().getSql("GetById", args);
  SqlRowSet rowSet = namedJdbc.queryForRowSet(sql, args);
  return rowSet.next();
}
项目:FinanceAnalytics    文件:AbstractDbUserMaster.java   
List<HistoryEvent> doEventHistory(ObjectId objectId) {
  try (Timer.Context context = _eventHistoryTimer.time()) {
    final long oid = extractOid(objectId);
    final DbMapSqlParameterSource args = createParameterSource()
      .addValue("doc_id", oid);
    final NamedParameterJdbcOperations namedJdbc = getDbConnector().getJdbcTemplate();
    final String sql = getElSqlBundle().getSql("GetEventHistory", args);
    return namedJdbc.query(sql, args, new EventExtractor());
  }
}
项目:contestparser    文件:DataSourceAutoConfigurationTests.java   
@Test
public void testNamedParameterJdbcTemplateExists() throws Exception {
    this.context.register(DataSourceAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    assertNotNull(this.context.getBean(NamedParameterJdbcOperations.class));
}
项目:class-guard    文件:SimpleJdbcTemplateTests.java   
@Before
public void setup() {
    this.operations = mock(JdbcOperations.class);
    this.namedParameterOperations = mock(NamedParameterJdbcOperations.class);
    this.template = new SimpleJdbcTemplate(operations);
    this.namedParameterTemplate = new SimpleJdbcTemplate(namedParameterOperations);
}
项目:spring-data-jdbc    文件:JdbcQueryLookupStrategy.java   
public CreateQueryLookupStrategy(SqlGenerator generator, NamedParameterJdbcOperations template, RowMapper rowMapper,
                                 TableDescription tableDescription) {
    super(generator, template, rowMapper, tableDescription);
}
项目:spring-data-jdbc    文件:CountJdbcRepositoryExecutionStrategy.java   
@Override
public Long execute(final NamedParameterJdbcOperations namedParameterJdbcOperations, final String query,
                    final Map<String, Object> parameters, final RowMapper rowMapper) {
    return namedParameterJdbcOperations.queryForObject(query, parameters, Long.class);
}
项目:spring-data-jdbc    文件:SingleQueryJdbcRepositoryExecutionStrategy.java   
@Override
public Object execute(final NamedParameterJdbcOperations namedParameterJdbcOperations, final String query,
                      final Map<String, Object> parameters, final RowMapper rowMapper) {
    List result = namedParameterJdbcOperations.query(query, parameters, rowMapper);
    return CollectionUtils.isEmpty(result) ? null : result.get(0);
}
项目:spring-data-jdbc    文件:JdbcRepositoryExecutionStrategy.java   
Object execute(final NamedParameterJdbcOperations namedParameterJdbcOperations, final String query,
final Map<String, Object> parameters, final RowMapper rowMapper);
项目:spring-data-jdbc    文件:CollectionQueryJdbcRepositoryExecutionStrategy.java   
@Override
public Object execute(final NamedParameterJdbcOperations namedParameterJdbcOperations, final String query,
                      final Map<String, Object> parameters, final RowMapper rowMapper) {
    return namedParameterJdbcOperations.query(query, parameters, rowMapper);
}
项目:spring-data-jdbc    文件:ExistsJdbcRepositoryExecutionStrategy.java   
@Override
public Boolean execute(final NamedParameterJdbcOperations namedParameterJdbcOperations, final String query,
                       final Map<String, Object> parameters, final RowMapper rowMapper) {
    return namedParameterJdbcOperations.queryForObject(query, parameters, Long.class) > 0;
}
项目:spring-data-jdbc    文件:UpdateJdbcRepositoryExecutionStrategy.java   
@Override
public Object execute(final NamedParameterJdbcOperations namedParameterJdbcOperations, final String query,
                      final Map<String, Object> parameters, final RowMapper rowMapper) {
    namedParameterJdbcOperations.update(query, parameters);
    return null;
}
项目:spring-data-jdbc    文件:PageJdbcRepositoryExecutionStrategy.java   
@Override
public Object execute(final NamedParameterJdbcOperations namedParameterJdbcOperations, final String query,
                      final Map<String, Object> parameters, final RowMapper rowMapper) {
    return null;
}