Search in sources :

Example 6 with AttributePlugin

use of com.ramussoft.common.attribute.AttributePlugin in project ramus by Vitaliy-Yakovchuk.

the class ModelParaleler method copyAttributes.

private void copyAttributes(List<Attribute> attributes, Element source, Element destination) {
    for (Attribute attribute : attributes) if ((!attribute.getAttributeType().getTypeName().equals("Hierarchical")) && (!attribute.getAttributeType().getTypeName().equals("VisualData")) && (!attribute.getAttributeType().getTypeName().equals("SectorBorder"))) {
        AttributePlugin plugin = attribute.getAttributeType().getAttributePlugin(fromEngine);
        if (plugin == null)
            System.err.println("WARNING: Attribute plugin not found for type: " + attribute.getAttributeType());
        else
            plugin.copyAttribute(fromEngine, toEngine, attribute, getAttribute(attribute), source, destination, this);
    }
}
Also used : AttributePlugin(com.ramussoft.common.attribute.AttributePlugin) Attribute(com.ramussoft.common.Attribute)

Example 7 with AttributePlugin

use of com.ramussoft.common.attribute.AttributePlugin in project ramus by Vitaliy-Yakovchuk.

the class ModelParaleler method getAttribute.

private Attribute getAttribute(Attribute source) {
    if (source == null)
        return null;
    Attribute res = attrHash.get(source.getId());
    if (res == null) {
        res = toEngine.createAttribute(source.getAttributeType());
        attrHash.put(source.getId(), res);
        res.setName(source.getName());
        AttributePlugin plugin = source.getAttributeType().getAttributePlugin(fromEngine);
        plugin.copyAttribute(fromEngine, toEngine, source, res, null, null, this);
        toEngine.updateAttribute(res);
    }
    return res;
}
Also used : AttributePlugin(com.ramussoft.common.attribute.AttributePlugin) Attribute(com.ramussoft.common.Attribute)

Example 8 with AttributePlugin

use of com.ramussoft.common.attribute.AttributePlugin in project ramus by Vitaliy-Yakovchuk.

the class StandardAttributesPlugin method isSystem.

protected boolean isSystem(AttributeType attributeType) {
    PluginFactory factory = (PluginFactory) engine.getPluginProperty("Core", "PluginFactory");
    if (factory == null)
        return false;
    AttributePlugin plugin = factory.getAttributePlugin(attributeType);
    if (plugin == null) {
        System.err.println("WARNING: Attribute plugin for attribute type " + attributeType + " not found");
        return false;
    }
    return plugin.isSystem();
}
Also used : AttributePlugin(com.ramussoft.common.attribute.AttributePlugin) PluginFactory(com.ramussoft.common.PluginFactory)

Example 9 with AttributePlugin

use of com.ramussoft.common.attribute.AttributePlugin in project ramus by Vitaliy-Yakovchuk.

the class FileIEngineImpl method getPluginNames.

@SuppressWarnings("unchecked")
private PluginName[] getPluginNames(List<Plugin> plugins) {
    List<PluginName> data = new ArrayList<PluginName>(plugins.size());
    List<AttributeType> types = template.query("SELECT attribute_type_plugin_name, attribute_type_name from " + prefix + "attributes GROUP BY attribute_type_plugin_name, attribute_type_name", new RowMapper() {

        @Override
        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new AttributeType(rs.getString(1).trim(), rs.getString(2).trim());
        }
    });
    for (int i = 0; i < plugins.size(); i++) {
        Plugin plugin = plugins.get(i);
        String name = plugin.getName();
        if (plugin instanceof AttributePlugin) {
            AttributePlugin attributePlugin = (AttributePlugin) plugin;
            AttributeType type = new AttributeType(attributePlugin.getName(), attributePlugin.getTypeName());
            if (types.indexOf(type) >= 0) {
                name = "Attribute." + name + "." + attributePlugin.getTypeName();
                data.add(new PluginName(plugin, name));
            }
        } else {
            data.add(new PluginName(plugin, name));
        }
    }
    return data.toArray(new PluginName[data.size()]);
}
Also used : AttributePlugin(com.ramussoft.common.attribute.AttributePlugin) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) RowMapper(com.ramussoft.jdbc.RowMapper) AttributePlugin(com.ramussoft.common.attribute.AttributePlugin)

Example 10 with AttributePlugin

use of com.ramussoft.common.attribute.AttributePlugin in project ramus by Vitaliy-Yakovchuk.

the class IEngineImpl method getBinaryAttribute.

@Override
@SuppressWarnings("unchecked")
public List<Persistent>[] getBinaryAttribute(long elementId, long attributeId) {
    throwExaptionIfNotCan(getAccessor().canReadElement(elementId, attributeId), "Can not get attribute.");
    Attribute attribute = getAttribute(attributeId);
    AttributePlugin plugin = factory.getAttributePlugin(attribute.getAttributeType());
    final Class<? extends Persistent>[] classes;
    if (elementId >= 0)
        classes = plugin.getAttributePersistents();
    else
        classes = plugin.getAttributePropertyPersistents();
    List<Persistent>[] lists = new List[classes.length];
    for (int i = 0; i < lists.length; i++) {
        final Class<? extends Persistent> clazz = classes[i];
        final PersistentRow row = metadata.get(clazz);
        final PersistentWrapper wrapper = wrappers.get(clazz);
        ArrayList<Object> params = new ArrayList<Object>(2);
        ArrayList<String> paramFields = new ArrayList<String>(2);
        plugin.fillAttributeQuery(row, attributeId, elementId, params, paramFields, this);
        if (elementId >= 0l && attribute.getAttributeType().getTypeName().equals("ElementList") && attribute.getAttributeType().getPluginName().equals("Core")) {
            return getEListFixed(row, clazz, wrapper, paramFields, params, getActiveBranchId());
        }
        long branchId = 0l;
        try {
            branchId = getBranch(prefix + "attributes_data_metadata", new Object[] { "element_id", "attribute_id" }, new Object[] { elementId, attributeId }, getActiveBranchId());
        } catch (SQLException e1) {
            e1.printStackTrace();
            throw new RuntimeException(e1);
        }
        params.add(branchId);
        paramFields.add("value_branch_id");
        StringBuffer sb = new StringBuffer("SELECT * FROM " + row.getTableName());
        if (params.size() > 0) {
            sb.append(" WHERE ");
        }
        boolean first = true;
        for (int j = 0; j < params.size(); j++) {
            if (first) {
                first = false;
            } else {
                sb.append(" AND ");
            }
            sb.append(paramFields.get(j));
            sb.append("=?");
        }
        List<Persistent> list = template.query(sb.toString(), new RowMapper() {

            @Override
            public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                try {
                    Persistent persistent = clazz.newInstance();
                    for (PersistentField field : row.getFields()) {
                        wrapper.setDatabaseField(persistent, field, rs);
                    }
                    return persistent;
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                throw new RuntimeException();
            }
        }, params.toArray(new Object[params.size()]), true);
        lists[i] = list;
    }
    return lists;
}
Also used : PersistentField(com.ramussoft.common.persistent.PersistentField) Attribute(com.ramussoft.common.Attribute) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) RowMapper(com.ramussoft.jdbc.RowMapper) AttributePlugin(com.ramussoft.common.attribute.AttributePlugin) PersistentRow(com.ramussoft.common.persistent.PersistentRow) Persistent(com.ramussoft.common.persistent.Persistent) FindObject(com.ramussoft.common.attribute.FindObject) PersistentWrapper(com.ramussoft.common.persistent.PersistentWrapper)

Aggregations

AttributePlugin (com.ramussoft.common.attribute.AttributePlugin)11 Attribute (com.ramussoft.common.Attribute)5 FindObject (com.ramussoft.common.attribute.FindObject)5 RowMapper (com.ramussoft.jdbc.RowMapper)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 ArrayList (java.util.ArrayList)5 Persistent (com.ramussoft.common.persistent.Persistent)4 PersistentField (com.ramussoft.common.persistent.PersistentField)4 PersistentRow (com.ramussoft.common.persistent.PersistentRow)4 PersistentWrapper (com.ramussoft.common.persistent.PersistentWrapper)4 List (java.util.List)3 Element (com.ramussoft.common.Element)1 Plugin (com.ramussoft.common.Plugin)1 PluginFactory (com.ramussoft.common.PluginFactory)1 Qualifier (com.ramussoft.common.Qualifier)1 Transaction (com.ramussoft.common.persistent.Transaction)1 GUIPlugin (com.ramussoft.gui.common.GUIPlugin)1 Hashtable (java.util.Hashtable)1 JScrollPane (javax.swing.JScrollPane)1