hw09-SelfmadeORM - #12
Open
1121977 wants to merge 5 commits into
Open
Conversation
petrelevich
reviewed
Feb 9, 2021
| import java.util.List; | ||
|
|
||
| public class EntityClassMetaDataImpl<T> implements EntityClassMetaData <T>{ | ||
| T objectData; |
|
|
||
| @Override | ||
| public String getName() { | ||
| return Arrays.stream(objectData.getClass().getName().toLowerCase().split("\\.")).reduce((first, second)->second).get(); |
There was a problem hiding this comment.
попробуйте:
EntityClassMetaDataImpl.class.getSimpleName()
| return field; | ||
| } | ||
| } | ||
| return null; |
There was a problem hiding this comment.
лучше исключение выбрасывать вместо null.
Тем более, что не везде есть обработка null,
например, как этот фрагмент отработает ?
public List<Field> getAllFields() {
List<Field> fields = new ArrayList<>();
fields.add(getIdField());
fields.addAll(getFieldsWithoutId());
return fields;
}
|
|
||
| @Override | ||
| public Constructor<T> getConstructor() { | ||
| return null; |
There was a problem hiding this comment.
почему тут вместо констуктора null ?
|
|
||
| public class EntitySQLMetaDataImpl implements EntitySQLMetaData { | ||
| Class<?> clazz; | ||
| EntityClassMetaData entityClassMetaData; |
| List<Field> fieldsList = entityClassMetaData.getFieldsWithoutId(); | ||
| Iterator<Field> fieldListIterator = fieldsList.iterator(); | ||
| while (fieldListIterator.hasNext()){ | ||
| stringSelectByIdSql = stringSelectByIdSql + fieldListIterator.next().getName() + ", "; |
| id, rs -> { | ||
| try { | ||
| if (rs.next()) { | ||
| Constructor<T> constructorT = clazz.getConstructor(new Class<?>[]{}); |
There was a problem hiding this comment.
тут бы пригодился метод
public Constructor<T> getConstructor()
который null возвращает.
| for (Field field : clazz.getDeclaredFields()) { | ||
| boolean access = field.canAccess(resultT); | ||
| field.setAccessible(true); | ||
| field.set(resultT, getValue(rs, field)); |
There was a problem hiding this comment.
функционал "получить значение поля", "установить значение поля" лучше в отдельные методы вынести.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.