use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method getBinaryElements.
@Override
public Hashtable<Element, List<Persistent>[][]> getBinaryElements(long qualifierId, final long[] attributeIds) {
for (long attributeId : attributeIds) throwExaptionIfNotCan(getAccessor().canReadAttribute(qualifierId, attributeId), "Can not get attribute for qualifier.");
List<Element> elements = getElements(qualifierId);
Hashtable<Element, List<Persistent>[][]> result = new Hashtable<Element, List<Persistent>[][]>();
final Hashtable<Long, List<Persistent>[][]> values = new Hashtable<Long, List<Persistent>[][]>();
int index = 0;
final int[] persistentCount = new int[attributeIds.length];
for (int i = 0; i < attributeIds.length; i++) {
Attribute attribute = getAttribute(attributeIds[i]);
AttributePlugin plugin = factory.getAttributePlugin(attribute.getAttributeType());
persistentCount[i] = plugin.getAttributePersistents().length;
}
for (long attributeId : attributeIds) {
final int attrIndex = index;
Attribute attribute = getAttribute(attributeId);
AttributePlugin plugin = factory.getAttributePlugin(attribute.getAttributeType());
final Class<? extends Persistent>[] classes;
classes = plugin.getAttributePersistents();
for (int i = 0; i < classes.length; i++) {
final Class<? extends Persistent> clazz = classes[i];
final int listIndex = 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, -1l, params, paramFields, this);
StringBuffer sb = new StringBuffer("SELECT * FROM " + row.getTableName() + " main_table");
StringBuffer where = new StringBuffer(" AND attribute_id=?");
for (int j = 0; j < params.size(); j++) if (paramFields.get(j).startsWith("element") && paramFields.get(j).endsWith("id")) {
where.append(" AND main_table.");
where.append(paramFields.get(j));
where.append("=element_id");
}
for (PersistentField field : row.getFields()) {
if (field.isAutoset()) {
if (field.getType() == PersistentField.ELEMENT) {
where.append(" AND main_table.");
where.append(field.getDatabaseName());
where.append("=element_id");
}
}
}
sb.append(" WHERE (value_branch_id IN (SELECT MAX(branch_id) FROM " + prefix + "attributes_data_metadata WHERE branch_id<=? " + where + ") OR ((SELECT MAX(branch_id) FROM " + prefix + "attributes_data_metadata WHERE branch_id<=? " + where + ") IS NULL AND value_branch_id=0))");
for (int j = 0; j < params.size(); j++) {
sb.append(" AND ");
sb.append(paramFields.get(j));
sb.append("=?");
}
params.add(0, getActiveBranchId());
params.add(1, attributeId);
params.add(2, getActiveBranchId());
params.add(3, attributeId);
template.query(sb.toString(), new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
try {
Persistent persistent = clazz.newInstance();
long id = -1;
for (PersistentField field : row.getFields()) {
wrapper.setDatabaseField(persistent, field, rs);
if ((field.isAutoset()) && (field.getType() == PersistentField.ELEMENT)) {
id = rs.getLong(field.getDatabaseName());
}
}
getLists(values, id, attributeIds.length, persistentCount)[attrIndex][listIndex].add(persistent);
return null;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
throw new RuntimeException();
}
}, params.toArray(new Object[params.size()]), false);
}
index++;
}
for (Element element : elements) {
result.put(element, getLists(values, element.getId(), attributeIds.length, persistentCount));
}
return result;
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method getAttributePropertyWhatWillBeDeleted.
@Override
public Transaction getAttributePropertyWhatWillBeDeleted(long attributeId) {
throwExaptionIfNotCan(getAccessor().canDeleteAttribute(attributeId), "Can not get attributes what will be deleted, as can not delete element.");
Attribute attribute = getAttribute(attributeId);
return getAttributeWhatWillBeDeleted(-1, attribute, true);
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method getAttributesWhatWillBeDeleted.
@Override
public Transaction[] getAttributesWhatWillBeDeleted(long elementId, List<Attribute> attrs) {
throwExaptionIfNotCan(getAccessor().canDeleteElements(new long[] { elementId }), "Can not get attributes what will be deleted, as you can not delete element.");
Transaction[] res = new Transaction[attrs.size()];
for (int i = 0; i < attrs.size(); i++) {
Attribute attribute = attrs.get(i);
res[i] = getAttributeWhatWillBeDeleted(elementId, attribute, false);
}
return res;
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class EvalPlugin method replaceElements.
@Override
public void replaceElements(Engine engine, Element[] oldElements, Element newElement) {
Hashtable<Long, Qualifier> qualifiers = new Hashtable<Long, Qualifier>();
Qualifier main = getQualifier(newElement.getQualifierId(), qualifiers, engine);
for (Element element : oldElements) {
Qualifier qualifier = getQualifier(element.getQualifierId(), qualifiers, engine);
for (Attribute attr : qualifier.getAttributes()) {
for (CalculateInfo info : engine.getDependences(element.getId(), attr.getId(), false)) {
Eval eval = new Eval(info.getFormula());
final String old = Util.ELEMENT_PREFIX + element.getId() + Util.ATTRIBUTE_PREFIX + attr.getId();
Attribute attribute = null;
for (Attribute a : main.getAttributes()) if (a.getId() == attr.getId())
attribute = a;
final String newValue;
if (attribute == null)
newValue = "NULL";
else
newValue = Util.ELEMENT_PREFIX + newElement.getId() + Util.ATTRIBUTE_PREFIX + attribute.getId();
eval.replaceValueNames(new Replacementable() {
@Override
public String getNewName(String oldName) {
if (oldName.equals(old))
return newValue;
return null;
}
});
info.setFormula(eval.toString());
engine.setCalculateInfo(info);
}
}
}
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class EvalPlugin method recalculateFunctionOfQualifier.
@SuppressWarnings("unchecked")
private void recalculateFunctionOfQualifier(final Engine engine, AttributeEvent event) {
Qualifier q = StandardAttributesPlugin.getQualifier(engine, event.getElement());
List<Attribute> attrs = new ArrayList<Attribute>();
attrs.add(functionDependenceAttribute);
attrs.add(functionDependenceQualifier);
Hashtable<Element, Object[]> deps = engine.getElements(functionDependences, attrs);
for (Attribute qa : q.getAttributes()) {
for (Entry<Element, Object[]> entry : deps.entrySet()) {
Object[] value = entry.getValue();
if ((((((Long) value[0]).longValue() == qa.getId()) || ((Long) value[0]).longValue() == -1l)) && (((Long) value[1]).longValue() == q.getId())) {
engine.deleteElement(entry.getKey().getId());
}
}
}
if (event.getNewValue() != null) {
Util utils = Util.getUtils(engine);
List<FunctionPersistent> list = (List<FunctionPersistent>) event.getNewValue();
for (FunctionPersistent fp : list) {
if (fp.getAutochange() != 0) {
Eval eval = new Eval(fp.getFunction());
for (MetaValue value : utils.toMetaValues(eval.getValues())) {
if (value != null) {
Element element = engine.createElement(functionDependences.getId());
engine.setAttribute(element, functionDependence, value.getElementId());
engine.setAttribute(element, functionDependenceSourceAttribute, value.getAttributeId());
engine.setAttribute(element, functionDependenceAttribute, fp.getQualifierAttributeId());
engine.setAttribute(element, functionDependenceQualifier, q.getId());
}
}
recalculateQualifierAttribute(engine, q, utils, fp);
}
}
}
}
Aggregations