Search in sources :

Example 11 with BimserverLockConflictException

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);
            }
        }
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException)

Example 12 with BimserverLockConflictException

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);
        }
    }
}
Also used : RecordIterator(org.bimserver.database.RecordIterator) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) KeyValueStore(org.bimserver.database.KeyValueStore) Record(org.bimserver.database.Record) ByteBuffer(java.nio.ByteBuffer) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException)

Example 13 with BimserverLockConflictException

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;
}
Also used : MavenPluginLocation(org.bimserver.plugins.MavenPluginLocation) MavenPluginBundle(org.bimserver.plugins.MavenPluginBundle) UserException(org.bimserver.shared.exceptions.UserException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 14 with BimserverLockConflictException

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) UserException(org.bimserver.shared.exceptions.UserException) LocalMavenPluginBundle(org.bimserver.plugins.LocalMavenPluginBundle) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) UserException(org.bimserver.shared.exceptions.UserException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 15 with BimserverLockConflictException

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();
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) RecordIterator(org.bimserver.database.RecordIterator) EClass(org.eclipse.emf.ecore.EClass) AtomicLong(java.util.concurrent.atomic.AtomicLong) Record(org.bimserver.database.Record) ByteBuffer(java.nio.ByteBuffer) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException)

Aggregations

BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)23 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)17 DatabaseException (com.sleepycat.je.DatabaseException)8 LockConflictException (com.sleepycat.je.LockConflictException)8 UserException (org.bimserver.shared.exceptions.UserException)7 DatabaseEntry (com.sleepycat.je.DatabaseEntry)6 ByteBuffer (java.nio.ByteBuffer)5 EClass (org.eclipse.emf.ecore.EClass)5 OperationStatus (com.sleepycat.je.OperationStatus)4 IOException (java.io.IOException)4 KeyValueStore (org.bimserver.database.KeyValueStore)4 Record (org.bimserver.database.Record)4 RecordIterator (org.bimserver.database.RecordIterator)4 User (org.bimserver.models.store.User)4 ServerException (org.bimserver.shared.exceptions.ServerException)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 DatabaseSession (org.bimserver.database.DatabaseSession)3 SPluginInformation (org.bimserver.interfaces.objects.SPluginInformation)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2