use of org.h2.command.dml.Insert in project h2database by h2database.
the class Recover method dumpLobMaps.
private void dumpLobMaps(PrintWriter writer, MVStore mv) {
lobMaps = mv.hasMap("lobData");
if (!lobMaps) {
return;
}
MVMap<Long, byte[]> lobData = mv.openMap("lobData");
StreamStore streamStore = new StreamStore(lobData);
MVMap<Long, Object[]> lobMap = mv.openMap("lobMap");
writer.println("-- LOB");
writer.println("CREATE TABLE IF NOT EXISTS " + "INFORMATION_SCHEMA.LOB_BLOCKS(" + "LOB_ID BIGINT, SEQ INT, DATA BINARY, " + "PRIMARY KEY(LOB_ID, SEQ));");
boolean hasErrors = false;
for (Entry<Long, Object[]> e : lobMap.entrySet()) {
long lobId = e.getKey();
Object[] value = e.getValue();
byte[] streamStoreId = (byte[]) value[0];
InputStream in = streamStore.get(streamStoreId);
int len = 8 * 1024;
byte[] block = new byte[len];
try {
for (int seq = 0; ; seq++) {
int l = IOUtils.readFully(in, block, block.length);
String x = StringUtils.convertBytesToHex(block, l);
if (l > 0) {
writer.println("INSERT INTO INFORMATION_SCHEMA.LOB_BLOCKS " + "VALUES(" + lobId + ", " + seq + ", '" + x + "');");
}
if (l != len) {
break;
}
}
} catch (IOException ex) {
writeError(writer, ex);
hasErrors = true;
}
}
writer.println("-- lobMap.size: " + lobMap.sizeAsLong());
writer.println("-- lobData.size: " + lobData.sizeAsLong());
if (hasErrors) {
writer.println("-- lobMap");
for (Long k : lobMap.keyList()) {
Object[] value = lobMap.get(k);
byte[] streamStoreId = (byte[]) value[0];
writer.println("-- " + k + " " + StreamStore.toString(streamStoreId));
}
writer.println("-- lobData");
for (Long k : lobData.keyList()) {
writer.println("-- " + k + " len " + lobData.get(k).length);
}
}
}
use of org.h2.command.dml.Insert in project h2database by h2database.
the class Db method upgradeDb.
Db upgradeDb() {
if (!upgradeChecked.contains(dbUpgrader.getClass())) {
// flag as checked immediately because calls are nested.
upgradeChecked.add(dbUpgrader.getClass());
JQDatabase model = dbUpgrader.getClass().getAnnotation(JQDatabase.class);
if (model.version() > 0) {
DbVersion v = new DbVersion();
DbVersion dbVersion = // (SCHEMA="" && TABLE="") == DATABASE
from(v).where(v.schema).is("").and(v.table).is("").selectFirst();
if (dbVersion == null) {
// database has no version registration, but model specifies
// version: insert DbVersion entry and return.
DbVersion newDb = new DbVersion(model.version());
insert(newDb);
} else {
// check to see if upgrade is required.
if ((model.version() > dbVersion.version) && (dbUpgrader != null)) {
// database is an older version than the model
boolean success = dbUpgrader.upgradeDatabase(this, dbVersion.version, model.version());
if (success) {
dbVersion.version = model.version();
update(dbVersion);
}
}
}
}
}
return this;
}
use of org.h2.command.dml.Insert 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.Insert 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);
}
}
use of org.h2.command.dml.Insert in project h2database by h2database.
the class JdbcResultSet method updateNCharacterStream.
/**
* 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 updateNCharacterStream(String columnLabel, Reader x, long length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("updateNCharacterStream(" + quote(columnLabel) + ", x, " + length + "L);");
}
checkClosed();
Value v = conn.createClob(x, length);
update(columnLabel, v);
} catch (Exception e) {
throw logAndConvert(e);
}
}
Aggregations