use of com.ctrip.platform.dal.exceptions.DalException in project dal by ctripcorp.
the class BatchUpdateTask method createTaskContext.
@Override
public BulkTaskContext<T> createTaskContext(DalHints hints, List<Map<String, ?>> daoPojos, List<T> rawPojos) throws DalException {
BulkTaskContext<T> taskContext = new BulkTaskContext<T>(rawPojos);
Map<String, Boolean> pojoFieldStatus = taskContext.isUpdatableEntity() ? filterUpdatableEntity(hints, rawPojos) : filterNullColumns(hints, daoPojos);
if (pojoFieldStatus.size() == 0)
throw new DalException(ErrorCode.ValidateFieldCount);
taskContext.setPojoFieldStatus(pojoFieldStatus);
return taskContext;
}
use of com.ctrip.platform.dal.exceptions.DalException in project dal by ctripcorp.
the class DalBulkTaskRequest method validate.
@Override
public void validate() throws SQLException {
if (null == rawPojos)
throw new DalException(ErrorCode.ValidatePojoList);
if (task == null)
throw new DalException(ErrorCode.ValidateTask);
dbShardMerger = task.createMerger();
daoPojos = task.getPojosFields(rawPojos);
taskContext = task.createTaskContext(hints, daoPojos, rawPojos);
}
use of com.ctrip.platform.dal.exceptions.DalException in project dal by ctripcorp.
the class DalSingleTaskRequest method validate.
@Override
public void validate() throws SQLException {
if (isList && null == rawPojos)
throw new DalException(ErrorCode.ValidatePojoList);
if (isList == false && null == rawPojo)
throw new DalException(ErrorCode.ValidatePojo);
if (task == null)
throw new DalException(ErrorCode.ValidateTask);
if (isList == false) {
rawPojos = new ArrayList<>(1);
rawPojos.add(rawPojo);
}
daoPojos = task.getPojosFields(rawPojos);
detectDistributedTransaction(logicDbName, hints, daoPojos);
}
use of com.ctrip.platform.dal.exceptions.DalException in project dal by ctripcorp.
the class SingleUpdateTask method execute.
@Override
public int execute(DalHints hints, Map<String, ?> fields, T rawPojo) throws SQLException {
if (fields.size() == 0)
throw new DalException(ErrorCode.ValidateFieldCount);
Map<String, ?> pks = getPrimaryKeys(fields);
Object version = getVersion(fields);
Map<String, ?> filted = null;
if (rawPojo instanceof UpdatableEntity)
filted = filterUpdatableEntity(hints, fields, getUpdatedColumns(rawPojo));
else
filted = filterNullColumns(hints, fields);
// If there is no columns changed, we will not perform update
if (filted.size() == 0)
return 0;
String updateSql = buildUpdateSql(getTableName(hints, fields), filted, hints);
StatementParameters parameters = new StatementParameters();
addParameters(parameters, filted);
addParameters(parameters, pks);
addVersion(parameters, version);
return client.update(updateSql, parameters, hints.setFields(fields));
}
use of com.ctrip.platform.dal.exceptions.DalException in project dal by ctripcorp.
the class DalTableDao method queryByPk.
/**
* Query by Primary key. The key column type should be Integer, Long, etc.
* For table that the primary key is not of Integer type, this method will
* fail.
*
* @param id The primary key in number format
* @param hints Additional parameters that instruct how DAL Client perform database operation.
* @return entity of this table. Null if no result found.
* @throws SQLException
*/
public T queryByPk(Number id, DalHints hints) throws SQLException {
if (parser.getPrimaryKeyNames().length != 1)
throw new DalException(ErrorCode.ValidatePrimaryKeyCount);
StatementParameters parameters = new StatementParameters();
parameters.set(1, parser.getPrimaryKeyNames()[0], getColumnType(parser.getPrimaryKeyNames()[0]), id);
return queryObject(new SelectSqlBuilder().where(pkSql).with(parameters).requireSingle().nullable(), hints);
}
Aggregations