@Test public void testQueryWithoutEnoughParams() { MappingSqlQuery<Integer> query = new MappingSqlQuery<Integer>() { @Override protected Integer mapRow(ResultSet rs, int rownum) throws SQLException { return rs.getInt(1); } }; query.setDataSource(dataSource); query.setSql(SELECT_ID_WHERE); query.declareParameter(new SqlParameter(COLUMN_NAMES[0], COLUMN_TYPES[0])); query.declareParameter(new SqlParameter(COLUMN_NAMES[1], COLUMN_TYPES[1])); query.compile(); thrown.expect(InvalidDataAccessApiUsageException.class); query.execute(); }
/** * Analogous to the SqlQuery.execute([]) method. This is a * generic method to execute a query, taken a number of arguments. * @param parameters array of parameters. These will be objects or * object wrapper types for primitives. * @return the value of the function */ public int run(Object... parameters) { Object obj = super.findObject(parameters); if (!(obj instanceof Number)) { throw new TypeMismatchDataAccessException("Couldn't convert result object [" + obj + "] to int"); } return ((Number) obj).intValue(); }
/** * This method is implemented to invoke the simpler mapRow * template method, ignoring parameters. * @see #mapRow(ResultSet, int) */ @Override @Nullable protected final T mapRow(ResultSet rs, int rowNum, @Nullable Object[] parameters, @Nullable Map<?, ?> context) throws SQLException { return mapRow(rs, rowNum); }
@Test public void testQueryWithMissingMapParams() { MappingSqlQuery<Integer> query = new MappingSqlQuery<Integer>() { @Override protected Integer mapRow(ResultSet rs, int rownum) throws SQLException { return rs.getInt(1); } }; query.setDataSource(dataSource); query.setSql(SELECT_ID_WHERE); query.declareParameter(new SqlParameter(COLUMN_NAMES[0], COLUMN_TYPES[0])); query.declareParameter(new SqlParameter(COLUMN_NAMES[1], COLUMN_TYPES[1])); query.compile(); thrown.expect(InvalidDataAccessApiUsageException.class); query.executeByNamedParam(Collections.singletonMap(COLUMN_NAMES[0], "value")); }
public List<Integer> getRunningTenants() { return getRunningTenants.execute(); }
"SELECT * FROM plugin_configuration WHERE tenantId = ? AND assocTypeId = ? AND pluginId = ? AND " + "pluginVersion = ? AND name = ?", pluginRegistry); readConfiguration.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); readConfiguration.declareParameter(new SqlParameter("assocTypeId", Types.INTEGER)); readConfiguration.declareParameter(new SqlParameter("pluginId", Types.VARCHAR)); readConfiguration.declareParameter(new SqlParameter("pluginVersion", Types.VARCHAR)); readConfiguration.declareParameter(new SqlParameter("name", Types.VARCHAR)); readConfiguration.compile(); readConfigurations.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); readConfigurations.declareParameter(new SqlParameter("assocTypeId", Types.INTEGER)); readConfigurations.declareParameter(new SqlParameter("pluginId", Types.VARCHAR)); readConfigurations.declareParameter(new SqlParameter("pluginVersion", Types.VARCHAR)); readConfigurations.compile(); readActiveConfiguration.declareParameter(new SqlParameter("tenantId", Types.INTEGER)); readActiveConfiguration.declareParameter(new SqlParameter("assocTypeId", Types.INTEGER)); readActiveConfiguration.compile();
public UserQuery(DataSource ds, String sql) { super(ds, sql); if (sql.equals(USER_QUERY_BY_ID)) { super.declareParameter(new SqlParameter("user id", Types.VARCHAR)); } else if (sql.equals(USER_QUERY_BY_NAME)) { super.declareParameter(new SqlParameter("user name", Types.VARCHAR)); } compile(); }
getRunningTenants.compile();
public Conference go() { List<Conference> confs= super.execute(slug); if(!confs.isEmpty()){ return confs.get(0); } return null; }
QUERY_GET_ITEMIDS.declareParameter(new SqlParameter("tenantId1", Types.INTEGER)); QUERY_GET_ITEMIDS.declareParameter(new SqlParameter("item1TypeId", Types.INTEGER)); QUERY_GET_ITEMIDS.declareParameter(new SqlParameter("tenantId2", Types.INTEGER)); QUERY_GET_ITEMIDS.declareParameter(new SqlParameter("item2TypeId", Types.INTEGER)); QUERY_GET_ITEMIDS.compile();
IncrementerValueQuery(DataSource ds) { super(ds, "SELECT SEQ_VL FROM UP_SEQ WHERE SEQ_NM=?"); super.declareParameter(new SqlParameter(Types.VARCHAR)); compile(); }
/** * Convenience method to lookup the acl_permission applying to a given acl_object_identity.id and * acl_permission.recipient. * * @param aclObjectIdentityId to locate * @param recipient to locate * * @return the acl_permission.id of the record, or -1 if not found * * @throws DataAccessException DOCUMENT ME! */ private long lookupPermissionId(long aclObjectIdentityId, Object recipient) throws DataAccessException { List list = lookupPermissionIdMapping.execute(new Object[] {new Long(aclObjectIdentityId), recipient}); if (list.size() == 0) { return -1; } return ((Long) list.get(0)).longValue(); }
public NamedConfiguration readActiveConfiguration(int tenantId, int assocTypeId) { return readActiveConfiguration.findObject(tenantId, assocTypeId); }
/** * This method is implemented to invoke the simpler mapRow * template method, ignoring parameters. * @see #mapRow(ResultSet, int) */ @Override protected final T mapRow(ResultSet rs, int rowNum, Object[] parameters, Map context) throws SQLException { return mapRow(rs, rowNum); }
/** * Executes the <tt>usersByUsernameQuery</tt> and returns a list of UserDetails objects (there should normally only be one matching user). */ @SuppressWarnings("unchecked") @Override protected List loadUsersByUsername(String username) { this.ocUsersByUsernameMapping = new OcUsersByUsernameMapping(getDataSource()); return ocUsersByUsernameMapping.execute(username); }
public Conference go() { return super.findObject(id); }
/** * This method is implemented to invoke the simpler mapRow * template method, ignoring parameters. * @see #mapRow(ResultSet, int) */ @Override @Nullable protected final T mapRow(ResultSet rs, int rowNum, @Nullable Object[] parameters, @Nullable Map<?, ?> context) throws SQLException { return mapRow(rs, rowNum); }
/** * Convenience method that obtains a given acl_object_identity record. * * @param aclObjectIdentity to lookup * * @return details of the record * * @throws DataRetrievalFailureException if record could not be found */ private AclDetailsHolder lookupAclDetailsHolder(AclObjectIdentity aclObjectIdentity) throws DataRetrievalFailureException { String aclObjectIdentityString = convertAclObjectIdentityToString(aclObjectIdentity); // Lookup the object's main properties from the RDBMS (guaranteed no nulls) List objects = objectProperties.execute(aclObjectIdentityString); if (objects.size() == 0) { throw new DataRetrievalFailureException("aclObjectIdentity not found: " + aclObjectIdentityString); } // Should only be one record return (AclDetailsHolder) objects.get(0); }
/** * Analogous to the SqlQuery.execute([]) method. This is a * generic method to execute a query, taken a number of arguments. * @param parameters array of parameters. These will be objects or * object wrapper types for primitives. * @return the value of the function */ public int run(Object... parameters) { Object obj = super.findObject(parameters); if (!(obj instanceof Number)) { throw new TypeMismatchDataAccessException("Couldn't convert result object [" + obj + "] to int"); } return ((Number) obj).intValue(); }
public List<NamedConfiguration> readConfigurations(int tenantId, int assocTypeId, PluginId pluginId) { Preconditions.checkNotNull(pluginId); Preconditions.checkNotNull(pluginId.getUri()); Preconditions.checkNotNull(pluginId.getVersion()); return readConfigurations.execute(tenantId, assocTypeId, pluginId.getUri().toASCIIString(), pluginId.getVersion().toString()); }