use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractDerbyMessageStore method storedSizeChange.
@Override
protected void storedSizeChange(final int delta) {
if (getPersistentSizeHighThreshold() > 0) {
synchronized (this) {
// the delta supplied is an approximation of a store size change. we don;t want to check the statistic every
// time, so we do so only when there's been enough change that it is worth looking again. We do this by
// assuming the total size will change by less than twice the amount of the message data change.
long newSize = _totalStoreSize += 3 * delta;
Connection conn = null;
try {
if (!_limitBusted && newSize > getPersistentSizeHighThreshold()) {
conn = newAutoCommitConnection();
_totalStoreSize = getSizeOnDisk(conn);
if (_totalStoreSize > getPersistentSizeHighThreshold()) {
_limitBusted = true;
_eventManager.notifyEvent(Event.PERSISTENT_MESSAGE_SIZE_OVERFULL);
}
} else if (_limitBusted && newSize < getPersistentSizeLowThreshold()) {
long oldSize = _totalStoreSize;
conn = newAutoCommitConnection();
_totalStoreSize = getSizeOnDisk(conn);
if (oldSize <= _totalStoreSize) {
reduceSizeOnDisk(conn);
_totalStoreSize = getSizeOnDisk(conn);
}
if (_totalStoreSize < getPersistentSizeLowThreshold()) {
_limitBusted = false;
_eventManager.notifyEvent(Event.PERSISTENT_MESSAGE_SIZE_UNDERFULL);
}
}
} catch (SQLException e) {
JdbcUtils.closeConnection(conn, getLogger());
throw new StoreException("Exception while processing store size change", e);
}
}
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCConfigurationStore method upgradeIfNecessary.
protected void upgradeIfNecessary(ConfiguredObject<?> parent) throws StoreException {
Connection connection = null;
try {
connection = newAutoCommitConnection();
boolean tableExists = tableExists(getConfigurationVersionTableName(), connection);
if (tableExists) {
int configVersion = getConfigVersion(connection);
getLogger().debug("Upgrader read existing config version {}", configVersion);
switch(configVersion) {
case 7:
upgradeFromV7(parent);
break;
default:
throw new UnsupportedOperationException("Cannot upgrade from configuration version : " + configVersion);
}
}
} catch (SQLException se) {
throw new StoreException("Failed to upgrade database", se);
} finally {
JdbcUtils.closeConnection(connection, getLogger());
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCConfigurationStore method insertConfiguredObject.
private void insertConfiguredObject(ConfiguredObjectRecord configuredObject, final Connection conn) throws StoreException {
try {
try (PreparedStatement stmt = conn.prepareStatement("SELECT object_type, attributes FROM " + getConfiguredObjectsTableName() + " where id = ?")) {
stmt.setString(1, configuredObject.getId().toString());
boolean exists;
try (ResultSet rs = stmt.executeQuery()) {
exists = rs.next();
}
// If we don't have any data in the result set then we can add this configured object
if (!exists) {
try (PreparedStatement insertStmt = conn.prepareStatement("INSERT INTO " + getConfiguredObjectsTableName() + " ( id, object_type, attributes) VALUES (?,?,?)")) {
insertStmt.setString(1, configuredObject.getId().toString());
insertStmt.setString(2, configuredObject.getType());
if (configuredObject.getAttributes() == null) {
insertStmt.setNull(3, Types.BLOB);
} else {
final Map<String, Object> attributes = configuredObject.getAttributes();
final ObjectMapper objectMapper = ConfiguredObjectJacksonModule.newObjectMapper(true);
byte[] attributesAsBytes = objectMapper.writeValueAsBytes(attributes);
ByteArrayInputStream bis = new ByteArrayInputStream(attributesAsBytes);
insertStmt.setBinaryStream(3, bis, attributesAsBytes.length);
}
insertStmt.execute();
}
writeHierarchy(configuredObject, conn);
}
}
} catch (IOException | SQLException e) {
throw new StoreException("Error inserting of configured object " + configuredObject + " into database: " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCConfigurationStore method create.
@Override
public void create(ConfiguredObjectRecord object) throws StoreException {
assertState(OPEN);
try {
Connection conn = newConnection();
try {
insertConfiguredObject(object, conn);
conn.commit();
} finally {
conn.close();
}
} catch (SQLException e) {
throw new StoreException("Error creating ConfiguredObject " + object, e);
}
}
use of org.apache.qpid.server.store.StoreException in project qpid-broker-j by apache.
the class AbstractJDBCConfigurationStore method remove.
@Override
public UUID[] remove(ConfiguredObjectRecord... objects) throws StoreException {
assertState(OPEN);
Collection<UUID> removed = new ArrayList<UUID>(objects.length);
try {
try (Connection conn = newAutoCommitConnection()) {
for (ConfiguredObjectRecord record : objects) {
if (removeConfiguredObject(record.getId(), conn) != 0) {
removed.add(record.getId());
}
}
}
} catch (SQLException e) {
throw new StoreException("Error deleting of configured objects " + Arrays.asList(objects) + " from database: " + e.getMessage(), e);
}
return removed.toArray(new UUID[removed.size()]);
}
Aggregations