Package fr.soleil.salsa.persistence.model

Examples of fr.soleil.salsa.persistence.model.Configuration


     * @param configId
     * @return Configuration
     */
    private Configuration getConfigByIdAux(Integer configId) throws SQLException {

        Configuration configuration = null;
        String query = "SELECT configid, name, type, data, directoryid, timestamp FROM config WHERE configid="
                + configId;

        ResultSet rs = stmt.executeQuery(query);

        while (rs.next()) {

            configuration = new Configuration();

            configuration.setId(rs.getInt("configid"));
            configuration.setName(rs.getString("name"));
            configuration.setType(rs.getString("type"));
            configuration.setData(rs.getString("data"));
            configuration.setDirectoryId(rs.getInt("directoryid"));
            configuration.setTimestamp(rs.getTimestamp("timestamp"));

            int parentId = rs.getInt("directoryid");

            if (!rs.wasNull()) {
                DirectoryImpl parent = new DirectoryImpl();
                parent.setId(parentId);
                configuration.setDirectoryId(parentId);
                configuration.setDirectory(parent);
                // configuration.setDirectory(getDirectoryById(dir));
            }
        }
        rs.close();
        stmt.clearBatch();
        configuration.setChartProperties(getChartPropertiesByIdAux(configId));
        configuration.setPlotPropertiesMap(getPlotPropertiesByIdAux(configId));

        return configuration;
    }
View Full Code Here


        try {
            startOperation();
            ResultSet rs = stmt.executeQuery(query);

            Configuration config = null;
            while (rs.next()) {

                config = new Configuration();

                config.setId(rs.getInt("configid"));
                config.setName(rs.getString("name"));
                config.setType(rs.getString("type"));
                config.setData(rs.getString("data"));
                config.setDirectoryId(rs.getInt("directoryid"));
                config.setTimestamp(rs.getTimestamp("timestamp"));

                configList.add(config);

            }
            rs.close();
View Full Code Here

        ScanConfigOutOfSyncException exception = null;
        if (config == null) {
            exception = new ScanConfigOutOfSyncException("Can't save a null configuration");
        }
        else {
            Configuration configuration = getConfigById(config.getId());
            boolean newConfig = (configuration == null);
            // Checking if the configuration is out of synchronization
            if ((!newConfig) && (!config.getTimestamp().equals(configuration.getTimestamp()))) {
                exception = new ScanConfigOutOfSyncException();
            }
            else {
                // Checking if the configuration directory has been deleted
                IDirectory directory = getDirectoryById(config.getDirectoryId(), false);
View Full Code Here

    @Override
    public IConfig<?> getConfigById(Integer id) throws ScanNotFoundException {
        IConfig<?> result = null;

        ConfigDAOJdbcImpl dao = new ConfigDAOJdbcImpl();
        Configuration c = dao.getConfigById(id);

        if (c != null) {
            result = (IConfig<?>) ConfigAsXmlHelper.fromXml(c.getData());
            // result.setName(c.getName());

            result.setLoaded(true);
            result.setId(id);
            result.setTimestamp(c.getTimestamp());
            if (c.getDirectoryId() != null) {
                IDirectory parent = new DirectoryImpl();
                parent.setId(c.getDirectoryId());
                result.setDirectory(parent);
            }
            if (c.getType().equals("Config1DImpl")) {
                result.setType(IConfig.ScanType.SCAN_1D);
            }
            else if (c.getType().equals("Config2DImpl")) {
                result.setType(IConfig.ScanType.SCAN_2D);
            }
            else if (c.getType().equals("ConfigHCS")) {
                result.setType(IConfig.ScanType.SCAN_HCS);
            }
            else if (c.getType().equals("ConfigK")) {
                result.setType(IConfig.ScanType.SCAN_K);
            }
            else if (c.getType().equals("ConfigEnergy")) {
                result.setType(IConfig.ScanType.SCAN_ENERGY);
            }

            if (result instanceof ISpectrumConfig<?>) {
                ISpectrumConfig<?> sc = (ISpectrumConfig<?>) result;
                sc.setChartProperties(c.getChartProperties());
                sc.setPlotPropertiesMap(c.getPlotPropertiesMap());
            }
            c.clean();
        }
        if (result == null) {
            StringBuilder builder = new StringBuilder("Failed to find configuration matching id = ");
            builder.append(id);
            throw new ScanNotFoundException(builder.toString());
View Full Code Here

            ScanNotFoundException {
        IConfig<?> result = null;
        ConfigDAOJdbcImpl dao = new ConfigDAOJdbcImpl();
        Document d = ConfigAsXmlHelper.toXml(config);

        Configuration c = new Configuration();
        c.setId(config.getId());
        c.setName(config.getName());
        c.setType(config.getClass().getSimpleName());
        c.setDirectory(config.getDirectory());
        try {
            c.setData(ConfigAsXmlHelper.xmlToString(d));
        }
        catch (TransformerException e) {
            e.printStackTrace();
        }
        // Parent directory need to be defined !!
        c.setDirectoryId(config.getDirectory().getId());
        c.setTimestamp(config.getTimestamp());
        if (config instanceof ISpectrumConfig<?>) {
            ISpectrumConfig<?> sc = (ISpectrumConfig<?>) config;
            c.setChartProperties(sc.getChartProperties());
            c.setPlotPropertiesMap(sc.getPlotPropertiesMap());
        }

        dao.saveConfig(c);

        if (c.getId() != null) {
            result = getConfigById(c.getId());
            // The timestamp is not defined by the getConfigById,
            // so we need to set his value explicitly with
            // the one provided by the save operation.
            if (result.getDirectory() != null && c.getDirectory() != null) {
                result.getDirectory().setTimestamp(c.getDirectory().getTimestamp());
            }
        }
        c.clean();

        return result;
    }
View Full Code Here

TOP

Related Classes of fr.soleil.salsa.persistence.model.Configuration

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.