use of herddb.client.HDBException in project herddb by diennea.
the class HerdDBPreparedStatement method doExecuteLargeUpdateWithParameters.
private long doExecuteLargeUpdateWithParameters(List<Object> actualParameters, boolean returnValues) throws SQLException {
try {
parent.discoverTableSpace(sql);
DMLResult result = parent.getConnection().executeUpdate(parent.getTableSpace(), sql, parent.ensureTransaction(), returnValues, actualParameters);
parent.statementFinished(result.transactionId);
lastUpdateCount = result.updateCount;
lastKey = result.key;
return lastUpdateCount;
} catch (ClientSideMetadataProviderException | HDBException err) {
throw SQLExceptionUtils.wrapException(err);
}
}
use of herddb.client.HDBException in project herddb by diennea.
the class HerdDBStatement method executeLargeUpdateImpl.
private long executeLargeUpdateImpl(String sql, boolean returnValues) throws SQLException {
try {
parent.discoverTableSpace(sql);
DMLResult result = parent.getConnection().executeUpdate(parent.getTableSpace(), sql, parent.ensureTransaction(), returnValues, Collections.emptyList());
parent.statementFinished(result.transactionId);
lastUpdateCount = result.updateCount;
lastKey = result.key;
return lastUpdateCount;
} catch (ClientSideMetadataProviderException | HDBException err) {
throw SQLExceptionUtils.wrapException(err);
}
}
use of herddb.client.HDBException in project herddb by diennea.
the class SQLExceptionUtils method wrapException.
public static SQLException wrapException(Exception exception) {
SQLException res;
if (exception instanceof HDBException) {
HDBException ex = (HDBException) exception;
res = new SQLException(ex.getMessage(), ex);
} else {
res = new SQLException(exception);
}
return res;
}
use of herddb.client.HDBException in project herddb by diennea.
the class TableSpaceManager method downloadTableSpaceData.
private void downloadTableSpaceData() throws MetadataStorageManagerException, DataStorageManagerException, LogNotAvailableException {
TableSpace tableSpaceData = metadataStorageManager.describeTableSpace(tableSpaceName);
String leaderId = tableSpaceData.leaderId;
if (this.nodeId.equals(leaderId)) {
throw new DataStorageManagerException("cannot download data of tableSpace " + tableSpaceName + " from myself");
}
Optional<NodeMetadata> leaderAddress = metadataStorageManager.listNodes().stream().filter(n -> n.nodeId.equals(leaderId)).findAny();
if (!leaderAddress.isPresent()) {
throw new DataStorageManagerException("cannot download data of tableSpace " + tableSpaceName + " from leader " + leaderId + ", no metadata found");
}
NodeMetadata nodeData = leaderAddress.get();
ClientConfiguration clientConfiguration = new ClientConfiguration(dbmanager.getTmpDirectory());
clientConfiguration.set(ClientConfiguration.PROPERTY_CLIENT_USERNAME, dbmanager.getServerToServerUsername());
clientConfiguration.set(ClientConfiguration.PROPERTY_CLIENT_PASSWORD, dbmanager.getServerToServerPassword());
try (HDBClient client = new HDBClient(clientConfiguration)) {
client.setClientSideMetadataProvider(new ClientSideMetadataProvider() {
@Override
public String getTableSpaceLeader(String tableSpace) throws ClientSideMetadataProviderException {
return leaderId;
}
@Override
public ServerHostData getServerHostData(String nodeId) throws ClientSideMetadataProviderException {
return new ServerHostData(nodeData.host, nodeData.port, "?", nodeData.ssl, Collections.emptyMap());
}
});
try (HDBConnection con = client.openConnection()) {
ReplicaFullTableDataDumpReceiver receiver = new ReplicaFullTableDataDumpReceiver(this);
int fetchSize = 10000;
con.dumpTableSpace(tableSpaceName, receiver, fetchSize, false);
long _start = System.currentTimeMillis();
boolean ok = receiver.join(1000 * 60 * 60);
if (!ok) {
throw new DataStorageManagerException("Cannot receive dump within " + (System.currentTimeMillis() - _start) + " ms");
}
if (receiver.getError() != null) {
throw new DataStorageManagerException("Error while receiving dump: " + receiver.getError(), receiver.getError());
}
this.actualLogSequenceNumber = receiver.logSequenceNumber;
LOGGER.log(Level.SEVERE, "After download local actualLogSequenceNumber is " + actualLogSequenceNumber);
} catch (ClientSideMetadataProviderException | HDBException | InterruptedException networkError) {
throw new DataStorageManagerException(networkError);
}
}
}
use of herddb.client.HDBException in project herddb by diennea.
the class HerdDBPreparedStatement method executeBatch.
@Override
public int[] executeBatch() throws SQLException {
try {
int[] results = new int[batch.size()];
int i = 0;
lastUpdateCount = 0;
parent.discoverTableSpace(sql);
List<DMLResult> dmlresults = parent.getConnection().executeUpdates(parent.getTableSpace(), sql, parent.ensureTransaction(), false, this.batch);
for (DMLResult dmlresult : dmlresults) {
results[i++] = (int) dmlresult.updateCount;
parent.statementFinished(dmlresult.transactionId);
lastUpdateCount += dmlresult.updateCount;
lastKey = dmlresult.key;
}
return results;
} catch (ClientSideMetadataProviderException | HDBException err) {
throw SQLExceptionUtils.wrapException(err);
} finally {
batch.clear();
}
}
Aggregations