use of org.springframework.dao.DataAccessException in project spring-data-mongodb by spring-projects.
the class AggregationTests method initSampleDataIfNecessary.
/**
* Imports the sample dataset (zips.json) if necessary (e.g. if it doesn't exist yet). The dataset can originally be
* found on the mongodb aggregation framework example website:
*
* @see <a href="https://docs.mongodb.org/manual/tutorial/aggregation-examples/">MongoDB Aggregation Examples</a>
*/
private void initSampleDataIfNecessary() {
if (!initialized) {
LOGGER.debug("Server uses MongoDB Version: {}", mongoVersion);
mongoTemplate.dropCollection(ZipInfo.class);
mongoTemplate.execute(ZipInfo.class, new CollectionCallback<Void>() {
@Override
public Void doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException {
Scanner scanner = null;
try {
scanner = new Scanner(new BufferedInputStream(new ClassPathResource("zips.json").getInputStream()));
while (scanner.hasNextLine()) {
String zipInfoRecord = scanner.nextLine();
collection.insertOne(Document.parse(zipInfoRecord));
}
} catch (Exception e) {
if (scanner != null) {
scanner.close();
}
throw new RuntimeException("Could not load mongodb sample dataset!", e);
}
return null;
}
});
long count = mongoTemplate.count(new Query(), ZipInfo.class);
assertThat(count, is(29467L));
initialized = true;
}
}
use of org.springframework.dao.DataAccessException in project spring-data-mongodb by spring-projects.
the class GeoJsonTests method shouldConvertLineStringRepresentationCorrectlyWhenSourceCoordinatesUsesInteger.
// DATAMONGO-1453
@Test
public void shouldConvertLineStringRepresentationCorrectlyWhenSourceCoordinatesUsesInteger() {
this.template.execute(template.getCollectionName(DocumentWithPropertyUsingGeoJsonType.class), new CollectionCallback<Object>() {
@Override
public Object doInCollection(MongoCollection<org.bson.Document> collection) throws MongoException, DataAccessException {
org.bson.Document lineStringRepresentation = new org.bson.Document();
lineStringRepresentation.put("type", "LineString");
lineStringRepresentation.put("coordinates", new BasicDbListBuilder().add(new BasicDbListBuilder().add(0).add(0).get()).add(new BasicDbListBuilder().add(1).add(1).get()).get());
org.bson.Document document = new org.bson.Document();
document.append("_id", "datamongo-1453");
document.append("geoJsonLineString", lineStringRepresentation);
collection.insertOne(document);
return document;
}
});
assertThat(template.findOne(query(where("id").is("datamongo-1453")), DocumentWithPropertyUsingGeoJsonType.class).geoJsonLineString, is(equalTo(new GeoJsonLineString(new Point(0D, 0D), new Point(1, 1)))));
}
use of org.springframework.dao.DataAccessException in project metacat by Netflix.
the class DirectSqlTable method delete.
/**
* Deletes all the table related information from the store.
* @param tableName table name
*/
public void delete(final QualifiedName tableName) {
try {
final TableSequenceIds ids = getSequenceIds(tableName);
directSqlSavePartition.delete(tableName);
jdbcTemplate.update(SQL.UPDATE_SDS_CD, new SqlParameterValue(Types.BIGINT, null), new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
jdbcTemplate.update(SQL.UPDATE_SDS_SERDE, new SqlParameterValue(Types.BIGINT, null), new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
//
try {
jdbcTemplate.update(SQL.DELETE_COLUMNS_OLD, new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
} catch (DataAccessException ignored) {
log.debug("Ignore. Probably table COLUMNS_OLD does not exist.");
}
try {
jdbcTemplate.update(SQL.DELETE_TBL_PRIVS, new SqlParameterValue(Types.BIGINT, ids.getTableId()));
} catch (DataAccessException ignored) {
log.debug("Ignore. Probably table TBL_PRIVS does not exist.");
}
try {
jdbcTemplate.update(SQL.DELETE_TBL_COL_PRIVS, new SqlParameterValue(Types.BIGINT, ids.getTableId()));
} catch (DataAccessException ignored) {
log.debug("Ignore. Probably table TBL_COL_PRIVS does not exist.");
}
jdbcTemplate.update(SQL.DELETE_COLUMNS_V2, new SqlParameterValue(Types.BIGINT, ids.getCdId()));
jdbcTemplate.update(SQL.DELETE_CDS, new SqlParameterValue(Types.BIGINT, ids.getCdId()));
jdbcTemplate.update(SQL.DELETE_PARTITION_KEYS, new SqlParameterValue(Types.BIGINT, ids.getTableId()));
jdbcTemplate.update(SQL.DELETE_TABLE_PARAMS, new SqlParameterValue(Types.BIGINT, ids.getTableId()));
jdbcTemplate.update(SQL.DELETE_TAB_COL_STATS, new SqlParameterValue(Types.BIGINT, ids.getTableId()));
jdbcTemplate.update(SQL.UPDATE_TABLE_SD, new SqlParameterValue(Types.BIGINT, null), new SqlParameterValue(Types.BIGINT, ids.getTableId()));
jdbcTemplate.update(SQL.DELETE_SKEWED_COL_NAMES, new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
jdbcTemplate.update(SQL.DELETE_BUCKETING_COLS, new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
jdbcTemplate.update(SQL.DELETE_SORT_COLS, new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
jdbcTemplate.update(SQL.DELETE_SD_PARAMS, new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
jdbcTemplate.update(SQL.DELETE_SKEWED_COL_VALUE_LOC_MAP, new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
jdbcTemplate.update(SQL.DELETE_SKEWED_VALUES, new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
jdbcTemplate.update(SQL.DELETE_SERDE_PARAMS, new SqlParameterValue(Types.BIGINT, ids.getSerdeId()));
jdbcTemplate.update(SQL.DELETE_SERDES, new SqlParameterValue(Types.BIGINT, ids.getSerdeId()));
jdbcTemplate.update(SQL.DELETE_SDS, new SqlParameterValue(Types.BIGINT, ids.getSdsId()));
jdbcTemplate.update(SQL.DELETE_TBLS, new SqlParameterValue(Types.BIGINT, ids.getTableId()));
} catch (DataAccessException e) {
throw new ConnectorException(String.format("Failed delete hive table %s", tableName), e);
}
}
use of org.springframework.dao.DataAccessException in project metacat by Netflix.
the class SequenceGeneration method newPartitionSequenceIdByName.
/**
* Returns the current sequence ids and increments the sequence ids by the given <code>size</code>.
*
* @param size number of records getting inserted
* @param sequenceParamName the sequence Parameter Name
* @return current sequence ids
*/
@Transactional(propagation = Propagation.REQUIRES_NEW)
public Long newPartitionSequenceIdByName(final int size, final String sequenceParamName) {
Long result = null;
try {
// Get current sequence number
result = jdbcTemplate.queryForObject(SQL.SEQUENCE_NEXT_VAL_BYNAME, new Object[] { sequenceParamName }, Long.class);
} catch (DataAccessException e) {
log.warn("Failed getting the sequence ids for partition", e);
} catch (Exception e) {
throw new IllegalStateException("Failed retrieving the sequence numbers.");
}
try {
if (result == null) {
// init to 1L in case there's no records
result = 1L;
jdbcTemplate.update(SQL.SEQUENCE_INSERT_VAL, result + size, sequenceParamName);
} else {
jdbcTemplate.update(SQL.SEQUENCE_UPDATE_VAL, result + size, sequenceParamName);
}
return result;
} catch (Exception e) {
throw new ConnectorException("Failed updating the sequence ids for partition", e);
}
}
Aggregations