use of org.h2.command.dml.Set in project h2database by h2database.
the class DbUpgrade method connectOrUpgrade.
/**
* If the upgrade classes are present, upgrade the database, or connect
* using the old version (if the parameter NO_UPGRADE is set to true). If
* the database is upgraded, or if no upgrade is possible or needed, this
* methods returns null.
*
* @param url the database URL
* @param info the properties
* @return the connection if connected with the old version (NO_UPGRADE)
*/
public static Connection connectOrUpgrade(String url, Properties info) throws SQLException {
if (!UPGRADE_CLASSES_PRESENT) {
return null;
}
Properties i2 = new Properties();
i2.putAll(info);
// clone so that the password (if set as a char array) is not cleared
Object o = info.get("password");
if (o instanceof char[]) {
i2.put("password", StringUtils.cloneCharArray((char[]) o));
}
info = i2;
ConnectionInfo ci = new ConnectionInfo(url, info);
if (ci.isRemote() || !ci.isPersistent()) {
return null;
}
String name = ci.getName();
if (FileUtils.exists(name + Constants.SUFFIX_PAGE_FILE)) {
return null;
}
if (!FileUtils.exists(name + Constants.SUFFIX_OLD_DATABASE_FILE)) {
return null;
}
if (ci.removeProperty("NO_UPGRADE", false)) {
return connectWithOldVersion(url, info);
}
synchronized (DbUpgrade.class) {
upgrade(ci, info);
return null;
}
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class RunScript method execute.
/**
* Executes the SQL commands read from the reader against a database.
*
* @param conn the connection to a database
* @param reader the reader
* @return the last result set
*/
public static ResultSet execute(Connection conn, Reader reader) throws SQLException {
// can not close the statement because we return a result set from it
Statement stat = conn.createStatement();
ResultSet rs = null;
ScriptReader r = new ScriptReader(reader);
while (true) {
String sql = r.readStatement();
if (sql == null) {
break;
}
if (sql.trim().length() == 0) {
continue;
}
boolean resultSet = stat.execute(sql);
if (resultSet) {
if (rs != null) {
rs.close();
rs = null;
}
rs = stat.getResultSet();
}
}
return rs;
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class JdbcPreparedStatement method executeBatch.
/**
* Executes the batch.
* If one of the batched statements fails, this database will continue.
*
* @return the array of update counts
*/
@Override
public int[] executeBatch() throws SQLException {
try {
debugCodeCall("executeBatch");
if (batchParameters == null) {
// TODO batch: check what other database do if no parameters are
// set
batchParameters = New.arrayList();
}
batchIdentities = new MergedResultSet();
int size = batchParameters.size();
int[] result = new int[size];
boolean error = false;
SQLException next = null;
checkClosedForWrite();
try {
for (int i = 0; i < size; i++) {
Value[] set = batchParameters.get(i);
ArrayList<? extends ParameterInterface> parameters = command.getParameters();
for (int j = 0; j < set.length; j++) {
Value value = set[j];
ParameterInterface param = parameters.get(j);
param.setValue(value, false);
}
try {
result[i] = executeUpdateInternal();
// Cannot use own implementation, it returns batch identities
ResultSet rs = super.getGeneratedKeys();
batchIdentities.add(rs);
} catch (Exception re) {
SQLException e = logAndConvert(re);
if (next == null) {
next = e;
} else {
e.setNextException(next);
next = e;
}
result[i] = Statement.EXECUTE_FAILED;
error = true;
}
}
batchParameters = null;
if (error) {
throw new JdbcBatchUpdateException(next, result);
}
return result;
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class JdbcResultSet method updateBinaryStream.
/**
* Updates a column in the current or insert row.
*
* @param columnLabel the column label
* @param x the value
* @param length the number of characters
* @throws SQLException if the result set is closed or not updatable
*/
@Override
public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBinaryStream(" + quote(columnLabel) + ", x, " + length + "L);");
}
checkClosed();
Value v = conn.createBlob(x, length);
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class JdbcResultSet method updateBlob.
/**
* Updates a column in the current or insert row.
*
* @param columnLabel the column label
* @param x the value
* @throws SQLException if the result set is closed or not updatable
*/
@Override
public void updateBlob(String columnLabel, Blob x) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateBlob(" + quote(columnLabel) + ", x);");
}
checkClosed();
Value v;
if (x == null) {
v = ValueNull.INSTANCE;
} else {
v = conn.createBlob(x.getBinaryStream(), -1);
}
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
Aggregations