@@ -157,7 +157,7 @@ public abstract class AbstractEntityPersister : AbstractPropertyMapping, IOuterJ
157
157
private SqlCommandInfo [ ] sqlInsertStrings ;
158
158
private SqlCommandInfo sqlIdentityInsertString ;
159
159
private SqlCommandInfo [ ] sqlUpdateStrings ;
160
- private SqlString sqlConcreteSelectString ;
160
+ private SqlString sqlSnapshotSelectString ;
161
161
private SqlString sqlVersionSelectString ;
162
162
private bool [ ] tableHasColumns ;
163
163
@@ -1503,7 +1503,7 @@ protected object GetGeneratedIdentity(object obj, ISessionImplementor session, I
1503
1503
return id ;
1504
1504
}
1505
1505
1506
- public object [ ] GetCurrentPersistentState ( object id , object version , ISessionImplementor session )
1506
+ public object [ ] GetDatabaseSnapshot ( object id , object version , ISessionImplementor session )
1507
1507
{
1508
1508
if ( ! HasSelectBeforeUpdate )
1509
1509
{
@@ -1518,7 +1518,7 @@ public object[] GetCurrentPersistentState(object id, object version, ISessionImp
1518
1518
IType [ ] types = PropertyTypes ;
1519
1519
object [ ] values = new object [ types . Length ] ;
1520
1520
bool [ ] includeProperty = PropertyUpdateability ;
1521
- SqlString sql = ConcreteSelectString ;
1521
+ SqlString sql = SQLSnapshotSelectString ;
1522
1522
try
1523
1523
{
1524
1524
IDbCommand st = session . Batcher . PrepareCommand ( CommandType . Text , sql , idAndVersionSqlTypes ) ;
@@ -1639,6 +1639,11 @@ protected int GetPropertyColumnSpan(int i)
1639
1639
{
1640
1640
return propertyColumnSpans [ i ] ;
1641
1641
}
1642
+
1643
+ protected string [ ] GetPropertyColumnFormulaTemplates ( int i )
1644
+ {
1645
+ return propertyColumnFormulaTemplates [ i ] ;
1646
+ }
1642
1647
1643
1648
public string SelectFragment ( string alias , string suffix , bool includeCollectionColumns )
1644
1649
{
@@ -2229,6 +2234,11 @@ protected EntityMetamodel EntityMetamodel
2229
2234
get { return entityMetamodel ; }
2230
2235
}
2231
2236
2237
+ private string RootAlias
2238
+ {
2239
+ get { return StringHelper . GenerateAlias ( ClassName ) ; }
2240
+ }
2241
+
2232
2242
protected void PostConstruct ( IMapping mapping )
2233
2243
{
2234
2244
InitPropertyPaths ( mapping ) ;
@@ -2239,7 +2249,73 @@ protected void PostConstruct(IMapping mapping)
2239
2249
idSqlTypes = IdentifierType . SqlTypes ( mapping ) ;
2240
2250
}
2241
2251
2242
- protected abstract SqlString GenerateConcreteSelectString ( ) ;
2252
+ protected abstract int [ ] PropertyTableNumbersInSelect { get ; }
2253
+
2254
+ protected string ConcretePropertySelectFragment ( string alias , bool [ ] includeProperty )
2255
+ {
2256
+ int propertyCount = entityMetamodel . PropertySpan ;
2257
+ int [ ] propertyTableNumbers = PropertyTableNumbersInSelect ;
2258
+ SelectFragment frag = new SelectFragment ( Factory . Dialect ) ;
2259
+ for ( int i = 0 ; i < propertyCount ; i ++ )
2260
+ {
2261
+ if ( includeProperty [ i ] )
2262
+ {
2263
+ //ie. updateable, not a formula
2264
+ frag . AddColumns (
2265
+ GenerateTableAlias ( alias , propertyTableNumbers [ i ] ) ,
2266
+ propertyColumnNames [ i ] ,
2267
+ propertyColumnAliases [ i ]
2268
+ ) ;
2269
+ frag . AddFormulas (
2270
+ GenerateTableAlias ( alias , propertyTableNumbers [ i ] ) ,
2271
+ propertyColumnFormulaTemplates [ i ] ,
2272
+ propertyColumnAliases [ i ]
2273
+ ) ;
2274
+ }
2275
+ }
2276
+ return frag . ToSqlStringFragment ( ) ;
2277
+ }
2278
+
2279
+ protected virtual SqlString GenerateSnapshotSelectString ( )
2280
+ {
2281
+ //TODO: should we use SELECT .. FOR UPDATE?
2282
+
2283
+ SqlSelectBuilder select = new SqlSelectBuilder ( Factory ) ;
2284
+
2285
+ //if (Factory.Settings.IsCommentsEnabled)
2286
+ //{
2287
+ // select.SetComment("get current state " + ClassName);
2288
+ //}
2289
+
2290
+ string [ ] aliasedIdColumns = StringHelper . Qualify ( RootAlias , IdentifierColumnNames ) ;
2291
+ string selectClause = StringHelper . Join ( ", " , aliasedIdColumns ) +
2292
+ ConcretePropertySelectFragment ( RootAlias , PropertyUpdateability ) ;
2293
+
2294
+ SqlString fromClause = FromTableFragment ( RootAlias ) +
2295
+ FromJoinFragment ( RootAlias , true , false ) ;
2296
+
2297
+ SqlString joiner = new SqlString ( "=" , Parameter . Placeholder , " and " ) ;
2298
+ SqlString whereClause = new SqlStringBuilder ( )
2299
+ . Add ( StringHelper . Join ( joiner , aliasedIdColumns ) )
2300
+ . Add ( "=" )
2301
+ . AddParameter ( )
2302
+ . Add ( WhereJoinFragment ( RootAlias , true , false ) )
2303
+ . ToSqlString ( ) ;
2304
+
2305
+ // TODO H3: this is commented out in H3.2
2306
+ if ( IsVersioned )
2307
+ {
2308
+ whereClause . Append ( " and " )
2309
+ . Append ( VersionColumnName )
2310
+ . Append ( "=?" ) ;
2311
+ }
2312
+
2313
+ return select . SetSelectClause ( selectClause )
2314
+ . SetFromClause ( fromClause )
2315
+ . SetOuterJoins ( SqlString . Empty , SqlString . Empty )
2316
+ . SetWhereClause ( whereClause )
2317
+ . ToSqlString ( ) ;
2318
+ }
2243
2319
2244
2320
public virtual void PostInstantiate ( )
2245
2321
{
@@ -2269,7 +2345,7 @@ public virtual void PostInstantiate()
2269
2345
? GenerateIdentityInsertString ( PropertyInsertability )
2270
2346
: null ;
2271
2347
2272
- sqlConcreteSelectString = GenerateConcreteSelectString ( ) ;
2348
+ sqlSnapshotSelectString = GenerateSnapshotSelectString ( ) ;
2273
2349
sqlVersionSelectString = GenerateSelectVersionString ( ) ;
2274
2350
2275
2351
// This is used to determine updates for objects that came in via update()
@@ -2818,9 +2894,9 @@ protected SqlString VersionSelectString
2818
2894
get { return sqlVersionSelectString ; }
2819
2895
}
2820
2896
2821
- protected SqlString ConcreteSelectString
2897
+ protected SqlString SQLSnapshotSelectString
2822
2898
{
2823
- get { return sqlConcreteSelectString ; }
2899
+ get { return sqlSnapshotSelectString ; }
2824
2900
}
2825
2901
2826
2902
protected SqlCommandInfo GenerateDeleteString ( int j )
0 commit comments