Commit 1f211ca 1 parent de0b060 commit 1f211ca Copy full SHA for 1f211ca
File tree 1 file changed +15
-1
lines changed
gemma-core/src/main/java/ubic/gemma/persistence/service
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,13 @@ public abstract class AbstractDao<T extends Identifiable> extends HibernateDaoSu
43
43
44
44
protected static final Log log = LogFactory .getLog ( TaxonServiceImpl .class );
45
45
46
+ /**
47
+ * Batch size to reach before flushing the Hibernate session.
48
+ *
49
+ * See https://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/batch.html for more details.
50
+ */
51
+ private static final int BATCH_SIZE = 100 ;
52
+
46
53
protected final Class <T > elementClass ;
47
54
48
55
protected AbstractDao ( Class <T > elementClass , SessionFactory sessionFactory ) {
@@ -55,8 +62,10 @@ public Collection<T> create( Collection<T> entities ) {
55
62
int i = 0 ;
56
63
for ( T t : entities ) {
57
64
this .create ( t );
58
- if ( ++i % 100 == 0 )
65
+ if ( ++i % BATCH_SIZE == 0 ) {
59
66
this .getSessionFactory ().getCurrentSession ().flush ();
67
+ this .getSessionFactory ().getCurrentSession ().clear ();
68
+ }
60
69
}
61
70
return entities ;
62
71
}
@@ -125,8 +134,13 @@ public void remove( T entity ) {
125
134
@ Override
126
135
@ Transactional
127
136
public void update ( Collection <T > entities ) {
137
+ int i = 0 ;
128
138
for ( T entity : entities ) {
129
139
this .update ( entity );
140
+ if ( ++i % BATCH_SIZE == 0 ) {
141
+ this .getSessionFactory ().getCurrentSession ().flush ();
142
+ this .getSessionFactory ().getCurrentSession ().clear ();
143
+ }
130
144
}
131
145
}
132
146
You can’t perform that action at this time.
0 commit comments