use of org.bimserver.BimserverDatabaseException 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);
}
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class DatabaseReadingStackFrame method readList.
private Object readList(HashMapVirtualObject idEObject, ByteBuffer buffer, EStructuralFeature feature) throws BimserverDatabaseException {
if (feature.getEType() instanceof EEnum) {
} else if (feature.getEType() instanceof EClass) {
if (buffer.capacity() == 1 && buffer.get(0) == -1) {
buffer.position(buffer.position() + 1);
} else {
int listSize = buffer.getInt();
for (int i = 0; i < listSize; i++) {
if (feature.getEAnnotation("twodimensionalarray") != null) {
HashMapVirtualObject newObject = new HashMapVirtualObject(reusable, (EClass) feature.getEType());
buffer.order(ByteOrder.LITTLE_ENDIAN);
short cid = buffer.getShort();
buffer.order(ByteOrder.BIG_ENDIAN);
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass((short) (-cid));
if (referenceClass == null) {
throw new BimserverDatabaseException("No class found for cid " + (-cid));
}
EStructuralFeature eStructuralFeature = ((EClass) feature.getEType()).getEStructuralFeature("List");
Object result = readList(newObject, buffer, eStructuralFeature);
if (result != null) {
newObject.setAttribute(newObject.eClass().getEStructuralFeature("List"), result);
}
idEObject.setListItem(feature, i, newObject);
} else {
buffer.order(ByteOrder.LITTLE_ENDIAN);
short cid = buffer.getShort();
buffer.order(ByteOrder.BIG_ENDIAN);
if (cid == -1) {
// null, do nothing
} else if (cid < 0) {
// negative cid means value is
// embedded
// in record
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass((short) (-cid));
if (referenceClass == null) {
throw new BimserverDatabaseException("No class found for cid " + (-cid));
}
idEObject.setListItem(feature, i, readWrappedValue(feature, buffer, referenceClass));
idEObject.addUseForSerialization(feature, i);
} else if (cid > 0) {
// positive cid means value is a
// reference
// to another record
EClass referenceClass = queryObjectProvider.getDatabaseSession().getEClass(cid);
if (referenceClass == null) {
throw new BimserverDatabaseException("Cannot find class with cid " + cid);
}
buffer.position(buffer.position() - 2);
long rf = readReference(buffer, feature, referenceClass);
idEObject.setListItemReference(feature, i, referenceClass, rf, -1);
if (rf != -1) {
if (queryObjectProvider.hasReadOrIsGoingToRead((rf)) || queryObjectProvider.hasReadOrIsGoingToRead(referenceClass)) {
idEObject.addUseForSerialization(feature, i);
}
}
}
}
}
}
} else if (feature.getEType() instanceof EDataType) {
int listSize = buffer.getInt();
for (int i = 0; i < listSize; i++) {
Object reference = readPrimitiveValue(feature.getEType(), buffer);
if (reference != null) {
idEObject.setListItem(feature, i, reference);
}
}
}
return null;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class WarServerInitializer method contextInitialized.
public void contextInitialized(ServletContextEvent servletContextEvent) {
ServletContext servletContext = servletContextEvent.getServletContext();
Path homeDir = null;
if (servletContext.getAttribute("homedir") != null) {
homeDir = Paths.get((String) servletContext.getAttribute("homedir"));
}
if (homeDir == null && servletContext.getInitParameter("homedir") != null) {
homeDir = Paths.get(servletContext.getInitParameter("homedir"));
}
boolean autoMigrate = false;
if (servletContext.getAttribute("autoMigrate") != null) {
autoMigrate = (Boolean) servletContext.getAttribute("autoMigrate");
}
if (autoMigrate == false && servletContext.getInitParameter("autoMigrate") != null) {
autoMigrate = Boolean.valueOf(servletContext.getInitParameter("autoMigrate"));
}
String realPath = servletContext.getRealPath("/");
if (!realPath.endsWith("/")) {
realPath = realPath + "/";
}
Path baseDir = Paths.get(realPath + "WEB-INF");
if (homeDir == null) {
homeDir = baseDir;
}
ResourceFetcher resourceFetcher = new WarResourceFetcher(servletContext, homeDir);
BimServerConfig config = new BimServerConfig();
config.setAutoMigrate(autoMigrate);
config.setEnvironment(Environment.WAR);
config.setHomeDir(homeDir);
config.setResourceFetcher(resourceFetcher);
if (homeDir != null) {
// Basically doing this twice (also in BimServer.init), but this makes sure the logback.xml file is copied to the homedir
try {
BimServer.initHomeDir(config);
} catch (IOException e) {
e.printStackTrace();
}
}
setupLogging(homeDir);
try {
fixLogging(config);
config.setClassPath(makeClassPath(resourceFetcher.getFile("lib")));
} catch (IOException e1) {
e1.printStackTrace();
}
config.setStartEmbeddedWebServer(false);
bimServer = new BimServer(config);
Jsr356Impl.setDefaultServletContext(servletContextEvent.getServletContext());
Logger LOGGER = LoggerFactory.getLogger(WarServerInitializer.class);
LOGGER.info("Servlet Context Name: " + servletContext.getServletContextName());
try {
bimServer.start();
} catch (ServerException e) {
LOGGER.error("", e);
} catch (DatabaseInitException e) {
LOGGER.error("", e);
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (PluginException e) {
LOGGER.error("", e);
} catch (DatabaseRestartRequiredException e) {
LOGGER.error("", e);
}
servletContext.setAttribute("bimserver", bimServer);
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class DatabaseSession method commit.
public void commit(ProgressHandler progressHandler) throws BimserverDatabaseException, ServiceException {
checkOpen();
try {
if (progressHandler != null) {
progressHandler.progress(0, objectsToCommit == null ? 0 : objectsToCommit.size());
}
int current = 0;
long writes = 0;
ByteBuffer keyBuffer = ByteBuffer.wrap(new byte[16]);
if (objectsToDelete != null) {
for (RecordIdentifierPlusType recordIdentifier : objectsToDelete) {
fillKeyBuffer(keyBuffer, recordIdentifier);
database.getKeyValueStore().storeNoOverwrite(recordIdentifier.getPackageName() + "_" + recordIdentifier.getClassName(), keyBuffer.array(), new byte[] { -1 }, this);
writes++;
}
}
// This buffer is reused for the values, it's position must be reset at the end of the loop, and the convertObjectToByteArray function is responsible for setting the buffer's position to the end of the (used part of the) buffer
ByteBuffer reusableBuffer = ByteBuffer.allocate(32768);
if (objectsToCommit != null) {
for (IdEObject object : objectsToCommit) {
if (object.getOid() == -1) {
throw new BimserverDatabaseException("Cannot store object with oid -1");
}
fillKeyBuffer(keyBuffer, object);
if (DEVELOPER_DEBUG) {
LOGGER.info("Write: " + object.eClass().getName() + " " + "pid=" + object.getPid() + " oid=" + object.getOid() + " rid=" + object.getRid());
}
ByteBuffer valueBuffer = convertObjectToByteArray(object, reusableBuffer, getMetaDataManager().getPackageMetaData(object.eClass().getEPackage().getName()));
int valueBufferPosition = valueBuffer.position();
processPossibleIndices(keyBuffer, object.getPid(), object.getRid(), object.getOid(), object.eClass(), valueBuffer);
if (object.eClass().getEAnnotation("nolazyload") == null && !overwriteEnabled) {
database.getKeyValueStore().storeNoOverwrite(object.eClass().getEPackage().getName() + "_" + object.eClass().getName(), keyBuffer.array(), valueBuffer.array(), 0, valueBufferPosition, this);
} else {
database.getKeyValueStore().store(object.eClass().getEPackage().getName() + "_" + object.eClass().getName(), keyBuffer.array(), valueBuffer.array(), 0, valueBuffer.position(), this);
}
if (progressHandler != null) {
progressHandler.progress(++current, objectsToCommit.size());
}
writes++;
// bimServerClient may have increased the size of the buffer by creating a new one, we keep using it for other objects
reusableBuffer = valueBuffer;
reusableBuffer.position(0);
}
}
if (bimTransaction != null) {
bimTransaction.commit();
database.getKeyValueStore().sync();
}
database.incrementCommittedWrites(writes);
close();
if (postCommitActions != null) {
for (PostCommitAction postCommitAction : postCommitActions) {
postCommitAction.execute();
}
}
} catch (BimserverDatabaseException e) {
throw e;
} catch (ServiceException e) {
throw e;
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class NotificationRegistryServiceImpl method updateProgressTopic.
@Override
public void updateProgressTopic(Long topicId, SLongActionState state) throws UserException, ServerException {
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
ProgressTopic topic = getBimServer().getNotificationsManager().getProgressTopic(topicId);
ProgressNotification progressNotification = new ProgressNotification(getBimServer(), topic, getBimServer().getSConverter().convertFromSObject(state));
getBimServer().getNotificationsManager().addToQueue(progressNotification);
} catch (BimserverDatabaseException e) {
handleException(e);
} finally {
session.close();
}
}
Aggregations