DATACASS-174 - Polishing.

Guard getTableName if PersistentEntity is null. Add author tags. Update date in license headers. Remove unused code.

Original pull request: #28.
This commit is contained in:
Mark Paluch
2016-04-28 14:12:30 +02:00
parent 58d6eb2b26
commit 71a1ba5255
3 changed files with 40 additions and 26 deletions

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2013-2014 the original author or authors
*
* Copyright 2013-2016 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -35,6 +35,8 @@ import com.datastax.driver.core.TableMetadata;
/**
* Default implementation of {@link CassandraAdminOperations}.
*
* @author Mark Paluch
*/
public class CassandraAdminTemplate extends CassandraTemplate implements CassandraAdminOperations {
@@ -42,7 +44,7 @@ public class CassandraAdminTemplate extends CassandraTemplate implements Cassand
/**
* Constructor used for a basic template configuration
*
*
* @param session must not be {@literal null}.
* @param converter must not be {@literal null}.
*/
@@ -85,7 +87,7 @@ public class CassandraAdminTemplate extends CassandraTemplate implements Cassand
/**
* Create a list of query operations to alter the table for the given entity
*
*
* @param entityClass
* @param tableName
*/

View File

@@ -1,12 +1,12 @@
/*
* Copyright 2013-2014 the original author or authors
*
* Copyright 2013-2016 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,6 +33,7 @@ import org.springframework.cassandra.core.cql.CqlIdentifier;
import org.springframework.cassandra.core.util.CollectionUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.cassandra.convert.CassandraConverter;
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
@@ -60,11 +61,12 @@ import com.datastax.driver.core.querybuilder.Update;
/**
* The CassandraTemplate is a convenient API for all Cassandra operations using POJOs with their Spring Data Cassandra
* mapping information. For low-level Cassandra operation, see {@link CqlTemplate}.
*
*
* @author Alex Shvid
* @author David Webb
* @author Matthew T. Adams
* @author Oliver Gierke
* @author Mark Paluch
* @see CqlTemplate
*/
public class CassandraTemplate extends CqlTemplate implements CassandraOperations {
@@ -83,7 +85,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Constructor if only session and converter are known at time of Template Creation
*
*
* @param session must not be {@literal null}
* @param converter must not be {@literal null}.
*/
@@ -213,8 +215,19 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
}
@Override
public CqlIdentifier getTableName(Class<?> type) {
return mappingContext.getPersistentEntity(type).getTableName();
public CqlIdentifier getTableName(Class<?> entityClass) {
if (entityClass == null) {
throw new InvalidDataAccessApiUsageException(
"No class parameter provided, entity table can't be determined!");
}
CassandraPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
if (entity == null) {
throw new InvalidDataAccessApiUsageException(
"No Persistent Entity information found for the class " + entityClass.getName());
}
return entity.getTableName();
}
@Override
@@ -689,7 +702,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Asynchronously performs a batch insert or update.
*
*
* @param entities The entities to insert or update.
* @param listener The listener that will receive notification of the completion of the batch insert or update. May be
* <code>null</code>.
@@ -703,7 +716,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Asynchronously performs a batch insert or update.
*
*
* @param entities The entities to insert or update.
* @param listener The listener that will receive notification of the completion of the batch insert or update. May be
* <code>null</code>.
@@ -717,7 +730,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Asynchronously performs a batch insert or update.
*
*
* @param entities The entities to insert or update.
* @param listener The listener that will receive notification of the completion of the batch insert or update. May be
* <code>null</code>.
@@ -824,7 +837,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Generates a Query Object for an insert
*
*
* @param tableName
* @param objectToSave
* @param entity
@@ -852,7 +865,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Generates a Query Object for an Update
*
*
* @param tableName
* @param objectToSave
* @param entity
@@ -880,7 +893,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Generates a Batch Object for multiple Updates
*
*
* @param tableName
* @param objectsToSave
* @param entity
@@ -903,7 +916,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Generates a Batch Object for multiple inserts
*
*
* @param tableName
* @param entities
* @param entity
@@ -926,7 +939,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Create a Delete Query Object from an annotated POJO
*
*
* @param tableName
* @param object
* @param entity
@@ -946,7 +959,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation
/**
* Create a Batch Query object for multiple deletes.
*
*
* @param tableName
* @param entities
* @param entity

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors
* Copyright 2013-2016 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ import com.datastax.driver.core.TableMetadata;
/**
* Test for CassandraAdminTemplate
*
*
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@@ -59,7 +59,6 @@ public class CassandraAdminTemplateTest extends AbstractSpringDataEmbeddedCassan
}
@Autowired private CassandraAdminTemplate cassandraAdminTemplate;
@Autowired private CassandraConverter converter;
@Before
public void before() {