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();
}
}
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();
}
}
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();
}
}
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();
}
}
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;
}
Aggregations