use of com.ramussoft.common.attribute.AttributePlugin in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method getAttributeWhatWillBeDeleted.
private Transaction getAttributeWhatWillBeDeleted(long elementId, Attribute attribute, boolean attributeDeteting) {
final Transaction transaction = new Transaction();
AttributePlugin plugin = factory.getAttributePlugin(attribute.getAttributeType());
final Class<? extends Persistent>[] classes;
if (elementId >= 0)
classes = plugin.getAttributePersistents();
else
classes = plugin.getAttributePropertyPersistents();
for (int i = 0; i < classes.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);
boolean delete = false;
for (PersistentField field : row.getFields()) {
if (field.isAutoset()) {
if (field.getType() == PersistentField.ELEMENT) {
params.add(elementId);
paramFields.add(field.getDatabaseName());
if (!attributeDeteting)
delete = true;
} else if (field.getType() == PersistentField.ATTRIBUTE) {
params.add(attribute.getId());
paramFields.add(field.getDatabaseName());
if (attributeDeteting)
delete = true;
} else if (field.getType() == PersistentField.VALUE_BRANCH_ID) {
params.add(getActiveBranchId());
paramFields.add(field.getDatabaseName());
if (attributeDeteting)
delete = true;
}
}
}
if (delete) {
StringBuffer sb = new StringBuffer("SELECT * FROM " + row.getTableName() + " WHERE ");
boolean first = true;
for (int x = 0; x < params.size(); x++) {
if (first) {
first = false;
} else {
sb.append(" AND ");
}
sb.append(paramFields.get(x));
sb.append("=?");
}
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);
}
transaction.getDelete().add(persistent);
return null;
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
throw new RuntimeException();
}
}, params.toArray(new Object[params.size()]), true);
}
}
transaction.setRemoveBranchInfo(true);
return transaction;
}
use of com.ramussoft.common.attribute.AttributePlugin 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.AttributePlugin 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.AttributePlugin in project ramus by Vitaliy-Yakovchuk.
the class IEngineImpl method getElements.
@SuppressWarnings("unchecked")
@Override
public List<Element> getElements(long qualifierId, Attribute attribute, FindObject[] findObjects) {
AttributePlugin plugin = factory.getAttributePlugin(attribute.getAttributeType());
Class<? extends Persistent> clazz = plugin.getAttributePersistents()[0];
String name = prefix + "attribute_" + clazz.getAnnotation(Table.class).name();
String w = findObjects[0].getField() + "=?";
for (int i = 1; i < findObjects.length; i++) {
w += " AND " + findObjects[i].getField() + "=?";
}
List<Object> objects = new ArrayList<Object>(findObjects.length + 1);
long branchId = getActiveBranchId();
objects.add(branchId);
objects.add(branchId);
objects.add(qualifierId);
for (int i = 0; i < findObjects.length; i++) {
objects.add(findObjects[i].getObject());
}
Qualifier qualifier = getQualifier(qualifierId);
long attr = qualifier.getAttributeForName();
String where = " AND attribute_id=" + attr + " AND elmts.element_id=element_id";
objects.add(branchId);
objects.add(branchId);
return template.query("SELECT ELEMENT_ID, elmts.QUALIFIER_ID, (SELECT value FROM " + prefix + "attribute_texts WHERE element_id=elmts.element_id AND attribute_id=" + attr + " " + " AND (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))) AS ELEMENT_TEXT_NAME FROM " + prefix + "elements elmts, " + prefix + "qualifiers q WHERE elmts.QUALIFIER_ID=? AND elmts.qualifier_id=q.qualifier_id " + "AND elmts.ELEMENT_ID IN (SELECT ELEMENT_ID FROM " + name + " WHERE " + w + ") AND elmts.created_branch_id <=? " + "AND (elmts.removed_branch_id>? ) ORDER BY ELEMENT_ID", new ElementRowMapper(), objects.toArray(), true);
}
use of com.ramussoft.common.attribute.AttributePlugin in project ramus by Vitaliy-Yakovchuk.
the class AboutDialog method createPluginListComponent.
private Component createPluginListComponent() {
JScrollPane pane = new JScrollPane();
Object[][] data = new Object[plugins.size()][];
for (int i = 0; i < plugins.size(); i++) {
Plugin plugin = plugins.get(i);
String name = plugin.getName();
if (plugin instanceof AttributePlugin)
name = "Attribute." + name + "." + ((AttributePlugin) plugin).getTypeName();
data[i] = new Object[] { name };
}
Arrays.sort(data, new Comparator<Object[]>() {
@SuppressWarnings("unchecked")
@Override
public int compare(Object[] o1, Object[] o2) {
return ((Comparable<String>) o1[0]).compareTo((String) o2[0]);
}
});
DefaultTableModel model = new DefaultTableModel(data, new Object[] { GlobalResourcesManager.getString("Plugin.Name") }) {
/**
*/
private static final long serialVersionUID = -1986847073145962545L;
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
pane.setViewportView(new JTable(model));
return pane;
}
Aggregations