|
|
@ -246,17 +246,28 @@ public class Repository<T>
|
|
|
|
return fields;
|
|
|
|
return fields;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Field[] cacheFields = null;
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private Field[] getFields()
|
|
|
|
private Field[] getFields()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (cacheFields == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<Field> fields = new ArrayList<>();
|
|
|
|
List<Field> fields = new ArrayList<>();
|
|
|
|
List<Pair<Field, Column>> columns = getFieldColumnPairs();
|
|
|
|
List<Pair<Field, Column>> columns = getFieldColumnPairs();
|
|
|
|
for (Pair<Field, Column> pair : columns) fields.add(pair.getLeft());
|
|
|
|
for (Pair<Field, Column> pair : columns) fields.add(pair.getLeft());
|
|
|
|
return fields.toArray(new Field[]{});
|
|
|
|
cacheFields = fields.toArray(new Field[]{});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cacheFields;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String[] cacheColumnNames = null;
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private String[] getColumnNames()
|
|
|
|
private String[] getColumnNames()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (cacheColumnNames == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<String> names = new ArrayList<>();
|
|
|
|
List<String> names = new ArrayList<>();
|
|
|
|
List<Pair<Field, Column>> columns = getFieldColumnPairs();
|
|
|
|
List<Pair<Field, Column>> columns = getFieldColumnPairs();
|
|
|
@ -269,35 +280,64 @@ public class Repository<T>
|
|
|
|
names.add(cname);
|
|
|
|
names.add(cname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return names.toArray(new String[]{});
|
|
|
|
cacheColumnNames = names.toArray(new String[]{});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cacheColumnNames;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String cacheTableName = null;
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private String getTableName()
|
|
|
|
private String getTableName()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (cacheTableName == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
String name = getTableAnnotation().name();
|
|
|
|
String name = getTableAnnotation().name();
|
|
|
|
if (name.isEmpty()) throw new RuntimeException("Table name is empty");
|
|
|
|
if (name.isEmpty()) throw new RuntimeException("Table name is empty");
|
|
|
|
return name;
|
|
|
|
cacheTableName = name;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return cacheTableName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String cacheIdName = null;
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private String getIdName()
|
|
|
|
private String getIdName()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (cacheIdName == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
String id = getTableAnnotation().id();
|
|
|
|
String id = getTableAnnotation().id();
|
|
|
|
if (id.isEmpty()) throw new RuntimeException("Table id is empty");
|
|
|
|
if (id.isEmpty()) throw new RuntimeException("Table id is empty");
|
|
|
|
return id;
|
|
|
|
cacheIdName = id;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cacheIdName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Field cacheIdField = null;
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private Field getIdField()
|
|
|
|
private Field getIdField()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (cacheIdField == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Field fields[] = getFields();
|
|
|
|
Field fields[] = getFields();
|
|
|
|
String idName = getIdName();
|
|
|
|
String idName = getIdName();
|
|
|
|
for (Field f : fields)
|
|
|
|
for (Field f : fields)
|
|
|
|
if (f.getName().equals(idName)) return f;
|
|
|
|
if (f.getName().equals(idName))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
cacheIdField = f;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cacheIdField == null)
|
|
|
|
throw new RuntimeException("Field not found: " + idName);
|
|
|
|
throw new RuntimeException("Field not found: " + idName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cacheIdField;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private Table getTableAnnotation()
|
|
|
|
private Table getTableAnnotation()
|
|
|
|
{
|
|
|
|
{
|
|
|
|