Hi Ralf,
I am in the process of returning appropriate SKG instance from SKG factory based on three styles we have [Before, After, During]. While looking at the SKG constructor, the code looks bit weird as far as style allocation is concerned. The code looks like the following
boolean returning = "true".equals(params.getProperty("returning"));
_triggerPresent = "true".equals(params.getProperty("trigger", "false"));
if (returning) {
if (!_factoryName.equals(OracleFactory.FACTORY_NAME)
&& !_factoryName.equals(PostgreSQLFactory.FACTORY_NAME)) {
throw new MappingException(Messages.format("mapping.keyGenParamNotCompat",
"returning=\"true\"", getClass().getName(), _factoryName));
}
}
_style = _factoryName.equals(PostgreSQLFactory.FACTORY_NAME)
|| _factoryName.equals(InterbaseFactory.FACTORY_NAME)
|| _factoryName.equals(DB2Factory.FACTORY_NAME)
? BEFORE_INSERT : (returning ? DURING_INSERT : AFTER_INSERT);
if (_triggerPresent && !returning) {
_style = AFTER_INSERT;
}
if (_triggerPresent && (_style == BEFORE_INSERT)) {
throw new MappingException(Messages.format("mapping.keyGenParamNotCompat",
"trigger=\"true\"", getClass().getName(), _factoryName));
}
The styling decision depends on the factory name, trigger presence and returning value. The following 'if' condition in the above is quite tricky and very dirty hack in to the code. I don't know how to handle this scenerio in our intialization.
if (_triggerPresent && !returning) {
_style = AFTER_INSERT;
}
One more thing I want to ask is, Do we provide factory methods in persistance factory to see whether it support 'before', 'after' or 'during' style or we handle it in the way as it is handling currently in the form of 'if' statements.
Also I was thinking to implement the following two additional methods for SKG as you did for IKG
boolean isKeyGeneratorSequenceTypeSupported(int type);
boolean isKeyGeneratorIdentitySupported();
Does this makes sense? or we keep the current methods present in SKG as supportsSQLType and checkSupportedFactory(factory);
Regards, Ahmad
Hi Ralf,
I am in the process of returning appropriate SKG instance from SKG factory based on three styles we have [Before, After, During]. While looking at the SKG constructor, the code looks bit weird as far as style allocation is concerned. The code looks like the following
boolean returning = "true".equals(params.getProperty("returning")); _triggerPresent = "true".equals(params.getProperty("trigger", "false")); if (returning) { if (!_factoryName.equals(OracleFactory.FACTORY_NAME) && !_factoryName.equals(PostgreSQLFactory.FACTORY_NAME)) { throw new MappingException(Messages.format("mapping.keyGenParamNotCompat", "returning=\"true\"", getClass().getName(), _factoryName)); } } _style = _factoryName.equals(PostgreSQLFactory.FACTORY_NAME) || _factoryName.equals(InterbaseFactory.FACTORY_NAME) || _factoryName.equals(DB2Factory.FACTORY_NAME) ? BEFORE_INSERT : (returning ? DURING_INSERT : AFTER_INSERT); if (_triggerPresent && !returning) { _style = AFTER_INSERT; } if (_triggerPresent && (_style == BEFORE_INSERT)) { throw new MappingException(Messages.format("mapping.keyGenParamNotCompat", "trigger=\"true\"", getClass().getName(), _factoryName)); }The styling decision depends on the factory name, trigger presence and returning value. The following 'if' condition in the above is quite tricky and very dirty hack in to the code. I don't know how to handle this scenerio in our intialization.
if (_triggerPresent && !returning) { _style = AFTER_INSERT; }One more thing I want to ask is, Do we provide factory methods in persistance factory to see whether it support 'before', 'after' or 'during' style or we handle it in the way as it is handling currently in the form of 'if' statements.
Also I was thinking to implement the following two additional methods for SKG as you did for IKG
Does this makes sense? or we keep the current methods present in SKG as supportsSQLType and checkSupportedFactory(factory);
Regards, Ahmad