Search in sources :

Example 16 with BimserverLockConflictException

use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.

the class UpdatePluginBundle method execute.

@Override
public Void execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException, ServerException {
    MavenPluginLocation mavenPluginLocation = bimServer.getMavenPluginRepository().getPluginLocation(repository, groupId, artifactId);
    try {
        Path jarFile = mavenPluginLocation.getVersionJar(version);
        Path pomFile = mavenPluginLocation.getVersionPom(version);
        try {
            List<SPluginInformation> plugins = null;
            try {
                plugins = bimServer.getPluginManager().getPluginInformationFromPluginFile(new ByteArrayInputStream(mavenPluginLocation.getVersionPluginXml(version)));
            } catch (ArtifactResolutionException e) {
                plugins = bimServer.getPluginManager().getPluginInformationFromJar(jarFile);
            }
            // IfcModelInterface allOfType = getDatabaseSession().getAllOfType(StorePackage.eINSTANCE.getPluginDescriptor(), OldQuery.getDefault());
            // for (SPluginInformation sPluginInformation : plugins) {
            // update plugin information with data from potentially existing plugins
            // }
            bimServer.getPluginManager().update(mavenPluginLocation.getPluginVersionIdentifier(version), mavenPluginLocation.getPluginBundle(version), mavenPluginLocation.getPluginBundleVersion(version), jarFile, pomFile, plugins);
        } catch (Exception e) {
            throw new UserException(e);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        throw new UserException(e);
    }
    return null;
}
Also used : Path(java.nio.file.Path) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenPluginLocation(org.bimserver.plugins.MavenPluginLocation) ByteArrayInputStream(java.io.ByteArrayInputStream) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) 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) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException)

Example 17 with BimserverLockConflictException

use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.

the class Schema method upgradeDatabase.

public void upgradeDatabase(Database database, int version, DatabaseSession databaseSession) {
    LOGGER.info("Upgrading database to version " + version);
    // initSubClasses();
    for (Change change : changes) {
        try {
            change.change(database, databaseSession);
            change.doSchemaChanges(this);
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    }
    try {
        database.setDatabaseVersion(version, databaseSession);
    } catch (BimserverLockConflictException e) {
        LOGGER.error("", e);
    }
}
Also used : Change(org.bimserver.database.migrations.change.Change) NewPackageChange(org.bimserver.database.migrations.change.NewPackageChange) NewEnumChange(org.bimserver.database.migrations.change.NewEnumChange) NewAttributeChange(org.bimserver.database.migrations.change.NewAttributeChange) AddIndexChange(org.bimserver.database.migrations.change.AddIndexChange) NewClassChange(org.bimserver.database.migrations.change.NewClassChange) NewReferenceChange(org.bimserver.database.migrations.change.NewReferenceChange) NewClassBulkChange(org.bimserver.database.migrations.change.NewClassBulkChange) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) IOException(java.io.IOException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException)

Example 18 with BimserverLockConflictException

use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.

the class AddIndexChange method change.

@Override
public void change(Database database, DatabaseSession databaseSession) throws NotImplementedException, BimserverDatabaseException {
    EClass eClass = eStructuralFeature.getEContainingClass();
    KeyValueStore keyValueStore = database.getKeyValueStore();
    for (EClass subClass : schema.getSubClasses(eClass)) {
        try {
            if (subClass.getEAnnotation("nodatabase") == null) {
                String indexTableName = subClass.getEPackage().getName() + "_" + subClass.getName() + "_" + eStructuralFeature.getName();
                boolean transactional = !(subClass.getEPackage() == Ifc4Package.eINSTANCE || subClass.getEPackage() == Ifc2x3tc1Package.eINSTANCE);
                keyValueStore.createIndexTable(indexTableName, databaseSession, transactional);
                RecordIterator recordIterator = keyValueStore.getRecordIterator(subClass.getEPackage().getName() + "_" + subClass.getName(), databaseSession);
                try {
                    Record record = recordIterator.next();
                    while (record != null) {
                        ByteBuffer buffer = ByteBuffer.wrap(record.getValue());
                        byte[] featureBytes = databaseSession.extractFeatureBytes(databaseSession, buffer, subClass, eStructuralFeature);
                        if (featureBytes != null) {
                            keyValueStore.store(indexTableName, featureBytes, record.getKey(), 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 19 with BimserverLockConflictException

use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.

the class BerkeleyKeyValueStore method store.

@Override
public void store(String tableName, byte[] key, byte[] value, int offset, int length, DatabaseSession databaseSession) throws BimserverDatabaseException, BimserverLockConflictException {
    DatabaseEntry dbKey = new DatabaseEntry(key);
    DatabaseEntry dbValue = new DatabaseEntry(value, offset, length);
    try {
        TableWrapper tableWrapper = getTableWrapper(tableName);
        tableWrapper.getDatabase().put(getTransaction(databaseSession, tableWrapper), dbKey, dbValue);
    } catch (LockConflictException e) {
        throw new BimserverLockConflictException(e);
    } catch (DatabaseException e) {
        throw new BimserverDatabaseException("", e);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 20 with BimserverLockConflictException

use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.

the class BerkeleySearchingRecordIterator method last.

@Override
public Record last() throws BimserverLockConflictException {
    if (nextStartSearchingAt != null) {
        return getFirstNext(nextStartSearchingAt);
    }
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    if (onlyKeys) {
        value.setPartial(0, 0, true);
    }
    try {
        OperationStatus next = cursor.getLast(key, value, LockMode.DEFAULT);
        if (next == OperationStatus.SUCCESS) {
            byte[] firstBytes = new byte[mustStartWith.length];
            System.arraycopy(key.getData(), 0, firstBytes, 0, mustStartWith.length);
            if (Arrays.equals(firstBytes, mustStartWith)) {
                return new BerkeleyRecord(key, value);
            }
        }
    } catch (LockConflictException e) {
        throw new BimserverLockConflictException(e);
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException)

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