Package fr.soleil.salsa.persistence.model

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


    @Override
    public IConfig<?> getConfigById(Integer id) {
        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);
            }
        }
        return result;
View Full Code Here


    public IConfig<?> saveConfig(IConfig<?> config) throws PersistenceException {
        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.getId() == null) {
            // create
            dao.saveConfig(c);
        }
        else {
            // update
            dao.updateConfig(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());
            }
        }

        return result;
    }
View Full Code Here

            SQLException {

        if (configuration == null || configuration.getId() == null)
            return;

        Configuration configResultat = null;

        // Load the config
        configResultat = getConfigById(configuration.getId());

        // Case when the entity is NULL
        if (configResultat == null
                || !configResultat.getTimestamp().equals(configuration.getTimestamp())) {
            throw new ScanConfigOutOfSyncException();
        }

        // delete the config
        deleteConfigNoCommitAux(configuration);
View Full Code Here

    }

    public Configuration getConfigById(Integer id) {
        try {
            startOperation();
            Configuration result = getConfigByIdAux(id);
            return result;
        }
        catch (SQLException e) {
            CommonsJDBC.catchException(e);
        }
View Full Code Here

     * @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();
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

        if (config == null)
            return;

        // V�rification de l'existence de la config
        Configuration configuration = getConfigById(config.getId());
        if (config == null || !config.getTimestamp().equals(configuration.getTimestamp())) {
            throw new ScanConfigOutOfSyncException();
        }

        // V�rification si le r�pertoire de la config
        // a �t� supprim� entre temps ou pas
View Full Code Here

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

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

        try {
            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);
View Full Code Here

        }
        catch (ConversionException e) {
            throw new PersistenceException(e.getMessage(), e);
        }

        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 (ConversionException 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

        if (configuration == null || configuration.getId() == null) {
            return;
        }

        Configuration configResultat = null;

        // Load the config
        configResultat = getConfigById(configuration.getId());

        // Case when the entity is NULL
        if (configResultat == null
                || !configResultat.getTimestamp().equals(configuration.getTimestamp())) {
            throw new ScanConfigOutOfSyncException();
        }

        // delete the config
        deleteConfigNoCommitAux(configuration);
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.