Search in sources :

Example 91 with BimserverDatabaseException

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;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) GetDataObjectsDatabaseAction(org.bimserver.database.actions.GetDataObjectsDatabaseAction) ArrayList(java.util.ArrayList) List(java.util.List)

Example 92 with BimserverDatabaseException

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;
}
Also used : EEnum(org.eclipse.emf.ecore.EEnum) EDataType(org.eclipse.emf.ecore.EDataType) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EEnum(org.eclipse.emf.ecore.EEnum) ByteBuffer(java.nio.ByteBuffer) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral)

Example 93 with BimserverDatabaseException

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());
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Enumerator(org.eclipse.emf.common.util.Enumerator) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 94 with BimserverDatabaseException

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");
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 95 with BimserverDatabaseException

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();
    }
}
Also used : AuthInterface(org.bimserver.shared.interfaces.AuthInterface) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) ServiceMap(org.bimserver.webservices.ServiceMap) CacheStoringEmfSerializerDataSource(org.bimserver.plugins.serializers.CacheStoringEmfSerializerDataSource) FileNotFoundException(java.io.FileNotFoundException) DataHandler(javax.activation.DataHandler) BimServerConfig(org.bimserver.BimServerConfig) SProject(org.bimserver.interfaces.objects.SProject) LocalDevelopmentResourceFetcher(org.bimserver.shared.LocalDevelopmentResourceFetcher) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) FileDataSource(javax.activation.FileDataSource) UserException(org.bimserver.shared.exceptions.UserException) Path(java.nio.file.Path) ServerException(org.bimserver.shared.exceptions.ServerException) BimServer(org.bimserver.BimServer) PluginException(org.bimserver.shared.exceptions.PluginException) SDownloadResult(org.bimserver.interfaces.objects.SDownloadResult) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SerializerException(org.bimserver.plugins.serializers.SerializerException) AdminInterface(org.bimserver.shared.interfaces.AdminInterface) SettingsInterface(org.bimserver.shared.interfaces.SettingsInterface) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

BimserverDatabaseException (org.bimserver.BimserverDatabaseException)123 DatabaseSession (org.bimserver.database.DatabaseSession)56 UserException (org.bimserver.shared.exceptions.UserException)30 EClass (org.eclipse.emf.ecore.EClass)24 User (org.bimserver.models.store.User)20 ByteBuffer (java.nio.ByteBuffer)19 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)18 ServerSettings (org.bimserver.models.store.ServerSettings)18 IOException (java.io.IOException)16 ServerSettingsSetter (org.bimserver.database.actions.ServerSettingsSetter)16 SetServerSettingDatabaseAction (org.bimserver.database.actions.SetServerSettingDatabaseAction)16 SServerSettings (org.bimserver.interfaces.objects.SServerSettings)16 ServerException (org.bimserver.shared.exceptions.ServerException)15 UserSettings (org.bimserver.models.store.UserSettings)12 ServiceException (org.bimserver.shared.exceptions.ServiceException)11 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)10 ArrayList (java.util.ArrayList)9 IdEObject (org.bimserver.emf.IdEObject)9 Project (org.bimserver.models.store.Project)9 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)9