Search in sources :

Example 76 with DatabaseSession

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

the class LowLevelServiceImpl method startTransaction.

@Override
public Long startTransaction(Long poid) throws UserException, ServerException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    int pid = -1;
    int rid = -1;
    long roid = -1;
    try {
        Project project = (Project) session.get(poid, OldQuery.getDefault());
        if (project == null) {
            throw new UserException("No project found with poid " + poid);
        }
        pid = project.getId();
        if (project.getLastRevision() != null) {
            Revision revision = project.getLastRevision();
            ConcreteRevision lastConcreteRevision = revision.getLastConcreteRevision();
            rid = lastConcreteRevision.getId();
            roid = revision.getOid();
        }
        LongTransaction longTransaction = getBimServer().getLongTransactionManager().newLongTransaction(getBimServer().getMetaDataManager().getPackageMetaData(project.getSchema()), poid, pid, rid, roid);
        return longTransaction.getTid();
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) Revision(org.bimserver.models.store.Revision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) ConcreteRevision(org.bimserver.models.store.ConcreteRevision) DatabaseSession(org.bimserver.database.DatabaseSession) UserException(org.bimserver.shared.exceptions.UserException) LongTransaction(org.bimserver.webservices.LongTransaction) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 77 with DatabaseSession

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

the class LowLevelServiceImpl method getDataObjectsByType.

@Override
public List<SDataObject> getDataObjectsByType(Long roid, String packageName, String className, Boolean flat) throws ServerException, UserException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    BimDatabaseAction<List<DataObject>> action = new GetDataObjectsByTypeDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, packageName, className, getAuthorization(), flat);
    try {
        return getBimServer().getSConverter().convertToSListDataObject(session.executeAndCommitAction(action));
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) GetDataObjectsByTypeDatabaseAction(org.bimserver.database.actions.GetDataObjectsByTypeDatabaseAction) ArrayList(java.util.ArrayList) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 78 with DatabaseSession

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

the class LowLevelServiceImpl method count.

public Integer count(Long roid, String className) throws UserException, ServerException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        CountDatabaseAction action = new CountDatabaseAction(getBimServer(), session, getInternalAccessMethod(), roid, className, getAuthorization());
        return session.executeAndCommitAction(action);
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) CountDatabaseAction(org.bimserver.database.actions.CountDatabaseAction) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 79 with DatabaseSession

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

the class LowLevelServiceImpl method getReference.

@Override
public Long getReference(Long tid, Long oid, String referenceName) throws ServerException, UserException {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        LongTransaction transaction = getBimServer().getLongTransactionManager().get(tid);
        EClass eClass = session.getEClassForOid(oid);
        IdEObject object = session.get(eClass, oid, new OldQuery(transaction.getPackageMetaData(), transaction.getPid(), transaction.getRid(), transaction.getRoid(), null, Deep.NO));
        if (object == null) {
            throw new UserException("No object of type " + eClass.getName() + " with oid " + oid + " found");
        }
        EStructuralFeature eStructuralFeature = object.eClass().getEStructuralFeature(referenceName);
        if (eStructuralFeature == null) {
            throw new UserException("No feature with name " + referenceName + " found on class " + object.eClass().getName());
        }
        IdEObject ref = (IdEObject) object.eGet(eStructuralFeature);
        if (ref == null) {
            return -1L;
        }
        return ref.getOid();
    } catch (Exception e) {
        return handleException(e);
    } finally {
        session.close();
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) DatabaseSession(org.bimserver.database.DatabaseSession) IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) UserException(org.bimserver.shared.exceptions.UserException) LongTransaction(org.bimserver.webservices.LongTransaction) UserException(org.bimserver.shared.exceptions.UserException) NoTransactionException(org.bimserver.webservices.NoTransactionException) ServerException(org.bimserver.shared.exceptions.ServerException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) OldQuery(org.bimserver.database.OldQuery)

Example 80 with DatabaseSession

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

the class LowLevelServiceImpl method commitTransaction.

@Override
public Long commitTransaction(Long tid, String comment) throws UserException, ServerException {
    requireAuthenticationAndRunningServer();
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        LongTransaction longTransaction = getBimServer().getLongTransactionManager().get(tid);
        if (longTransaction == null) {
            throw new UserException("No transaction with tid " + tid + " was found");
        }
        CommitTransactionDatabaseAction action = new CommitTransactionDatabaseAction(getBimServer(), session, getInternalAccessMethod(), getAuthorization(), longTransaction, comment);
        try {
            session.executeAndCommitAction(action);
            return action.getRevision().getOid();
        } catch (BimserverDatabaseException e) {
            LOGGER.error("", e);
        } finally {
            session.close();
        }
    } catch (NoTransactionException e) {
        LOGGER.error("", e);
    }
    return -1L;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) NoTransactionException(org.bimserver.webservices.NoTransactionException) DatabaseSession(org.bimserver.database.DatabaseSession) CommitTransactionDatabaseAction(org.bimserver.database.actions.CommitTransactionDatabaseAction) UserException(org.bimserver.shared.exceptions.UserException) LongTransaction(org.bimserver.webservices.LongTransaction)

Aggregations

DatabaseSession (org.bimserver.database.DatabaseSession)279 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)258 UserException (org.bimserver.shared.exceptions.UserException)228 ServerException (org.bimserver.shared.exceptions.ServerException)217 IOException (java.io.IOException)194 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)105 SerializerException (org.bimserver.plugins.serializers.SerializerException)105 UnsupportedEncodingException (java.io.UnsupportedEncodingException)103 MalformedURLException (java.net.MalformedURLException)103 MessagingException (javax.mail.MessagingException)103 AddressException (javax.mail.internet.AddressException)103 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)103 BcfException (org.opensourcebim.bcf.BcfException)103 User (org.bimserver.models.store.User)34 ArrayList (java.util.ArrayList)29 UserSettings (org.bimserver.models.store.UserSettings)29 Project (org.bimserver.models.store.Project)25 ServerSettings (org.bimserver.models.store.ServerSettings)21 ServerSettingsSetter (org.bimserver.database.actions.ServerSettingsSetter)18 SetServerSettingDatabaseAction (org.bimserver.database.actions.SetServerSettingDatabaseAction)18