@Override public boolean update(PropertyMeta propertyMeta) { propertyMetaRepository.saveAndFlush(propertyMeta); try { jdbcTemplate.execute(this.dropView(propertyMeta.getTenantId(), propertyMeta.getObjectName())); } catch (Exception e) { } jdbcTemplate.execute(this.createView(propertyMeta.getTenantId(), propertyMeta.getObjectName())); return true; }
private String dropColumn(PropertyMeta propertyMeta) { StringBuffer alterTableDropColumn = new StringBuffer(); alterTableDropColumn .append("alter table ") .append(propertyMeta.getObjectName()) .append(" drop(") .append(propertyMeta.getInternalName()) .append(" ") .append(")"); return alterTableDropColumn.toString(); }
@Override public boolean delete(Long id) { PropertyMeta propertyMeta = propertyMetaRepository.findOne(id); jdbcTemplate.execute(this.dropColumn(propertyMeta)); propertyMetaRepository.delete(propertyMeta); try { jdbcTemplate.execute(this.dropView(propertyMeta.getTenantId(), propertyMeta.getObjectName())); } catch (Exception e) { } jdbcTemplate.execute(this.createView(propertyMeta.getTenantId(), propertyMeta.getObjectName())); return true; }
// create view T_ORDER_TENANT1005_VIEW as select order_id from T_ORDER private String createView(String tenantId, String objectName) { List<PropertyMeta> propertiesMeta = propertyMetaRepository.findByTenantIdAndObjectName(tenantId, objectName); StringBuffer createView = new StringBuffer(); createView .append("create view ") .append(objectName) .append("_") .append(tenantId) .append("_") .append("VIEW as select "); for (PropertyMeta propertyMeta : propertiesMeta) { createView .append(" ") .append(propertyMeta.getInternalName()) .append(" as ") .append(propertyMeta.getDisplayName()) .append(", "); } createView.deleteCharAt(createView.lastIndexOf(",")); createView.append(" from ").append(objectName); return createView.toString(); }