public static String getSeparator() { initialize(); if(plainSqlMapping) return "_"; return "."; }
/** * Returns an EntityDataBuilder instance which can be used to construct an entityData from scratch. * @return An instance of EntityDataBuilder. */ public static EntityDataBuilder getBuilder() { return new DefaultEntityDataBuilder(); }
@SuppressWarnings("unchecked") @Override public Map<String, Object> asMap() { return (Map<String, Object>) cloneDeepMap((Map<String, Object>) properties, associationProperties); }
static String getPersistenceName(String fqEntityName, String elementName) { String persistenceName = null; if(isHdbcdsMode == null) isHdbcdsMode = CSNUtil.isHdbcdsMapping(); if(isHdbcdsMode) persistenceName = CSNUtil.getPersistenceName(fqEntityName, elementName); if (persistenceName == null) if (elementName != null) persistenceName = elementName; else persistenceName = replaceDotIfRequired(fqEntityName); return quoteIfRequired(persistenceName); }
public static String getCDSDataType(String entityName, String serviceName, String propName) { JsonNode entityNode = getCsn().get("definitions").get(serviceName + "." + entityName); if (entityNode != null) { return entityNode.get("elements").get(propName).get("type").asText(); } return null; }
public static String replaceDotIfRequired(String name) { if(name == null) return null; else return name.replaceAll("\\.", getSeparator()); }
private void appendCount(StringBuilder queryString) { queryString.append(SPACE).append("COUNT").append(LEFTBRACE+quoteIfRequired(count)+RIGHTBRACE); if(selectColumn != null){ queryString.append(COMMA).append(SPACE).append(selectColumn); } }
private static void initialize() { if(plainSqlMapping == null) plainSqlMapping = CSNUtil.isPlainSqlMapping(); }
private HashMap<String, ElementType> copyElementTypes(EntityMetadata em) { if(em instanceof DefaultEntityData) return ((DefaultEntityMetadata)em).getElementTypes(); HashMap<String, ElementType> elementTypes = new HashMap<>(); for(String element : em.getElementNames()) { elementTypes.put(element, em.getElementType(element)); } return elementTypes; }
public static boolean isDraftEnabledEntity(String entityName, String serviceName) { JsonNode csn = getCsn(); if (csn == null) return false; JsonNode draftEnabled = csn.get("definitions").get(serviceName + "." + entityName).get(DRAFT_ENABLED); return draftEnabled != null && "true".equals(draftEnabled.asText()); }
public static boolean isPlainSqlMapping() { initialize(); return plainSqlMapping; }
/** * Returns an EntityDataBuilder instance which is partially initialized based on the passed entityData. * This method should be used if you need to construct an entityData starting from an existing entityData. * * For example:- You have an entityData for an entity Customer. But you would like to add an extra element to this entityData for the name of the Customer's company. * The first step you have to do is to get a builder by passing the existing entitydata. * EntityDataBuilder builder = EntityData.getBuilder(customerEntityData); * * Once you have the builder you can add the extra element, by calling the addElement method. * * * @param entityData The entityData from which a new EntityData is to be constructed, for example by adding an extra element. * @return An instance of EntityDataBuilder which is initialized based on the passed EntityData. */ public static EntityDataBuilder getBuilder(EntityData entityData) { return new DefaultEntityDataBuilder(entityData); }
/** * Sets the column based on which the condition is created. * @param columnName Name of the column * @return A builder with which you can set the operator and operand of the condition */ public OperatorBuilder columnName(String columnName){ condition.append(quoteIfRequired(columnName)); return new OperatorBuilder(condition); }
public static boolean isHdbcdsMapping() { JsonNode csn = getCsn(); if (csn == null) return false; String sqlMapping = csn.get(SQL_MAPPING) == null ? null : csn.get(SQL_MAPPING).asText(); return sqlMapping != null && sqlMapping.equals("hdbcds"); }
public static String quoteIfRequired(String sqlPart) { initialize(); if(plainSqlMapping) return sqlPart; return '"' + sqlPart + '"'; }
public static boolean isUpdatable(String serviceName, String entityName) throws CSNNotSetException { JsonNode csn = getCsn(); if (csn == null) return true; JsonNode updatable = csn.get("definitions").get(serviceName + "." + entityName) .get("@Capabilities.UpdateRestrictions.Updatable"); return updatable == null || updatable.asText().equals("true"); }
public static String convertToUpperCaseIfRequired(String sqlPart) { initialize(); if(plainSqlMapping) return sqlPart.toUpperCase(); return sqlPart; }
public static boolean isDeletable(String serviceName, String entityName) throws CSNNotSetException { JsonNode csn = getCsn(); if (csn == null) return true; JsonNode deletable = csn.get("definitions").get(serviceName + "." + entityName) .get("@Capabilities.DeleteRestrictions.Deletable"); return deletable == null || deletable.asText().equals("true"); }
public static boolean isDraftNodeEntity(String entityName,String serviceName) { JsonNode csn = getCsn(); if(csn == null){ return false; } JsonNode draftEnabled = csn.get("definitions").get(serviceName + "." + entityName).get(DRAFT_NODE); return draftEnabled != null && "draftPrepare".equals(draftEnabled.asText()); }
public static boolean isCreatable(String serviceName, String entityName) throws CSNNotSetException { JsonNode csn = getCsn(); if (csn == null) return true; JsonNode insertable = csn.get("definitions").get(serviceName + "." + entityName) .get("@Capabilities.InsertRestrictions.Insertable"); return insertable == null || insertable.asText().equals("true"); }