use of org.dbflute.s2dao.metadata.TnPropertyType in project dbflute-core by dbflute.
the class TnQueryInsertDynamicCommand method execute.
// ===================================================================================
// Execute
// =======
public Object execute(Object[] args) {
// analyze arguments
final Entity entity = extractEntityWithCheck(args);
final ConditionBean intoCB = extractIntoConditionBeanWithCheck(args);
final ConditionBean resourceCB = extractResourceConditionBeanWithCheck(args);
final InsertOption<ConditionBean> option = extractInsertOptionWithCheck(args);
prepareStatementConfigOnThreadIfExists(option);
// arguments for execution (not contains an option)
final String[] argNames = new String[] { "entity", "pmb" };
final Class<?>[] argTypes = new Class<?>[] { entity.getClass(), resourceCB.getClass() };
final Object[] realArgs = new Object[] { entity, resourceCB };
// prepare context
final List<TnPropertyType> boundPropTypeList = new ArrayList<TnPropertyType>();
final CommandContext context;
{
final String twoWaySql = buildQueryInsertTwoWaySql(entity, intoCB, resourceCB, option, boundPropTypeList);
context = createCommandContext(twoWaySql, argNames, argTypes, realArgs);
}
// execute
final TnCommandContextHandler handler = createCommandContextHandler(context);
handler.setExceptionMessageSqlArgs(context.getBindVariables());
final boolean identityDisabled = option != null && option.isPrimaryKeyIdentityDisabled();
if (identityDisabled) {
disableIdentityGeneration(entity);
}
final int rows;
RuntimeException sqlEx = null;
try {
rows = handler.execute(realArgs);
} catch (RuntimeException e) {
sqlEx = e;
throw e;
} finally {
if (identityDisabled) {
try {
enableIdentityGeneration(entity);
} catch (RuntimeException e) {
if (sqlEx == null) {
throw e;
}
// ignore the exception when main SQL fails
// not to close the main exception
}
}
}
return Integer.valueOf(rows);
}
use of org.dbflute.s2dao.metadata.TnPropertyType in project dbflute-core by dbflute.
the class TnAbstractEntityHandler method setupInsertBindVariables.
protected void setupInsertBindVariables(Object bean) {
final List<Object> varList = new ArrayList<Object>();
final List<ValueType> varValueTypeList = new ArrayList<ValueType>();
final TnBeanMetaData bmd = getBeanMetaData();
final String timestampPropertyName = bmd.getTimestampPropertyName();
final String versionNoPropertyName = bmd.getVersionNoPropertyName();
for (int i = 0; i < _boundPropTypes.length; ++i) {
final TnPropertyType pt = _boundPropTypes[i];
if (pt.getPropertyName().equalsIgnoreCase(timestampPropertyName)) {
final Timestamp timestamp = ResourceContext.getAccessTimestamp();
addNewTimestamp(timestamp);
varList.add(timestamp);
} else if (pt.getPropertyName().equalsIgnoreCase(versionNoPropertyName)) {
final Long firstNo = InsertOption.VERSION_NO_FIRST_VALUE;
addNewVersionNo(firstNo);
varList.add(firstNo);
} else {
varList.add(pt.getPropertyDesc().getValue(bean));
}
varValueTypeList.add(pt.getValueType());
}
_bindVariables = varList.toArray();
_bindVariableValueTypes = (ValueType[]) varValueTypeList.toArray(new ValueType[varValueTypeList.size()]);
}
use of org.dbflute.s2dao.metadata.TnPropertyType in project dbflute-core by dbflute.
the class TnUpdateEntityDynamicCommand method createUpdatePropertyTypes.
// ===================================================================================
// Update Column
// =============
protected TnPropertyType[] createUpdatePropertyTypes(Object bean, UpdateOption<ConditionBean> option) {
final Set<String> modifiedSet = getModifiedPropertyNames(bean);
final List<TnPropertyType> typeList = new ArrayList<TnPropertyType>();
final String timestampProp = _beanMetaData.getTimestampPropertyName();
final String versionNoProp = _beanMetaData.getVersionNoPropertyName();
final String[] propertyNames = _propertyNames;
for (int i = 0; i < propertyNames.length; ++i) {
final TnPropertyType pt = _beanMetaData.getPropertyType(propertyNames[i]);
if (pt.isPrimaryKey()) {
continue;
}
if (// optimistic lock
isOptimisticLockProperty(timestampProp, versionNoProp, pt) || // statement
isStatementProperty(option, pt) || isSpecifiedProperty(option, modifiedSet, pt)) {
// specified
typeList.add(pt);
}
}
return typeList.toArray(new TnPropertyType[typeList.size()]);
}
use of org.dbflute.s2dao.metadata.TnPropertyType in project dbflute-core by dbflute.
the class TnAbstractEntityHandler method setupUpdateBindVariables.
protected void setupUpdateBindVariables(Object bean) {
final List<Object> varList = new ArrayList<Object>();
final List<ValueType> varValueTypeList = new ArrayList<ValueType>();
// might be null
final Set<String> uniqueDrivenPropSet = extractUniqueDrivenPropSet(bean);
final TnBeanMetaData bmd = getBeanMetaData();
final String timestampPropertyName = bmd.getTimestampPropertyName();
final String versionNoPropertyName = bmd.getVersionNoPropertyName();
for (int i = 0; i < _boundPropTypes.length; ++i) {
final TnPropertyType pt = _boundPropTypes[i];
final String propertyName = pt.getPropertyName();
if (uniqueDrivenPropSet != null && uniqueDrivenPropSet.contains(propertyName)) {
continue;
}
if (propertyName.equalsIgnoreCase(timestampPropertyName)) {
final Timestamp timestamp = ResourceContext.getAccessTimestamp();
addNewTimestamp(timestamp);
varList.add(timestamp);
} else if (propertyName.equalsIgnoreCase(versionNoPropertyName)) {
if (!_versionNoAutoIncrementOnMemory) {
// because of 'VERSION_NO = VERSION_NO + 1'
continue;
}
// already null-checked
final Object value = pt.getPropertyDesc().getValue(bean);
final long longValue = DfTypeUtil.toPrimitiveLong(value) + 1L;
final Long versionNo = Long.valueOf(longValue);
addNewVersionNo(versionNo);
varList.add(versionNo);
} else if (_updateOption != null && _updateOption.hasStatement(pt.getColumnDbName())) {
// because of 'FOO_COUNT = FOO_COUNT + 1'
continue;
} else {
varList.add(pt.getPropertyDesc().getValue(bean));
}
varValueTypeList.add(pt.getValueType());
}
doSetupUpdateWhereBindVariables(varList, varValueTypeList, bean, uniqueDrivenPropSet);
_bindVariables = varList.toArray();
_bindVariableValueTypes = (ValueType[]) varValueTypeList.toArray(new ValueType[varValueTypeList.size()]);
}
use of org.dbflute.s2dao.metadata.TnPropertyType in project dbflute-core by dbflute.
the class TnRelationRowCache method doCreateRelationKeySimple.
protected TnRelationKey doCreateRelationKeySimple(ResultSet rs, TnRelationPropertyType rpt, Map<String, String> selectColumnMap, Map<String, Map<String, Integer>> selectIndexMap, String relationNoSuffix) throws SQLException {
final TnPropertyType pt = rpt.getSimpleUniquePropertyType();
final String columnKeyName = buildColumnKeyName(pt, relationNoSuffix);
final Object keyValue = setupKeyElement(rs, rpt, selectColumnMap, selectIndexMap, columnKeyName, pt, relationNoSuffix);
return keyValue != null ? new TnRelationKeySimple(columnKeyName, keyValue) : null;
}
Aggregations