use of org.bimserver.webservices.LongTransaction in project BIMserver by opensourceBIM.
the class LowLevelServiceImpl method getReferences.
@SuppressWarnings("unchecked")
@Override
public List<Long> getReferences(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");
}
List<IdEObject> list = (List<IdEObject>) object.eGet(object.eClass().getEStructuralFeature(referenceName));
List<Long> oidList = new ArrayList<Long>();
for (IdEObject idEObject : list) {
oidList.add(idEObject.getOid());
}
return oidList;
} catch (Exception e) {
return handleException(e);
} finally {
session.close();
}
}
use of org.bimserver.webservices.LongTransaction 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.webservices.LongTransaction in project BIMserver by opensourceBIM.
the class LowLevelServiceImpl method createObject.
@Override
public Long createObject(Long tid, String className, Boolean generateGuid) throws UserException, ServerException {
requireAuthenticationAndRunningServer();
try {
LongTransaction longTransaction = getBimServer().getLongTransactionManager().get(tid);
if (longTransaction == null) {
throw new UserException("No transaction with tid " + tid + " was found");
}
try {
EClass eClass = ((Database) getBimServer().getDatabase()).getEClass(longTransaction.getPackageMetaData().getEPackage().getName(), className);
Long oid = getBimServer().getDatabase().newOid(eClass);
CreateObjectChange createObject = new CreateObjectChange(className, oid, eClass, generateGuid);
longTransaction.add(createObject);
return oid;
} catch (BimserverDatabaseException e) {
throw new UserException("Unknown type: \"" + className + "\"");
}
} catch (Exception e) {
return handleException(e);
}
}
use of org.bimserver.webservices.LongTransaction 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.webservices.LongTransaction 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