use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method storeNoOverwrite.
@Override
public void storeNoOverwrite(String tableName, byte[] key, byte[] value, int index, int length, DatabaseSession databaseSession) throws BimserverDatabaseException, BimserverLockConflictException, BimserverConcurrentModificationDatabaseException {
DatabaseEntry dbKey = new DatabaseEntry(key);
DatabaseEntry dbValue = new DatabaseEntry(value, index, length);
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
OperationStatus putNoOverwrite = tableWrapper.getDatabase().putNoOverwrite(getTransaction(databaseSession, tableWrapper), dbKey, dbValue);
if (putNoOverwrite == OperationStatus.KEYEXIST) {
// TODO temporary test
tableWrapper.getDatabase().put(getTransaction(databaseSession, tableWrapper), dbKey, dbValue);
ByteBuffer keyBuffer = ByteBuffer.wrap(key);
if (key.length == 16) {
int pid = keyBuffer.getInt();
long oid = keyBuffer.getLong();
int rid = -keyBuffer.getInt();
LOGGER.warn("Key exists: pid: " + pid + ", oid: " + oid + ", rid: " + rid + ", " + databaseSession.getEClassForOid(oid).getName());
throw new BimserverConcurrentModificationDatabaseException("Key exists: pid: " + pid + ", oid: " + oid + ", rid: " + rid);
} else {
LOGGER.warn("Key exists");
// throw new BimserverConcurrentModificationDatabaseException("Key exists: " );
}
}
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
throw new BimserverDatabaseException("", e);
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method get.
@Override
public byte[] get(String tableName, byte[] keyBytes, DatabaseSession databaseSession) throws BimserverDatabaseException {
DatabaseEntry key = new DatabaseEntry(keyBytes);
DatabaseEntry value = new DatabaseEntry();
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
OperationStatus operationStatus = tableWrapper.getDatabase().get(getTransaction(databaseSession, tableWrapper), key, value, getLockMode(tableWrapper));
if (operationStatus == OperationStatus.SUCCESS) {
return value.getData();
}
} catch (DatabaseException e) {
LOGGER.error("", e);
}
return null;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class BerkeleyTransaction method commit.
@Override
public void commit() throws BimserverLockConflictException, BimserverDatabaseException {
try {
transaction.commit();
transactionAlive = false;
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
throw new BimserverDatabaseException(e);
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class NewAttributeChange method change.
@Override
public void change(Database database, DatabaseSession databaseSession) throws NotImplementedException, BimserverDatabaseException {
EClass eClass = eAttribute.getEContainingClass();
KeyValueStore keyValueStore = database.getKeyValueStore();
for (EClass subClass : schema.getSubClasses(eClass)) {
try {
// No data migration if the database is new
if (subClass.getEAnnotation("nodatabase") == null) {
RecordIterator recordIterator = keyValueStore.getRecordIterator(subClass.getEPackage().getName() + "_" + subClass.getName(), databaseSession);
try {
Record record = recordIterator.next();
while (record != null) {
ByteBuffer buffer = ByteBuffer.wrap(record.getValue());
PackageMetaData packageMetaData = database.getMetaDataManager().getPackageMetaData(subClass.getEPackage().getName());
int newUnsettedLength = packageMetaData.getUnsettedLength(subClass);
int previousUnsettedLength = packageMetaData.getUnsettedLength(subClass, eAttribute);
byte[] unsetted = new byte[newUnsettedLength];
buffer.get(unsetted, 0, previousUnsettedLength);
int fieldCounter = 0;
for (EStructuralFeature feature : subClass.getEAllStructuralFeatures()) {
if (packageMetaData.useForDatabaseStorage(subClass, feature)) {
if (feature == eAttribute) {
unsetted[fieldCounter / 8] |= (1 << (fieldCounter % 8));
}
fieldCounter++;
}
}
int extra = 0;
ByteBuffer newBuffer = ByteBuffer.allocate(record.getValue().length + (newUnsettedLength - previousUnsettedLength) + extra);
newBuffer.put(unsetted);
buffer.position(previousUnsettedLength);
newBuffer.put(buffer);
keyValueStore.store(subClass.getEPackage().getName() + "_" + subClass.getName(), record.getKey(), newBuffer.array(), databaseSession);
record = recordIterator.next();
}
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} finally {
recordIterator.close();
}
}
} catch (BimserverLockConflictException e) {
LOGGER.error("", e);
}
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class NewClassBulkChange method change.
@Override
public void change(Database database, DatabaseSession databaseSession) throws BimserverDatabaseException {
boolean transactional = !(ePackage == Ifc2x3tc1Package.eINSTANCE || ePackage == Ifc4Package.eINSTANCE || ePackage == GeometryPackage.eINSTANCE);
LOGGER.info("Creating " + eClasses.size() + " " + (transactional ? "transactional" : "non transactional") + " tables for package " + ePackage.getName());
for (EClass eClass : eClasses) {
String tableName = eClass.getEPackage().getName() + "_" + eClass.getName();
if (eClass.getEAnnotation("nodatabase") == null) {
try {
boolean created = database.createTable(eClass, databaseSession, transactional);
if (!created) {
throw new BimserverDatabaseException("Could not create table " + tableName);
}
// for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) {
// if (eStructuralFeature.getEAnnotation("index") != null) {
// database.createIndexTable(eClass, eStructuralFeature, databaseSession);
// }
// }
} catch (BimserverLockConflictException e) {
LOGGER.error("", e);
}
}
}
}
Aggregations