This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityTransaction tx = entityManager.getTransaction(); | |
Iterator<TripEntity> iterator = trips.iterator(); | |
while (iterator.hasNext()) { | |
tx.begin(); | |
entityManager.persist(iterator.next()); | |
tx.commit(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityTransaction tx = entityManager.getTransaction(); | |
Iterator<TripEntity> iterator = trips.iterator(); | |
tx.begin(); | |
int cont = 0; | |
while (iterator.hasNext()) { | |
entityManager.persist(iterator.next()); | |
cont++; | |
if (cont % batchSize == 0) { | |
tx.commit(); | |
tx.begin(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityTransaction tx = entityManager.getTransaction(); | |
Iterator<TripEntity> iterator = trips.iterator(); | |
tx.begin(); | |
int cont = 0; | |
while (iterator.hasNext()) { | |
entityManager.persist(iterator.next()); | |
cont++; | |
if (cont % batchSize == 0) { | |
entityManager.flush(); | |
entityManager.clear(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
@Table(name = "bike_trip") | |
public class TripEntity implements Trip { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private Integer id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityManagerFactoryFactory factory = new EntityManagerFactoryFactory(dsFactory, TripEntity.class) { | |
@Override | |
public Properties properties() { | |
Properties properties = super.properties(); | |
properties.put("hibernate.jdbc.batch_size", batchSize); | |
return properties; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityTransaction tx = entityManager.getTransaction(); | |
Iterator<TripEntityJpa> iterator = trips.iterator(); | |
tx.begin(); | |
int cont = 0; | |
int idSeq = 1; | |
while (iterator.hasNext()) { | |
TripEntityJpa trip = iterator.next(); | |
trip.setId(idSeq++); | |
entityManager.persist(trip); | |
cont++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connection.setAutoCommit(true); | |
try (PreparedStatement pstmt = connection.prepareStatement(TripEntityInsert.INSERT)) { | |
Iterator<TripEntity> iterator = trips.iterator(); | |
while (iterator.hasNext()) { | |
tripInsert.setParameters(pstmt, iterator.next()); | |
pstmt.executeUpdate(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connection.setAutoCommit(false); | |
try (PreparedStatement pstmt = connection.prepareStatement(TripEntityInsert.INSERT)) { | |
int cont = 0; | |
Iterator<TripEntity> iterator = trips.iterator(); | |
while (iterator.hasNext()) { | |
tripInsert.setParameters(pstmt, iterator.next()); | |
pstmt.executeUpdate(); | |
cont++; | |
if (cont % batchSize == 0) { | |
connection.commit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connection.setAutoCommit(false); | |
try (PreparedStatement pstmt = connection.prepareStatement(TripEntityInsert.INSERT)) { | |
int cont = 0; | |
Iterator<TripEntity> iterator = trips.iterator(); | |
while (iterator.hasNext()) { | |
TripEntity entity = iterator.next(); | |
tripInsert.setParameters(pstmt, entity); | |
pstmt.addBatch(); | |
cont++; | |
if (cont % batchSize == 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 2016-01-01 00:00:00 2016-01-01 00:16:00 268 Howard St & Centre St 40.71910537 -73.99973337 3002 South End Ave & Liberty St 40.711512 -74.015756 22285 Subscriber 1958 1 | |
379 2016-01-01 00:00:00 2016-01-01 00:07:00 476 E 31 St & 3 Ave 40.74394314 -73.97966069 498 Broadway & W 32 St 40.74854862 -73.98808416 17827 Subscriber 1969 1 | |
589 2016-01-01 00:00:00 2016-01-01 00:10:00 489 10 Ave & W 28 St 40.75066386 -74.00176802 284 Greenwich Ave & 8 Ave 40.7390169121 -74.0026376103 21997 Subscriber 1982 2 | |
889 2016-01-01 00:01:00 2016-01-01 00:15:00 268 Howard St & Centre St 40.71910537 -73.99973337 3002 South End Ave & Liberty St 40.711512 -74.015756 22794 Subscriber 1961 2 | |
1480 2016-01-01 00:01:00 2016-01-01 00:25:00 2006 Central Park S & 6 Ave 40.76590936 -73.97634151 2006 Central Park S & 6 Ave 40.76590936 -73.97634151 14562 Subscriber \N 1 |
OlderNewer