use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class ReportPlugin method setReportName.
public static void setReportName(Engine engine, Element element, String name) {
Attribute attribute = getReportPlugin(engine).reportName;
engine.setAttribute(element, attribute, name);
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method setBinaryAttribute.
// @SuppressWarnings("unused")
@Override
public boolean setBinaryAttribute(final long elementId, final long attributeId, final Transaction transaction) {
if (elementId >= 0) {
long qualifierId = getQualifierIdForElement(elementId);
Qualifier qualifier = getQualifier(qualifierId);
boolean attr = false;
if ((qualifier == null) && (Metadata.DEBUG)) {
System.err.println("WARNING: Can not set attribute for not existing element");
throw new RuntimeException("WARNING: Can not set attribute for not existing element");
}
for (Attribute attribute : qualifier.getAttributes()) {
if (attributeId == attribute.getId()) {
attr = true;
}
}
for (Attribute attribute : qualifier.getSystemAttributes()) {
if (attributeId == attribute.getId()) {
attr = true;
}
}
if (!attr) {
throw new RuntimeException("Attribute with id: " + attributeId + " not found for qualifier: " + qualifier);
}
}
Attribute propertyAttribute = getAttribute(attributeId);
if (elementId < 0l && propertyAttribute != null && propertyAttribute.getAttributeType().toString().equals("Core.Variant")) {
} else if (!getAccessor().canUpdateElement(elementId, attributeId))
return false;
process(transaction.getDelete(), elementId, attributeId);
process(transaction.getUpdate(), elementId, attributeId);
process(transaction.getSave(), elementId, attributeId);
if (elementId >= 0 && propertyAttribute.getAttributeType().getTypeName().equals("ElementList") && propertyAttribute.getAttributeType().getPluginName().equals("Core")) {
try {
setElistFix(transaction);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
return (Boolean) template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
executeTransaction(transaction, connection);
long branch = getActiveBranchId();
Boolean res = Boolean.FALSE;
if (branch > 0l) {
PreparedStatement ps = template.getPreparedStatement("SELECT branch_id FROM " + prefix + "attributes_data_metadata WHERE branch_id=? AND attribute_id=? AND element_id=?", true);
ps.setLong(1, branch);
ps.setLong(2, attributeId);
ps.setLong(3, elementId);
ResultSet rs = ps.executeQuery();
if (!rs.next() && !transaction.isRemoveBranchInfo()) {
rs.close();
ps = template.getPreparedStatement("INSERT INTO " + prefix + "attributes_data_metadata(element_id, attribute_id, branch_id) VALUES(?, ?, ?)", true);
ps.setLong(1, elementId);
ps.setLong(2, attributeId);
ps.setLong(3, branch);
ps.execute();
res = Boolean.TRUE;
} else {
rs.close();
if (transaction.isRemoveBranchInfo()) {
ps = template.getPreparedStatement("DELETE FROM " + prefix + "attributes_data_metadata WHERE branch_id=? AND attribute_id=? AND element_id=?", false);
ps.setLong(1, branch);
ps.setLong(2, attributeId);
ps.setLong(3, elementId);
ps.execute();
ps.close();
}
}
}
return res;
}
});
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method setElementQualifier.
@Override
public void setElementQualifier(final long elementId, final long qualifierId) {
throwExaptionIfNotCan(getAccessor().canDeleteElements(new long[] { elementId }), "Can not update element's qualifier.");
throwExaptionIfNotCan(getAccessor().canCreateElement(qualifierId), "Can not update element's qualifier.");
Element element = getElement(elementId);
Qualifier current = getQualifier(element.getQualifierId());
Qualifier newQualifier = getQualifier(qualifierId);
final List<Attribute> attrs = new ArrayList<Attribute>();
addNotPresentAttributes(current.getAttributes(), newQualifier.getAttributes(), attrs);
addNotPresentAttributes(current.getSystemAttributes(), newQualifier.getSystemAttributes(), attrs);
template.execute(new JDBCCallback() {
@Override
public Object execute(Connection connection) throws SQLException {
Transaction[] transactions = getAttributesWhatWillBeDeleted(elementId, attrs);
for (Transaction transaction : transactions) {
executeTransaction(transaction, connection);
}
PreparedStatement ps = connection.prepareStatement("UPDATE " + prefix + "elements SET QUALIFIER_ID=? WHERE ELEMENT_ID=?");
ps.setLong(1, qualifierId);
ps.setLong(2, elementId);
ps.execute();
ps.close();
return null;
}
});
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method getBinaryBranchAttribute.
@Override
public List<Persistent>[] getBinaryBranchAttribute(long elementId, long attributeId, long branchId) {
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>(3);
ArrayList<String> paramFields = new ArrayList<String>(3);
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());
}
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;
}
use of com.ramussoft.common.Attribute in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method createAttribute.
@Override
public Attribute createAttribute(long attributeId, AttributeType attributeType, boolean system) {
throwExaptionIfNotCan(getAccessor().canCreateAttribute(), "Can not create attribute.");
if (attributeId == -1) {
attributeId = nextValue("attributes_sequence");
long id = template.queryForLong("SELECT MAX(ATTRIBUTE_ID) FROM " + prefix + "attributes;");
while (id >= attributeId) {
attributeId = template.nextVal(prefix + "attributes_sequence");
}
}
Attribute attribute = new Attribute();
attribute.setId(attributeId);
attribute.setAttributeType(attributeType);
attribute.setSystem(system);
long branchId = getActiveBranchId();
Long l = (Long) template.queryForObjects("SELECT COUNT(*) FROM " + prefix + "attributes WHERE ATTRIBUTE_ID=? AND removed_branch_id=?", new RowMapper() {
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getLong(1);
}
}, new Object[] { attributeId, branchId }, false);
if (l.longValue() > 0)
template.update("UPDATE " + prefix + "attributes SET ATTRIBUTE_NAME=?, ATTRIBUTE_SYSTEM=?, ATTRIBUTE_TYPE_PLUGIN_NAME=?, ATTRIBUTE_TYPE_NAME=?, ATTRIBUTE_TYPE_COMPARABLE=?, " + "removed_branch_id=? WHERE ATTRIBUTE_ID = ? AND removed_branch_id=?", new Object[] { attribute.getName(), system, attributeType.getPluginName(), attributeType.getTypeName(), attributeType.isComparable(), Integer.MAX_VALUE, attribute.getId(), branchId }, true);
else
template.update("INSERT INTO " + prefix + "attributes(ATTRIBUTE_ID, ATTRIBUTE_NAME, ATTRIBUTE_SYSTEM, ATTRIBUTE_TYPE_PLUGIN_NAME, ATTRIBUTE_TYPE_NAME, ATTRIBUTE_TYPE_COMPARABLE, created_branch_id) " + "VALUES(?, ?, ?, ?, ?, ?, ?)", new Object[] { attribute.getId(), attribute.getName(), system, attributeType.getPluginName(), attributeType.getTypeName(), attributeType.isComparable(), branchId }, true);
return attribute;
}
Aggregations