本文整理了Java中org.sql2o.Query.throwOnMappingFailure
方法的一些代码示例,展示了Query.throwOnMappingFailure
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.throwOnMappingFailure
方法的具体详情如下:
包路径:org.sql2o.Query
类名称:Query
方法名:throwOnMappingFailure
暂无
代码示例来源:origin: lets-blade/blade-jdbc
public <T> T query(Class<T> type, String sql, Object... args) {
int pos = 1;
while (sql.contains(SQL_QM)) {
sql = sql.replaceFirst("\\?", ":p" + (pos++));
}
try (Connection con = getSql2o().open()) {
log.debug(EXECUTE_SQL_PREFIX + " => {}", sql);
log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(args));
this.cleanParam();
Query query = con.createQuery(sql).withParams(args).throwOnMappingFailure(false);
QueryMeta queryMeta = SqlBuilder.buildFindAllSql(this, null);
if (queryMeta.hasColumnMapping()) {
queryMeta.getColumnMapping().forEach(query::addColumnMapping);
}
return query.executeAndFetchFirst(type);
}
}
代码示例来源:origin: lets-blade/blade-jdbc
public <T> List<T> queryAll(Class<T> type, String sql, Object... args) {
int pos = 1;
while (sql.contains(SQL_QM)) {
sql = sql.replaceFirst("\\?", ":p" + (pos++));
}
PageRow pageRow = Base.pageLocal.get();
sql = SqlBuilder.appendPageParams(sql, pageRow);
args = args == null ? new Object[]{} : args;
try (Connection con = getSql2o().open()) {
log.debug(EXECUTE_SQL_PREFIX + " => {}", sql);
log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(args));
this.cleanParam();
Query query = con.createQuery(sql).withParams(args).throwOnMappingFailure(false);
QueryMeta queryMeta = SqlBuilder.buildFindAllSql(this, null);
if (queryMeta.hasColumnMapping()) {
queryMeta.getColumnMapping().forEach(query::addColumnMapping);
}
return query.executeAndFetch(type);
}
}
代码示例来源:origin: lets-blade/blade-jdbc
public <T extends ActiveRecord> T find() {
QueryMeta queryMeta = SqlBuilder.buildFindSql(this);
Class<T> type = (Class<T>) getClass();
try (Connection con = getSql2o().open()) {
this.cleanParam();
log.debug(EXECUTE_SQL_PREFIX + " => {}", queryMeta.getSql());
log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(queryMeta.getParams()));
Query query = con.createQuery(queryMeta.getSql()).withParams(queryMeta.getParams()).throwOnMappingFailure(false);
if (queryMeta.hasColumnMapping()) {
queryMeta.getColumnMapping().forEach(query::addColumnMapping);
}
return query.executeAndFetchFirst(type);
}
}
代码示例来源:origin: lets-blade/blade-jdbc
public <T> List<T> findAll(Class<T> type, Supplier<ConditionEnum>... conditions) {
QueryMeta queryMeta = SqlBuilder.buildFindAllSql(this, conditions);
try (Connection con = getSql2o().open()) {
log.debug(EXECUTE_SQL_PREFIX + " => {}", queryMeta.getSql());
log.debug(PARAMETER_PREFIX + " => {}", Arrays.toString(queryMeta.getParams()));
this.cleanParam();
Query query = con.createQuery(queryMeta.getSql()).withParams(queryMeta.getParams()).throwOnMappingFailure(false);
if (queryMeta.hasColumnMapping()) {
queryMeta.getColumnMapping().forEach(query::addColumnMapping);
}
return query.executeAndFetch(type);
}
}
代码示例来源:origin: lets-blade/blade-jdbc
public <T> T find(Class<T> type, Serializable id) {
String sql = "SELECT * FROM " + getTableName() + " WHERE " + getPk() + " = :p1";
QueryMeta queryMeta = new QueryMeta();
SqlBuilder.mapping(queryMeta, this.getClass());
try (Connection con = getSql2o().open()) {
this.cleanParam();
log.debug(EXECUTE_SQL_PREFIX + " => {}", sql);
log.debug(PARAMETER_PREFIX + " => [{}]", id);
Query query = con.createQuery(sql).withParams(id).throwOnMappingFailure(false);
if (queryMeta.hasColumnMapping()) {
queryMeta.getColumnMapping().forEach(query::addColumnMapping);
}
return query.executeAndFetchFirst(type);
}
}
代码示例来源:origin: biezhi/anima
/**
* Querying a List<Map>
*
* @param sql sql statement
* @param params params
* @return List<Map>
*/
public List<Map<String, Object>> queryListMap(String sql, Object[] params) {
Connection conn = getConn();
try {
return conn.createQuery(sql)
.withParams(params)
.setAutoDeriveColumnNames(true)
.throwOnMappingFailure(false)
.executeAndFetchTable()
.asList();
} finally {
this.closeConn(conn);
this.clean(null);
}
}
代码示例来源:origin: biezhi/anima
/**
* Querying a list
*
* @param type model type
* @param sql sql statement
* @param params params
* @param <S>
* @return List<S>
*/
public <S> List<S> queryList(Class<S> type, String sql, Object[] params) {
Connection conn = getConn();
try {
return conn.createQuery(sql)
.withParams(params)
.setColumnMappings(computeModelColumnMappings(type))
.throwOnMappingFailure(false)
.executeAndFetch(type);
} finally {
this.closeConn(conn);
this.clean(null);
}
}
代码示例来源:origin: biezhi/anima
/**
* Querying a model
*
* @param type model type
* @param sql sql statement
* @param params params
* @param <S>
* @return S
*/
public <S> S queryOne(Class<S> type, String sql, Object[] params) {
Connection conn = getConn();
try {
Query query = conn.createQuery(sql)
.withParams(params)
.setAutoDeriveColumnNames(true)
.throwOnMappingFailure(false);
return ifReturn(AnimaUtils.isBasicType(type),
() -> query.executeScalar(type),
() -> query.executeAndFetchFirst(type));
} finally {
this.closeConn(conn);
this.clean(null);
}
}
代码示例来源:origin: biezhi/anima
.withParams(params)
.setAutoDeriveColumnNames(true)
.throwOnMappingFailure(false)
.executeAndFetch(modelClass);
内容来源于网络,如有侵权,请联系作者删除!