use of org.bimserver.database.BimserverLockConflictException 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);
}
}
}
}
use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.
the class NewReferenceChange method change.
@Override
public void change(Database database, DatabaseSession databaseSession) throws NotImplementedException, BimserverDatabaseException {
EClass eClass = eReference.getEContainingClass();
KeyValueStore keyValueStore = database.getKeyValueStore();
for (EClass subClass : schema.getSubClasses(eClass)) {
try {
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());
int nrStartBytesBefore = (int) Math.ceil(nrFeaturesBefore / 8.0);
int nrStartBytesAfter = (int) Math.ceil((nrFeaturesBefore + 1) / 8.0);
byte x = buffer.get();
if (x != nrStartBytesBefore) {
throw new BimserverDatabaseException("Size to not match");
}
byte[] unsetted = new byte[nrStartBytesAfter];
buffer.get(unsetted, 0, x);
if (eReference.isUnsettable()) {
unsetted[(nrFeaturesBefore + 1) / 8] |= (1 << ((nrFeaturesBefore + 1) % 8));
}
int extra = 0;
if (!eReference.isUnsettable()) {
if (eReference.isMany()) {
extra = 4;
} else {
extra = 2;
}
}
ByteBuffer newBuffer = ByteBuffer.allocate(record.getValue().length + (nrStartBytesAfter - nrStartBytesBefore) + extra);
newBuffer.put((byte) nrStartBytesAfter);
newBuffer.put(unsetted);
buffer.position(1 + nrStartBytesBefore);
newBuffer.put(buffer);
if (!eReference.isUnsettable()) {
if (eReference.isMany()) {
newBuffer.putInt(0);
} else {
buffer.order(ByteOrder.LITTLE_ENDIAN);
newBuffer.putShort((short) -1);
buffer.order(ByteOrder.BIG_ENDIAN);
}
}
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.database.BimserverLockConflictException in project BIMserver by opensourceBIM.
the class InstallPluginBundle method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
LOGGER.info("Installing plugin " + repository + " " + groupId + "." + artifactId + "." + version);
MavenPluginLocation mavenPluginLocation = bimServer.getMavenPluginRepository().getPluginLocation(repository, groupId, artifactId);
if (version == null) {
String latestVersion = mavenPluginLocation.getLatestVersionString();
LOGGER.info("Using version " + latestVersion + " because no version given");
version = latestVersion;
}
try {
LOGGER.info(mavenPluginLocation.getRepository(version));
} catch (Exception e1) {
e1.printStackTrace();
}
MavenPluginBundle mavenPluginBundle = mavenPluginLocation.getMavenPluginBundle(version);
LOGGER.info(mavenPluginBundle.getVersion());
try {
bimServer.getPluginManager().install(mavenPluginBundle, plugins, false);
} catch (Exception e) {
LOGGER.error("", e);
throw new UserException(e);
}
return null;
}
use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.
the class InstallPluginBundleFromBytes method execute.
@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
LocalMavenPluginBundle mavenPluginBundle = new LocalMavenPluginBundle(data);
try {
List<SPluginInformation> pluginInformationFromPluginFile = bimServer.getPluginManager().getPluginInformationFromJar(new ByteArrayInputStream(data));
for (SPluginInformation sPluginInformation : pluginInformationFromPluginFile) {
sPluginInformation.setEnabled(true);
if (installAllPluginsForAllUsers) {
sPluginInformation.setInstallForAllUsers(true);
}
if (installAllPluginsForNewUsers) {
sPluginInformation.setInstallForNewUsers(true);
}
}
bimServer.getPluginManager().install(mavenPluginBundle, pluginInformationFromPluginFile, false);
} catch (Exception e) {
LOGGER.error("", e);
throw new UserException(e);
}
return null;
}
use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.
the class StreamingCheckinDatabaseAction method rollback.
public void rollback() throws BimserverDatabaseException {
// TODO do we need to remove indices too?
LOGGER.info("Rolling back");
int pid = newRevision.getProject().getId();
int rid = newRevision.getRid();
Map<EClass, Long> startOids = getDatabaseSession().getStartOids();
if (startOids == null) {
throw new BimserverDatabaseException("No objects changed");
}
int deleted = 0;
for (EClass eClass : startOids.keySet()) {
Long startOid = startOids.get(eClass);
ByteBuffer mustStartWith = ByteBuffer.wrap(new byte[4]);
mustStartWith.putInt(pid);
ByteBuffer startSearchWith = ByteBuffer.wrap(new byte[12]);
startSearchWith.putInt(pid);
startSearchWith.putLong(startOid);
String tableName = eClass.getEPackage().getName() + "_" + eClass.getName();
try {
if (!getDatabaseSession().getKeyValueStore().isTransactional(getDatabaseSession(), tableName)) {
// System.out.println("Checking " + tableName);
try (RecordIterator recordIterator = getDatabaseSession().getKeyValueStore().getRecordIterator(tableName, mustStartWith.array(), startSearchWith.array(), getDatabaseSession())) {
Record record = recordIterator.next();
while (record != null) {
// System.out.println("Deleting from " + tableName);
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
// pid
keyBuffer.getInt();
// oid
keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
if (keyRid == rid) {
getDatabaseSession().getKeyValueStore().delete(tableName, record.getKey(), getDatabaseSession());
deleted++;
}
record = recordIterator.next();
}
} catch (BimserverLockConflictException e) {
e.printStackTrace();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
}
}
} catch (BimserverDatabaseException e1) {
e1.printStackTrace();
}
}
LOGGER.info("Deleted " + deleted + " objects in rollback");
// getDatabaseSession().getKeyValueStore().sync();
}
Aggregations