public RawSqlSource(Configuration configuration, String sql, Class<?> parameterType) { SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration); Class<?> clazz = parameterType == null ? Object.class : parameterType; sqlSource = sqlSourceParser.parse(sql, clazz, new HashMap<String, Object>()); }
private SqlSource createSqlSource(Object parameterObject) { try { Class<?>[] parameterTypes = providerMethod.getParameterTypes(); String sql; if (parameterTypes.length == 0) { sql = (String) providerMethod.invoke(providerType.newInstance()); } else if (parameterTypes.length == 1 && (parameterObject == null || parameterTypes[0].isAssignableFrom(parameterObject.getClass()))) { sql = (String) providerMethod.invoke(providerType.newInstance(), parameterObject); } else if (parameterObject instanceof Map) { @SuppressWarnings("unchecked") Map<String, Object> params = (Map<String, Object>) parameterObject; sql = (String) providerMethod.invoke(providerType.newInstance(), extractProviderMethodArguments(params, providerMethodArgumentNames)); } else { throw new BuilderException("Error invoking SqlProvider method (" + providerType.getName() + "." + providerMethod.getName() + "). Cannot invoke a method that holds " + (parameterTypes.length == 1 ? "named argument(@Param)": "multiple arguments") + " using a specifying parameterObject. In this case, please specify a 'java.util.Map' object."); } Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); return sqlSourceParser.parse(sql, parameterType, new HashMap<String, Object>()); } catch (BuilderException e) { throw e; } catch (Exception e) { throw new BuilderException("Error invoking SqlProvider method (" + providerType.getName() + "." + providerMethod.getName() + "). Cause: " + e, e); } }
public ProviderSqlSource(Configuration config, Object provider) { String providerMethodName; try { this.sqlSourceParser = new SqlSourceBuilder(config); this.providerType = (Class<?>) provider.getClass().getMethod("type").invoke(provider); providerMethodName = (String) provider.getClass().getMethod("method").invoke(provider); for (Method m : this.providerType.getMethods()) { if (providerMethodName.equals(m.getName())) { if (m.getReturnType() == String.class) { if (providerMethod != null){ throw new BuilderException("Error creating SqlSource for SqlProvider. Method '" + providerMethodName + "' is found multiple in SqlProvider '" + this.providerType.getName() + "'. Sql provider method can not overload."); } this.providerMethod = m; this.providerMethodArgumentNames = new ParamNameResolver(config, m).getNames(); } } } } catch (BuilderException e) { throw e; } catch (Exception e) { throw new BuilderException("Error creating SqlSource for SqlProvider. Cause: " + e, e); } if (this.providerMethod == null) { throw new BuilderException("Error creating SqlSource for SqlProvider. Method '" + providerMethodName + "' not found in SqlProvider '" + this.providerType.getName() + "'."); } }
return sqlSourceParser.parse(replacePlaceholder(sql), parameterType, new HashMap<>()); } catch (BuilderException e) { throw e;
try { this.configuration = configuration; this.sqlSourceParser = new SqlSourceBuilder(configuration); this.providerType = (Class<?>) provider.getClass().getMethod("type").invoke(provider); providerMethodName = (String) provider.getClass().getMethod("method").invoke(provider);
public RawSqlSource(Configuration configuration, String sql, Class<?> parameterType) { SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration); Class<?> clazz = parameterType == null ? Object.class : parameterType; sqlSource = sqlSourceParser.parse(sql, clazz, new HashMap<>()); }
private SqlSource createSqlSource(Object parameterObject) { try { String sql; if (providerTakesParameterObject) { sql = (String) providerMethod.invoke(providerType.newInstance(), parameterObject); } else { sql = (String) providerMethod.invoke(providerType.newInstance()); } Class parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); return sqlSourceParser.parse(sql, parameterType); } catch (Exception e) { throw new BuilderException("Error invoking SqlProvider method (" + providerType.getName() + "." + providerMethod.getName() + "). Cause: " + e, e); } }
public InsertSqlSource(ComponentConfiguration componentConfiguration, Class<E> componentClass) { super(); this.componentClass = componentClass; this.sqlSourceParser = new SqlSourceBuilder(componentConfiguration); }
@Override public BoundSql getBoundSql(Object parameterObject) { DynamicContext context = new DynamicContext(configuration, parameterObject); rootSqlNode.apply(context); SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration); Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings()); BoundSql boundSql = sqlSource.getBoundSql(parameterObject); for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) { boundSql.setAdditionalParameter(entry.getKey(), entry.getValue()); } return boundSql; }
@SuppressWarnings("unchecked") private SqlSource createSqlSource(Object parameterObject) { try { String sql = buildUpdate((E) parameterObject); Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); return sqlSourceParser.parse(sql, parameterType, null); } catch (Exception e) { throw new BuilderException("Error invoking Count method for Update Cause: " + e, e); } }
public AbstractRsqlSqlSource(BeanConfiguration beanConfiguration, Class<?> beanClass) { super(); this.beanConfiguration = beanConfiguration; this.beanClass = beanClass; this.sqlSourceParser = new SqlSourceBuilder(beanConfiguration); }
@Override public BoundSql getBoundSql(Object parameterObject) { DynamicContext context = new DynamicContext(configuration, parameterObject); rootSqlNode.apply(context); SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(configuration); Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); SqlSource sqlSource = sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings()); BoundSql boundSql = sqlSource.getBoundSql(parameterObject); for (Map.Entry<String, Object> entry : context.getBindings().entrySet()) { boundSql.setAdditionalParameter(entry.getKey(), entry.getValue()); } return boundSql; }
@SuppressWarnings("unchecked") private SqlSource createSqlSource(Object parameterObject) { try { String sql = buildInsert((E) parameterObject); Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); return sqlSourceParser.parse(sql, parameterType, null); } catch (Exception e) { throw new BuilderException("Error invoking Count method for Insert Cause: " + e, e); } }
public InsertSqlSource(BeanConfiguration beanConfiguration, Class<?> beanClass) { super(); this.beanConfiguration = beanConfiguration; this.beanClass = beanClass; this.sqlSourceParser = new SqlSourceBuilder(beanConfiguration); }
private SqlSource buildSqlSource(Configuration configuration, String originalSql, Class<?> parameterType) { SqlSourceBuilder builder = new SqlSourceBuilder(configuration); return builder.parse(originalSql, parameterType, null); }
@SuppressWarnings("unchecked") private SqlSource createSqlSource(Object parameterObject) { try { String sql = buildInsert(parameterObject); Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass(); return sqlSourceParser.parse(sql, parameterType, null); } catch (Exception e) { throw new BuilderException("Error invoking Count method for Insert Cause: " + e, e); } }
public UpdateSqlSource(ComponentConfiguration componentConfiguration, Class<E> componentClass, String[] nlsProperties) { super(); this.componentClass = componentClass; this.nlsProperties = new HashSet<>(Arrays.asList(nlsProperties)); this.sqlSourceParser = new SqlSourceBuilder(componentConfiguration); }
public DeleteSqlSource(ComponentConfiguration componentConfiguration, Class<E> componentClass) { super(); SqlSourceBuilder sqlSourceParser = new SqlSourceBuilder(componentConfiguration); String sql = buildDelete(componentClass); sqlSource = sqlSourceParser.parse(sql, Map.class, new HashMap<>()); }
SqlSource sqlSource = sqlSourceParser.parse(sql, String.class, additionalParameters); BoundSql boundSql = sqlSource.getBoundSql(parameterObject); additionalParameters.forEach(boundSql::setAdditionalParameter);
public ProviderSqlSource(Configuration config, Object provider) { try { this.sqlSourceParser = new SqlSourceBuilder(config); this.providerType = (Class) provider.getClass().getMethod("type").invoke(provider); String providerMethod = (String) provider.getClass().getMethod("method").invoke(provider); for (Method m : providerType.getMethods()) { if (providerMethod.equals(m.getName())) { if (m.getParameterTypes().length < 2 && m.getReturnType() == String.class) { this.providerMethod = m; this.providerTakesParameterObject = m.getParameterTypes().length == 1; } } } } catch (Exception e) { throw new BuilderException("Error creating SqlSource for SqlProvider. Cause: " + e, e); } }