use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class FunctionTable method getValueResultSet.
private ValueResultSet getValueResultSet(Session session) {
functionExpr = functionExpr.optimize(session);
Value v = functionExpr.getValue(session);
if (v == ValueNull.INSTANCE) {
return null;
}
return (ValueResultSet) v;
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class Table method validateConvertUpdateSequence.
/**
* Validate all values in this row, convert the values if required, and
* update the sequence values if required. This call will also set the
* default values if required and set the computed column if there are any.
*
* @param session the session
* @param row the row
*/
public void validateConvertUpdateSequence(Session session, Row row) {
for (int i = 0; i < columns.length; i++) {
Value value = row.getValue(i);
Column column = columns[i];
Value v2;
if (column.getComputed()) {
// force updating the value
value = null;
v2 = column.computeValue(session, row);
}
v2 = column.validateConvertUpdateSequence(session, value);
if (v2 != value) {
row.setValue(i, v2);
}
}
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class Table method getDefaultValue.
/**
* Get or generate a default value for the given column.
*
* @param session the session
* @param column the column
* @return the value
*/
public Value getDefaultValue(Session session, Column column) {
Expression defaultExpr = column.getDefaultExpression();
Value v;
if (defaultExpr == null) {
v = column.validateConvertUpdateSequence(session, null);
} else {
v = defaultExpr.getValue(session);
}
return column.convert(v);
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class JdbcCallWorker method doWork.
@Override
public Integer doWork() {
Connection conn = null;
PreparedStatement stmt = null;
try {
DataSource dataSource = getDataSource();
Optional optional = Optional.build().shardName(shardName).readOnly(false);
if (trace.isDebugEnabled()) {
trace.debug("{0} Fetching connection from DataSource.", shardName);
}
conn = session.applyConnection(dataSource, optional);
attach(conn);
if (trace.isDebugEnabled()) {
trace.debug("{0} Preparing: {1};", shardName, sql);
}
stmt = conn.prepareStatement(sql);
attach(stmt);
applyQueryTimeout(stmt);
if (params != null) {
for (int i = 0, size = params.size(); i < size; i++) {
Value v = params.get(i);
v.set(stmt, i + 1);
if (trace.isDebugEnabled()) {
trace.debug("{0} setParameter: {1} -> {2};", shardName, i + 1, v.getSQL());
}
}
}
int rows = stmt.executeUpdate();
if (trace.isDebugEnabled()) {
trace.debug("{0} executeUpdate: {1} affected.", shardName, rows);
}
return rows;
} catch (SQLException e) {
StatementBuilder buff = new StatementBuilder();
buff.append(shardName).append(" executing executeUpdate error:").append(sql);
if (params != null && params.size() > 0) {
buff.append("\n{");
int i = 1;
for (Value v : params) {
buff.appendExceptFirst(", ");
buff.append(i++).append(": ").append(v.getSQL());
}
buff.append('}');
}
buff.append(';');
trace.error(e, buff.toString());
throw wrapException(sql, e);
}
}
use of com.wplatform.ddal.value.Value in project jdbc-shards by wplatform.
the class JdbcUpdateWorker method doWork.
@Override
public Integer doWork() {
Connection conn = null;
PreparedStatement stmt = null;
try {
DataSource dataSource = getDataSource();
Optional optional = Optional.build().shardName(shardName).readOnly(false);
if (trace.isDebugEnabled()) {
trace.debug("{0} Fetching connection from DataSource.", shardName);
}
conn = session.applyConnection(dataSource, optional);
attach(conn);
if (trace.isDebugEnabled()) {
trace.debug("{0} Preparing call: {1};", shardName, sql);
}
stmt = conn.prepareCall(sql);
attach(stmt);
applyQueryTimeout(stmt);
if (params != null) {
for (int i = 0, size = params.size(); i < size; i++) {
Value v = params.get(i);
v.set(stmt, i + 1);
if (trace.isDebugEnabled()) {
trace.debug("{0} setParameter: {1} -> {2};", shardName, i + 1, v.getSQL());
}
}
}
int rows = stmt.executeUpdate();
if (trace.isDebugEnabled()) {
trace.debug("{0} executeUpdate: {1} affected.", shardName, rows);
}
return rows;
} catch (SQLException e) {
StatementBuilder buff = new StatementBuilder();
buff.append(shardName).append(" executing executeUpdate error:").append(sql);
if (params != null && 0 < params.size()) {
buff.append("\n{");
int i = 1;
for (Value v : params) {
buff.appendExceptFirst(", ");
buff.append(i++).append(": ").append(v.getSQL());
}
buff.append('}');
}
buff.append(';');
trace.error(e, buff.toString());
throw wrapException(sql, e);
}
}
Aggregations