ru.curs.celesta.score.ColumnMeta Maven / Gradle / Ivy
The newest version!
package ru.curs.celesta.score;
/**
* Meta information about column of a table or a view.
*
* @param Java class of column value
*/
public interface ColumnMeta {
/**
* Returns column name.
*
* @return
*/
String getName();
/**
* Name of jdbcGetter that should be used for getting column data.
*
* @return
*/
String jdbcGetterName();
/**
* Celesta data type that corresponds to the field.
*
* @return
*/
String getCelestaType();
/**
* Returns corresponding Java data type.
*
* @return
*/
Class> getJavaClass();
/**
* Whether the field is nullable.
*
* @return
*/
boolean isNullable();
/**
* Column's CelestaDoc.
*
* @return
*/
String getCelestaDoc();
/**
* Returns column ordering if any.
*
* @return {@code null} if ordering is unspecified
*/
default Ordering ordering() {
return null;
}
/**
* Returns {@code this} column meta information with ascending ordering set.
*
* @return
*/
default ColumnMeta asc() {
return new ColumnMetaOrderingDecorator<>(this, Ordering.ASC);
}
/**
* Returns {@code this} column meta information with descending ordering set.
*
* @return
*/
default ColumnMeta desc() {
return new ColumnMetaOrderingDecorator<>(this, Ordering.DESC);
}
/**
* Column ordering specifier.
*/
enum Ordering {
/**
* Ascending order.
*/
ASC,
/**
* Descending order.
*/
DESC
}
}
abstract class ColumnMetaAdaptor implements ColumnMeta {
final ColumnMeta column;
ColumnMetaAdaptor(ColumnMeta column) {
this.column = column;
}
@Override
public String getName() {
return column.getName();
}
@Override
public String jdbcGetterName() {
return column.jdbcGetterName();
}
@Override
public String getCelestaType() {
return column.getCelestaType();
}
@Override
public Class> getJavaClass() {
return column.getJavaClass();
}
@Override
public boolean isNullable() {
return column.isNullable();
}
@Override
public String getCelestaDoc() {
return column.getCelestaDoc();
}
}
final class ColumnMetaOrderingDecorator extends ColumnMetaAdaptor {
private final Ordering ordering;
ColumnMetaOrderingDecorator(ColumnMeta column, Ordering ordering) {
super(column);
this.ordering = ordering;
}
@Override
public Ordering ordering() {
return ordering;
}
@Override
public ColumnMetaOrderingDecorator asc() {
return (ordering != Ordering.ASC) ? new ColumnMetaOrderingDecorator<>(column, Ordering.ASC) : this;
}
@Override
public ColumnMetaOrderingDecorator desc() {
return (ordering != Ordering.DESC) ? new ColumnMetaOrderingDecorator<>(column, Ordering.DESC) : this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy