Package com.buschmais.cdo.api

Examples of com.buschmais.cdo.api.CdoException


    private boolean active = false;

    @Override
    public void begin() {
        if (active) {
            throw new CdoException("There is already an active transaction.");
        }
        active = true;
    }
View Full Code Here


    @Override
    public Datastore<JsonFileStoreSession, JsonNodeMetadata, String> createDatastore(CdoUnit cdoUnit) {
        URL url = cdoUnit.getUrl();
        if (!"file".equals(url.getProtocol())) {
            throw new CdoException("Only file URLs are supported by this store.");
        }
        return new JsonFileStore(url.getPath());
    }
View Full Code Here

        try {
            cdoContext = JAXBContext.newInstance(ObjectFactory.class);
            xsdFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            cdoXsd = xsdFactory.newSchema(new StreamSource(classLoader.getResourceAsStream("META-INF/xsd/cdo-1.0.xsd")));
        } catch (JAXBException e) {
            throw new CdoException("Cannot create JAXBContext for reading cdo.xml descriptors.", e);
        } catch (SAXException e) {
            throw new CdoException("Cannot create Schema for validation of cdo.xml descriptors.", e);
        }
        try {
            Enumeration<URL> resources = classLoader.getResources("META-INF/cdo.xml");
            while (resources.hasMoreElements()) {
                URL url = resources.nextElement();
                com.buschmais.cdo.schema.v1.Cdo cdo = readCdoDescriptor(cdoContext, url, cdoXsd);
                getCdoUnits(cdo);
            }
        } catch (IOException e) {
            throw new CdoException("Cannot read cdo.xml descriptors.", e);
        }
    }
View Full Code Here

                unmarshaller.setEventHandler(validationHandler);
                Cdo cdoXmlContent = unmarshaller.unmarshal(new StreamSource(is), Cdo.class).getValue();
                if (validationHandler.isValid()) {
                    return cdoXmlContent;
                } else {
                    throw new CdoException("Invalid cdo.xml descriptor detected: "
                            + validationHandler.getValidationMessages());
                }
            } catch (JAXBException e) {
                throw new CdoException("Cannot create JAXB unmarshaller for reading cdo.xml descriptors.");
            }
        }
    }
View Full Code Here

            String urlName = cdoUnitType.getUrl();
            URL url;
            try {
                url = new URL(urlName);
            } catch (MalformedURLException e) {
                throw new CdoException("Cannot convert '" + urlName + "' to url.");
            }
            String providerName = cdoUnitType.getProvider();
            Class<? extends CdoDatastoreProvider> provider = ClassHelper.getType(providerName);
            Set<Class<?>> types = new HashSet<>();
            for (String typeName : cdoUnitType.getTypes().getType()) {
                types.add(ClassHelper.getType(typeName));
            }
            ValidationModeType validationModeType = cdoUnitType.getValidationMode();
            ValidationMode validationMode;
            if (validationModeType != null) {
                switch (validationModeType) {
                    case NONE:
                        validationMode = ValidationMode.NONE;
                        break;
                    case AUTO:
                        validationMode = ValidationMode.AUTO;
                        break;
                    default:
                        throw new CdoException("Unknown validation mode type " + validationModeType);
                }
            } else {
                validationMode = ValidationMode.AUTO;
            }
            TransactionAttributeType defaultTransactionAttributeType = cdoUnitType.getDefaultTransactionAttribute();
            TransactionAttribute defaultTransactionAttribute;
            if (defaultTransactionAttributeType != null) {
                switch (defaultTransactionAttributeType) {
                    case MANDATORY:
                        defaultTransactionAttribute = TransactionAttribute.MANDATORY;
                        break;
                    case REQUIRES:
                        defaultTransactionAttribute = TransactionAttribute.REQUIRES;
                        break;
                    default:
                        throw new CdoException("Unknown transaction attribute type " + defaultTransactionAttributeType);
                }
            } else {
                defaultTransactionAttribute = TransactionAttribute.MANDATORY;
            }
            Properties properties = new Properties();
View Full Code Here

    }

    public CdoUnit getCdoUnit(String name) {
        CdoUnit cdoUnit = cdoUnits.get(name);
        if (cdoUnit == null) {
            throw new CdoException("CDO unit with name '" + name + "' does not exist.");
        }
        return cdoUnit;
    }
View Full Code Here

    static <T> Class<T> getType(String name) {
        Class<T> type;
        try {
            type = (Class<T>) Class.forName(name);
        } catch (ClassNotFoundException e) {
            throw new CdoException("Cannot find class with name " + name);
        }
        return type;
    }
View Full Code Here

    static <T> T newInstance(Class<T> type) {
        try {
            return type.newInstance();
        } catch (InstantiationException e) {
            throw new CdoException("Cannot create instance of type " + type.getName());
        } catch (IllegalAccessException e) {
            throw new CdoException("Access denied to type " + type.getName());
        }
    }
View Full Code Here

    @Override
    public CdoManagerFactory createCdoManagerFactory(CdoUnit cdoUnit) {
        Class<?> providerType = cdoUnit.getProvider();
        if (providerType == null) {
            throw new CdoException("No provider specified for CDO unit '" + cdoUnit.getName() + "'.");
        }
        if (!CdoDatastoreProvider.class.isAssignableFrom(providerType)) {
            throw new CdoException(providerType.getName() + " specified as CDO provider must implement " + CdoDatastoreProvider.class.getName());
        }
        CdoDatastoreProvider cdoDatastoreProvider = CdoDatastoreProvider.class.cast(ClassHelper.newInstance(providerType));
        Datastore<?, ?, ?> datastore = cdoDatastoreProvider.createDatastore(cdoUnit);
        return new CdoManagerFactoryImpl(cdoUnit, datastore);
    }
View Full Code Here

    }

    public <T> T getInstance(Entity entity) {
        Set<?> discriminators = datastoreSession.getDiscriminators(entity);
        if (discriminators == null || discriminators.isEmpty()) {
            throw new CdoException("Cannot determine type discriminators for entity '" + entity + "'");
        }
        TypeMetadataSet<?> types = metadataProvider.getTypes(discriminators);
        EntityId id = datastoreSession.getId(entity);
        Object instance = cache.get(id);
        if (instance == null) {
View Full Code Here

TOP

Related Classes of com.buschmais.cdo.api.CdoException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.