Skip to content

hw09-SelfmadeORM - #12

Open
1121977 wants to merge 5 commits into
masterfrom
hw09-SelfMadeORM
Open

hw09-SelfmadeORM#12
1121977 wants to merge 5 commits into
masterfrom
hw09-SelfMadeORM

Conversation

@1121977

@1121977 1121977 commented Feb 4, 2021

Copy link
Copy Markdown
Owner

No description provided.

import java.util.List;

public class EntityClassMetaDataImpl<T> implements EntityClassMetaData <T>{
T objectData;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не забывайте про private final


@Override
public String getName() {
return Arrays.stream(objectData.getClass().getName().toLowerCase().split("\\.")).reduce((first, second)->second).get();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

попробуйте:
EntityClassMetaDataImpl.class.getSimpleName()

return field;
}
}
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше исключение выбрасывать вместо 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему тут вместо констуктора null ?


public class EntitySQLMetaDataImpl implements EntitySQLMetaData {
Class<?> clazz;
EntityClassMetaData entityClassMetaData;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private final

List<Field> fieldsList = entityClassMetaData.getFieldsWithoutId();
Iterator<Field> fieldListIterator = fieldsList.iterator();
while (fieldListIterator.hasNext()){
stringSelectByIdSql = stringSelectByIdSql + fieldListIterator.next().getName() + ", ";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

посмотрите String.join()

id, rs -> {
try {
if (rs.next()) {
Constructor<T> constructorT = clazz.getConstructor(new Class<?>[]{});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут бы пригодился метод
public Constructor<T> getConstructor()
который null возвращает.

for (Field field : clazz.getDeclaredFields()) {
boolean access = field.canAccess(resultT);
field.setAccessible(true);
field.set(resultT, getValue(rs, field));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

функционал "получить значение поля", "установить значение поля" лучше в отдельные методы вынести.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants