@Override public List<SInstance> getChildren() { return getFields(); }
@Override public Object getValue() { return getFields(); }
@Override public Object getValue() { return getFields(); }
@Override public List<SInstance> getChildren() { return getFields(); }
@Override public void clearInstance() { getFields().forEach(SInstance::clearInstance); }
@Override public void clearInstance() { getFields().forEach(SInstance::clearInstance); }
/** * Retorna todos os campos do tipo, instanciando os que ainda não foram. * * @return instancias dos campos */ @Nonnull public List<SInstance> getAllFields() { for (SType<?> field : getType().getFields()) getField(field.getNameSimple()); return getFields(); }
@Override public List<RelationalSQLCommmand> toSQLScript() { List<RelationalSQLCommmand> lines = new ArrayList<>(); for (SType<?> tableContext : targetTables) { String tableName = table(tableContext); List<Object> params = new ArrayList<>(); Map<String, Object> containerKeyColumns = new HashMap<>(); List<RelationalColumn> inserted = insertedColumns(tableName, containerKeyColumns); SIComposite tableInstance = instance; if (tableContext != tableContext(instance.getType())) { Optional<SInstance> found = instance.getFields().stream() .filter(field -> tableContext == tableContext(field.getType())).findFirst(); if (found.isPresent()) { tableInstance = (SIComposite) found.get(); } } lines.add(new RelationalSQLCommmand( "insert into " + tableName + " (" + concatenateColumnNames(inserted, ", ") + ") values (" + concatenateColumnValues(inserted, ", ", containerKeyColumns, params) + ")", params, tableInstance, inserted)); } return lines; }
/** * Retorna todos os campos do tipo, instanciando os que ainda não foram. * * @return instancias dos campos */ public List<SInstance> getAllFields() { for (SType<?> field : getType().getFields()) getField(field.getNameSimple()); return getFields(); }
private void copyIdValues(SInstance source, SInstance target) { target.setId(source.getId()); if (source instanceof SIComposite) { SIComposite sourceComposite = (SIComposite) source; SIComposite targetComposite = (SIComposite) target; if (sourceComposite.getFields() != null) { for (int i = 0; i < sourceComposite.getFields().size() ; i++) { copyIdValues(sourceComposite.getField(i), targetComposite.getField(i)); } } } else if (source instanceof SIList) { SIList sourceList = (SIList) source; SIList targetList = (SIList) target; if (sourceList.getChildren() != null) { for (int i = 0; i < sourceList.getChildren().size() ; i++) { SInstance sourceItem = (SInstance) sourceList.getChildren().get(i); SInstance targetItem = (SInstance) targetList.getChildren().get(i); copyIdValues(sourceItem, targetItem); } } } }
private static void copyIdValues(SInstance source, SInstance target) { target.setId(source.getId()); if (source instanceof SIComposite) { SIComposite sourceComposite = (SIComposite) source; SIComposite targetComposite = (SIComposite) target; for (int i = 0; i < sourceComposite.getFields().size() ; i++) { copyIdValues(sourceComposite.getField(i), targetComposite.getField(i)); } } else if (source instanceof SIList) { SIList sourceList = (SIList) source; SIList targetList = (SIList) target; if (sourceList.getChildren() != null) { for (int i = 0; i < sourceList.getChildren().size() ; i++) { SInstance sourceItem = (SInstance) sourceList.getChildren().get(i); SInstance targetItem = (SInstance) targetList.getChildren().get(i); copyIdValues(sourceItem, targetItem); } } } }
private static void copyIdValues(SInstance source, SInstance target) { target.setId(source.getId()); if (source instanceof SIComposite) { SIComposite sourceComposite = (SIComposite) source; SIComposite targetComposite = (SIComposite) target; for (int i = 0; i < sourceComposite.getFields().size() ; i++) { copyIdValues(sourceComposite.getField(i), targetComposite.getField(i)); } } else if (source instanceof SIList) { SIList sourceList = (SIList) source; SIList targetList = (SIList) target; if (sourceList.getChildren() != null) { for (int i = 0; i < sourceList.getChildren().size() ; i++) { SInstance sourceItem = (SInstance) sourceList.getChildren().get(i); SInstance targetItem = (SInstance) targetList.getChildren().get(i); copyIdValues(sourceItem, targetItem); } } } }
private static void copyIdValues(SInstance source, SInstance target) { target.setId(source.getId()); if (source instanceof SIComposite) { SIComposite sourceComposite = (SIComposite) source; SIComposite targetComposite = (SIComposite) target; for (int i = 0; i < sourceComposite.getFields().size() ; i++) { copyIdValues(sourceComposite.getField(i), targetComposite.getField(i)); } } else if (source instanceof SIList) { SIList sourceList = (SIList) source; SIList targetList = (SIList) target; if (sourceList.getChildren() != null) { for (int i = 0; i < sourceList.getChildren().size() ; i++) { SInstance sourceItem = (SInstance) sourceList.getChildren().get(i); SInstance targetItem = (SInstance) targetList.getChildren().get(i); copyIdValues(sourceItem, targetItem); } } } }
/** Gera o xml para instance e para seus dados interno. */ private static MElement toXML(ConfXMLGeneration conf, SInstance instance) { MElement newElement = null; if (instance instanceof SISimple<?>) { SISimple<?> iSimples = (SISimple<?>) instance; String sPersistence = iSimples.toStringPersistence(); if (sPersistence != null) { newElement = conf.createMElementComValor(instance, sPersistence); } else if (conf.isPersistirNull()) { newElement = conf.createMElement(instance); } } else if (instance instanceof SIComposite) { newElement = toXMLChildren(conf, instance, newElement, ((SIComposite) instance).getFields()); } else if (instance instanceof SIList) { newElement = toXMLChildren(conf, instance, newElement, ((SIList<?>) instance).getValues()); } else { throw new SingularFormException("Instancia da classe " + instance.getClass().getName() + " não suportada", instance); } //Verifica se há alguma informação lida anteriormente que deva ser grava novamente newElement = toXMLOldElementWithoutType(conf, instance, newElement); return newElement; }
/** * Cria um mapa onde a chave é o nome do campo e o valor é a informação contida no campo. * Se a instancia for do tipo attachment ela é ignorada automaticamente. * Listas de valores são processadas de forma recursiva e devem informar o código de agrupamento dos valores * @param mapFields * @param instance * @param formVersion */ private void loadMapFromInstance(Map<FormCacheFieldEntity, FormCacheValueEntity> mapFields, SInstance instance, FormVersionEntity formVersion, FormCacheValueEntity parent) { List<SInstance> fieldsInInstance = ((SIComposite) instance).getFields(); for (SInstance field : fieldsInInstance) { if (! field.asAtrIndex().isIndexed() || field instanceof SIAttachment){ continue; } if (field instanceof SIList && !(field.getType() instanceof STypeAttachmentList)) { LoadMapWithItensFromList(mapFields, (SIList) field, formVersion, parent); } if (field instanceof SIComposite) { SIComposite compositeField = (SIComposite) field; FormCacheValueEntity parentFormValue = addItemToMap(mapFields, field, formVersion, parent); loadMapFromInstance(mapFields, compositeField, formVersion, parentFormValue); } if (!(field instanceof SIComposite) && !(field instanceof SIList) && field.getValue() != null) { addItemToMap(mapFields, field, formVersion, parent); } } }
@Override public T toObject(SInstance ins) { if (!(ins instanceof SIComposite)) { throw new SingularFormException("AutoSICompositeConverter somente funciona com instancias compostas.", ins); } if (ins.isEmptyOfData()) { return null; } final SIComposite cins = (SIComposite) ins; final T newInstance = new Mirror().on(resultClass).invoke().constructor().withoutArgs(); final SetterHandler setterHandler = new Mirror().on(newInstance).set(); cins.getFields().forEach(f -> { final FieldSetter setter = setterHandler.field(f.getName()); if (setter != null) { setter.withValue(f.getValue()); } }); return newInstance; }
@Override public T toObject(SInstance ins) { if (!(ins instanceof SIComposite)) { throw new SingularFormException("AutoSICompositeConverter somente funciona com instancias compostas."); } if (ins.isEmptyOfData()) { return null; } final SIComposite cins = (SIComposite) ins; final T newInstance = new Mirror().on(resultClass).invoke().constructor().withoutArgs(); final SetterHandler setterHandler = new Mirror().on(newInstance).set(); cins.getFields().forEach(f -> { final FieldSetter setter = setterHandler.field(f.getName()); if (setter != null) { setter.withValue(f.getValue()); } }); return newInstance; }