use of org.dbflute.s2dao.metadata.TnRelationPropertyType in project dbflute-core by dbflute.
the class TnBeanMetaDataImpl method setupProperty.
protected void setupProperty() {
// only called in the initialize() process
final TnPropertyType[] propertyTypes = _propertyTypeFactory.createBeanPropertyTypes();
for (int i = 0; i < propertyTypes.length; i++) {
TnPropertyType pt = propertyTypes[i];
addPropertyType(pt);
_columnPropertyTypeMap.put(pt.getColumnDbName(), pt);
}
final TnRelationPropertyType[] rptTypes = _relationPropertyTypeFactory.createRelationPropertyTypes();
for (int i = 0; i < rptTypes.length; i++) {
TnRelationPropertyType rpt = rptTypes[i];
addRelationPropertyType(rpt);
}
}
use of org.dbflute.s2dao.metadata.TnRelationPropertyType in project dbflute-core by dbflute.
the class TnRelationRowCreatorExtension method setupNextRelationRow.
// -----------------------------------------------------
// Next Relation
// -------------
protected void setupNextRelationRow(TnRelationRowCreationResource res) throws SQLException {
final TnBeanMetaData nextBmd = res.getRelationBeanMetaData();
final Object row = res.getRow();
res.prepareNextLevelMapping();
try {
final List<TnRelationPropertyType> nextRptList = nextBmd.getRelationPropertyTypeList();
for (TnRelationPropertyType nextRpt : nextRptList) {
setupNextRelationRowElement(res, row, nextRpt);
}
} finally {
res.setRow(row);
res.closeNextLevelMapping();
}
}
use of org.dbflute.s2dao.metadata.TnRelationPropertyType in project dbflute-core by dbflute.
the class TnRelationRowCreatorExtension method mappingNextRelation.
/**
* Do mapping next relation row. <br>
* This logic is similar to first relation mapping in {@link TnBeanListResultSetHandler}. <br>
* So you should check it when this logic has modification.
* @param res The resource of relation row creation. (NotNull)
* @param row The base point row, which is previous relation row. (NotNull)
* @throws SQLException When it fails to handle the SQL.
*/
protected void mappingNextRelation(TnRelationRowCreationResource res, Object row) throws SQLException {
if (res.isStopCurrentRelationMapping()) {
return;
}
// also saves it in resource
final TnRelationKey relKey = res.prepareRelationKey();
final TnRelationPropertyType rpt = res.getRelationPropertyType();
Object relationRow = null;
if (relKey != null) {
final String relationNoSuffix = res.getRelationNoSuffix();
final boolean canUseRelationCache = res.canUseRelationCache();
TnRelationRowCache relRowCache = null;
if (canUseRelationCache) {
relRowCache = res.getRelRowCache();
relationRow = relRowCache.getRelationRow(relationNoSuffix, relKey);
}
if (relationRow == null) {
// when no cache
relationRow = createRelationRow(res);
if (relationRow != null) {
// is new created relation row
adjustCreatedRelationRow(relationRow, res.getRelationNoSuffix(), res.getRelationSelector(), rpt);
if (canUseRelationCache) {
relRowCache.addRelationRow(relationNoSuffix, relKey, relationRow);
}
}
}
}
// if exists, optional or plain value
// if null, empty optional or nothing
relationRow = filterOptionalRelationRowIfNeeds(row, rpt, relationRow);
if (relationRow != null) {
// exists or empty optional
rpt.getPropertyAccessor().setValue(row, relationRow);
}
}
use of org.dbflute.s2dao.metadata.TnRelationPropertyType in project dbflute-core by dbflute.
the class TnRelationRowCreatorExtension method setupRelationKeyValue.
// ===================================================================================
// Relation KeyValue Setup
// =======================
@Override
protected void setupRelationKeyValue(TnRelationRowCreationResource res) {
// /= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// setup of relation key is handled at all-value setup marked as '#RELKEY'
// so only entity instance creation exists in this method
// = = = = = = = = = =/
final TnRelationPropertyType rpt = res.getRelationPropertyType();
final TnBeanMetaData yourBmd = rpt.getYourBeanMetaData();
if (!res.hasRowInstance()) {
// always no instance here (check just in case)
final DBMeta dbmeta = yourBmd.getDBMeta();
final Object row = newRelationRow(rpt, res.getRelationSelector(), res.getRelationNoSuffix(), dbmeta);
res.setRow(row);
}
}
use of org.dbflute.s2dao.metadata.TnRelationPropertyType in project dbflute-core by dbflute.
the class TnBeanMetaDataImpl method convertFullColumnName.
public String convertFullColumnName(String alias) {
if (hasPropertyTypeByColumnName(alias)) {
return _tableName + "." + alias;
}
final int index = alias.lastIndexOf('_');
if (index < 0) {
String msg = "The alias was not found in the table: table=" + _tableName + " alias=" + alias;
throw new IllegalStateException(msg);
}
final String columnName = alias.substring(0, index);
final String relnoStr = alias.substring(index + 1);
int relno = -1;
try {
relno = Integer.parseInt(relnoStr);
} catch (Throwable t) {
String msg = "The alias was not found in the table: table=" + _tableName + " alias=" + alias;
throw new IllegalStateException(msg, t);
}
final TnRelationPropertyType rpt = getRelationPropertyType(relno);
if (!rpt.getYourBeanMetaData().hasPropertyTypeByColumnName(columnName)) {
String msg = "The alias was not found in the table: table=" + _tableName + " alias=" + alias;
throw new IllegalStateException(msg);
}
return rpt.getPropertyName() + "." + columnName;
}
Aggregations