use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class LowLevelServiceImpl method getDataObjects.
@Override
public List<SDataObject> getDataObjects(Long roid) throws ServerException, UserException {
requireAuthenticationAndRunningServer();
DatabaseSession session = getBimServer().getDatabase().createSession();
try {
BimDatabaseAction<List<DataObject>> action = new GetDataObjectsDatabaseAction(session, getInternalAccessMethod(), getBimServer(), roid, getAuthorization());
return getBimServer().getSConverter().convertToSListDataObject(session.executeAndCommitAction(action));
} catch (BimserverDatabaseException e) {
handleException(e);
} finally {
session.close();
}
return null;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class HashMapVirtualObject method write.
public ByteBuffer write() throws BimserverDatabaseException {
int bufferSize = getExactSize(this);
ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
byte[] unsetted = new byte[getPackageMetaData().getUnsettedLength(eClass)];
int fieldCounter = 0;
for (EStructuralFeature feature : eClass().getEAllStructuralFeatures()) {
if (getPackageMetaData().useForDatabaseStorage(eClass, feature)) {
if (useUnsetBit(feature)) {
unsetted[fieldCounter / 8] |= (1 << (fieldCounter % 8));
}
fieldCounter++;
}
}
buffer.put(unsetted);
EClass eClass = getDatabaseInterface().getEClassForOid(getOid());
if (!eClass.isSuperTypeOf(eClass())) {
throw new BimserverDatabaseException("Object with oid " + getOid() + " is a " + eClass().getName() + " but it's cid-part says it's a " + eClass.getName());
}
for (EStructuralFeature feature : eClass().getEAllStructuralFeatures()) {
if (getPackageMetaData().useForDatabaseStorage(eClass, feature)) {
if (!useUnsetBit(feature)) {
if (feature.isMany()) {
writeList(this, buffer, getPackageMetaData(), feature);
} else {
Object value = eGet(feature);
if (feature.getEType() instanceof EEnum) {
if (value == null) {
buffer.putInt(-1);
} else {
EEnum eEnum = (EEnum) feature.getEType();
EEnumLiteral eEnumLiteral = eEnum.getEEnumLiteralByLiteral(((Enum<?>) value).toString());
if (eEnumLiteral != null) {
buffer.putInt(eEnumLiteral.getValue());
} else {
LOGGER.error(((Enum<?>) value).toString() + " not found");
buffer.putInt(-1);
}
}
} else if (feature.getEType() instanceof EClass) {
if (value == null) {
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putShort((short) -1);
buffer.order(ByteOrder.BIG_ENDIAN);
} else if (value instanceof VirtualObject) {
writeWrappedValue(getPid(), getRid(), (VirtualObject) value, buffer, getPackageMetaData());
} else if (value instanceof WrappedVirtualObject) {
writeWrappedValue(getPid(), getRid(), (WrappedVirtualObject) value, buffer, getPackageMetaData());
} else {
long referencedOid = (Long) value;
writeReference(referencedOid, buffer, feature);
}
} else if (feature.getEType() instanceof EDataType) {
writePrimitiveValue(feature, value, buffer);
}
}
}
}
}
if (buffer.position() != bufferSize) {
throw new BimserverDatabaseException("Value buffer sizes do not match for " + eClass().getName() + " " + buffer.position() + "/" + bufferSize);
}
return buffer;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class AbstractByteBufferVirtualObject method writePrimitiveValue.
protected void writePrimitiveValue(EStructuralFeature feature, Object value) throws BimserverDatabaseException {
EClassifier type = feature.getEType();
if (type == EcorePackage.eINSTANCE.getEString()) {
if (value == null) {
ensureCapacity(buffer.position(), 4);
buffer.putInt(-1);
} else {
String stringValue = (String) value;
byte[] bytes = stringValue.getBytes(Charsets.UTF_8);
if (bytes.length > Integer.MAX_VALUE) {
throw new BimserverDatabaseException("String value too long (max length is " + Integer.MAX_VALUE + ")");
}
ensureCapacity(buffer.position(), 4 + bytes.length);
buffer.putInt(bytes.length);
buffer.put(bytes);
}
} else if (type == EcorePackage.eINSTANCE.getEInt() || type == EcorePackage.eINSTANCE.getEIntegerObject()) {
ensureCapacity(buffer.position(), 4);
if (value == null) {
buffer.putInt(0);
} else {
buffer.putInt((Integer) value);
}
} else if (type == EcorePackage.eINSTANCE.getEDouble() || type == EcorePackage.eINSTANCE.getEDoubleObject()) {
ensureCapacity(buffer.position(), 8);
if (value == null) {
buffer.putDouble(0D);
} else {
buffer.putDouble((Double) value);
}
} else if (type == EcorePackage.eINSTANCE.getEFloat() || type == EcorePackage.eINSTANCE.getEFloatObject()) {
ensureCapacity(buffer.position(), 4);
if (value == null) {
buffer.putFloat(0F);
} else {
buffer.putFloat((Float) value);
}
} else if (type == EcorePackage.eINSTANCE.getELong() || type == EcorePackage.eINSTANCE.getELongObject()) {
ensureCapacity(buffer.position(), 8);
if (value == null) {
buffer.putLong(0L);
} else {
buffer.putLong((Long) value);
}
} else if (type == EcorePackage.eINSTANCE.getEBoolean() || type == EcorePackage.eINSTANCE.getEBooleanObject()) {
ensureCapacity(buffer.position(), 1);
if (value == null) {
buffer.put((byte) 0);
} else {
buffer.put(((Boolean) value) ? (byte) 1 : (byte) 0);
}
} else if (type == EcorePackage.eINSTANCE.getEDate()) {
ensureCapacity(buffer.position(), 8);
if (value == null) {
buffer.putLong(-1L);
} else {
buffer.putLong(((Date) value).getTime());
}
} else if (type.getName().equals("Tristate")) {
ensureCapacity(buffer.position(), 4);
if (value == null) {
buffer.putInt(Tristate.UNDEFINED.getValue());
} else {
Enumerator eEnumLiteral = (Enumerator) value;
buffer.putInt(eEnumLiteral.getValue());
}
} else if (value instanceof Enumerator) {
ensureCapacity(buffer.position(), 4);
Enumerator eEnumLiteral = (Enumerator) value;
buffer.putInt(eEnumLiteral.getValue());
} else if (type == EcorePackage.eINSTANCE.getEByteArray()) {
if (value == null) {
ensureCapacity(buffer.position(), 4);
buffer.putInt(0);
} else {
byte[] bytes = (byte[]) value;
ensureCapacity(buffer.position(), 4 + bytes.length);
buffer.putInt(bytes.length);
buffer.put(bytes);
}
} else {
throw new RuntimeException("Unsupported type " + type.getName());
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class WaitingListVirtualObject method decrementOpenConnections.
private void decrementOpenConnections(VirtualObject virtualObject) throws BimserverDatabaseException {
AtomicInteger openConnectionCounter = getOpenConnectionCounter(virtualObject.getOid());
int decrementAndGet = openConnectionCounter.decrementAndGet();
if (decrementAndGet == 0) {
virtualObject.save();
} else if (decrementAndGet < 0) {
throw new BimserverDatabaseException("Inconsistent state");
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class TestSimultaniousDownloadWithCaching method start.
private void start() {
BimServerConfig config = new BimServerConfig();
Path homeDir = Paths.get("home");
try {
if (Files.isDirectory(homeDir)) {
PathUtils.removeDirectoryWithContent(homeDir);
}
} catch (IOException e) {
e.printStackTrace();
}
config.setClassPath(System.getProperty("java.class.path"));
config.setHomeDir(homeDir);
config.setPort(8080);
config.setStartEmbeddedWebServer(true);
config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../")));
final BimServer bimServer = new BimServer(config);
try {
LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), null);
bimServer.start();
if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) {
bimServer.getService(AdminInterface.class).setup("http://localhost", "Administrator", "admin@bimserver.org", "admin", null, null, null);
}
} catch (PluginException e2) {
e2.printStackTrace();
} catch (ServerException e) {
e.printStackTrace();
} catch (DatabaseInitException e) {
e.printStackTrace();
} catch (BimserverDatabaseException e) {
e.printStackTrace();
} catch (DatabaseRestartRequiredException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
}
try {
final ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL);
ServiceInterface serviceInterface = serviceMap.get(ServiceInterface.class);
SettingsInterface settingsInterface = serviceMap.get(SettingsInterface.class);
final AuthInterface authInterface = serviceMap.get(AuthInterface.class);
serviceInterface = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL).get(ServiceInterface.class);
settingsInterface.setCacheOutputFiles(true);
settingsInterface.setGenerateGeometryOnCheckin(false);
final SProject project = serviceMap.getServiceInterface().addProject("test", "ifc2x3tc1");
SDeserializerPluginConfiguration deserializerByName = serviceMap.getServiceInterface().getDeserializerByName("IfcStepDeserializer");
Path file = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc");
serviceInterface.checkin(project.getOid(), "test", deserializerByName.getOid(), file.toFile().length(), file.getFileName().toString(), new DataHandler(new FileDataSource(file.toFile())), false, true);
final SProject projectUpdate = serviceMap.getServiceInterface().getProjectByPoid(project.getOid());
ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(1000));
for (int i = 0; i < 20; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
ServiceMap serviceMap2 = bimServer.getServiceFactory().get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL);
SSerializerPluginConfiguration serializerPluginConfiguration = serviceMap.getServiceInterface().getSerializerByName("Ifc2x3");
Long download = serviceMap2.getServiceInterface().download(Collections.singleton(projectUpdate.getLastRevisionId()), DefaultQueries.allAsString(), serializerPluginConfiguration.getOid(), true);
SDownloadResult downloadData = serviceMap2.getServiceInterface().getDownloadData(download);
if (downloadData.getFile().getDataSource() instanceof CacheStoringEmfSerializerDataSource) {
CacheStoringEmfSerializerDataSource c = (CacheStoringEmfSerializerDataSource) downloadData.getFile().getDataSource();
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
c.writeToOutputStream(baos, null);
System.out.println(baos.size());
} catch (SerializerException e) {
e.printStackTrace();
}
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(downloadData.getFile().getInputStream(), baos);
System.out.println(baos.size());
}
serviceMap2.getServiceInterface().cleanupLongAction(download);
} catch (ServerException e) {
e.printStackTrace();
} catch (UserException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e1) {
e1.printStackTrace();
}
}
});
}
executor.shutdown();
executor.awaitTermination(1, TimeUnit.HOURS);
bimServer.stop();
} catch (ServerException e1) {
e1.printStackTrace();
} catch (UserException e1) {
e1.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (PublicInterfaceNotFoundException e2) {
e2.printStackTrace();
}
}
Aggregations