Details
diff --git a/util/src/main/java/com/ning/billing/util/customfield/api/DefaultCustomFieldUserApi.java b/util/src/main/java/com/ning/billing/util/customfield/api/DefaultCustomFieldUserApi.java
index 3fa6bd1..ba20f36 100644
--- a/util/src/main/java/com/ning/billing/util/customfield/api/DefaultCustomFieldUserApi.java
+++ b/util/src/main/java/com/ning/billing/util/customfield/api/DefaultCustomFieldUserApi.java
@@ -50,9 +50,10 @@ public class DefaultCustomFieldUserApi implements CustomFieldUserApi {
@Override
public void addCustomFields(final List<CustomField> fields, final CallContext context) throws CustomFieldApiException {
+
// TODO make it transactional
for (CustomField cur : fields) {
- customFieldDao.create(cur, internalCallContextFactory.createInternalCallContext(context));
+ customFieldDao.create(cur, internalCallContextFactory.createInternalCallContext(cur.getObjectId(), cur.getObjectType(), context));
}
}
}
diff --git a/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.java b/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.java
index bd367d6..c14b131 100644
--- a/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.java
@@ -23,6 +23,7 @@ import java.util.UUID;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlBatch;
+import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
import org.skife.jdbi.v2.sqlobject.mixins.Transactional;
import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
@@ -42,5 +43,6 @@ import com.ning.billing.util.entity.dao.EntitySqlDaoStringTemplate;
@RegisterMapper(CustomFieldMapper.class)
public interface CustomFieldSqlDao extends EntitySqlDao<CustomField> {
+ @SqlQuery
List<CustomField> getCustomFieldsForObject(@Bind("objectId") UUID objectId, @Bind("objectType") ObjectType objectType, @BindBean InternalTenantContext internalTenantContext);
}
diff --git a/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
index d73eaf4..2f8b857 100644
--- a/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
@@ -26,41 +26,15 @@ tableValues() ::= <<
historyTableName() ::= "custom_field_history"
-updateFromTransaction() ::= <<
- UPDATE custom_fields
- SET field_value = :fieldValue, updated_by = :userName, updated_date = :updatedDate
- WHERE object_id = :objectId AND object_type = :objectType AND field_name = :fieldName
- <AND_CHECK_TENANT()>
- ;
->>
-
-deleteFromTransaction() ::= <<
- DELETE FROM custom_fields
- WHERE object_id = :objectId AND object_type = :objectType AND field_name = :fieldName
- <AND_CHECK_TENANT()>
- ;
->>
-load() ::= <<
- SELECT id, object_id, object_type, field_name, field_value, created_by, created_date, updated_by, updated_date
- FROM custom_fields
- WHERE object_id = :objectId AND object_type = :objectType
- <AND_CHECK_TENANT()>
- ;
+getCustomFieldsForObject() ::= <<
+select
+<allTableFields()>
+from <tableName()>
+where
+object_id = :objectId
+and object_type = :objectType
+<AND_CHECK_TENANT()>
+;
>>
-getRecordIds() ::= <<
- SELECT record_id, id
- FROM custom_fields
- WHERE object_id = :objectId AND object_type = :objectType
- <AND_CHECK_TENANT()>
- ;
->>
-
-getHistoryRecordIds() ::= <<
- SELECT history_record_id, record_id
- FROM custom_field_history
- WHERE history_record_id > :maxHistoryRecordId
- <AND_CHECK_TENANT()>
- ;
->>
diff --git a/util/src/test/java/com/ning/billing/KillbillTestSuite.java b/util/src/test/java/com/ning/billing/KillbillTestSuite.java
index f5d9882..b0d009d 100644
--- a/util/src/test/java/com/ning/billing/KillbillTestSuite.java
+++ b/util/src/test/java/com/ning/billing/KillbillTestSuite.java
@@ -32,6 +32,8 @@ import com.ning.billing.util.callcontext.CallOrigin;
import com.ning.billing.util.callcontext.InternalCallContext;
import com.ning.billing.util.callcontext.InternalCallContextFactory;
import com.ning.billing.util.callcontext.UserType;
+import com.ning.billing.util.clock.Clock;
+import com.ning.billing.util.clock.ClockMock;
public class KillbillTestSuite {
@@ -40,10 +42,12 @@ public class KillbillTestSuite {
private boolean hasFailed = false;
+ private Clock clock = new ClockMock();
+
protected final InternalCallContext internalCallContext = new InternalCallContext(InternalCallContextFactory.INTERNAL_TENANT_RECORD_ID, 1687L, UUID.randomUUID(),
UUID.randomUUID().toString(), CallOrigin.TEST,
UserType.TEST, "Testing", "This is a test",
- new DateTime(DateTimeZone.UTC), new DateTime(DateTimeZone.UTC));
+ clock.getUTCNow(), clock.getUTCNow());
protected final CallContext callContext = internalCallContext.toCallContext();
@BeforeMethod(alwaysRun = true)
diff --git a/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java b/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java
index 78522e4..c72c883 100644
--- a/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java
+++ b/util/src/test/java/com/ning/billing/util/customfield/TestFieldStore.java
@@ -61,12 +61,13 @@ public class TestFieldStore extends UtilTestSuiteWithEmbeddedDB {
final ObjectType objectType = ObjectType.ACCOUNT;
- final String fieldName = "TestField1";
+ String fieldName = "TestField1";
String fieldValue = "Kitty Hawk";
CustomField field = new StringCustomField(fieldName, fieldValue, objectType, id, internalCallContext.getCreatedDate());
customFieldDao.create(field, internalCallContext);
+ fieldName = "TestField2";
fieldValue = "Cape Canaveral";
CustomField field2 = new StringCustomField(fieldName, fieldValue, objectType, id, internalCallContext.getCreatedDate());
customFieldDao.create(field2 ,internalCallContext);
diff --git a/util/src/test/java/com/ning/billing/util/tag/dao/TestAuditedTagDao.java b/util/src/test/java/com/ning/billing/util/tag/dao/TestAuditedTagDao.java
index 4556034..9f58e12 100644
--- a/util/src/test/java/com/ning/billing/util/tag/dao/TestAuditedTagDao.java
+++ b/util/src/test/java/com/ning/billing/util/tag/dao/TestAuditedTagDao.java
@@ -167,8 +167,8 @@ public class TestAuditedTagDao extends UtilTestSuiteWithEmbeddedDB {
Assert.assertEquals(createdTagDefinition.getDescription(), description);
// Make sure we can create a tag
- final Tag tag = createdTagDefinition.isControlTag() ? new DefaultControlTag(ControlTagType.getTypeFromId(createdTagDefinition.getId()), ObjectType.ACCOUNT, objectId, internalCallContext.getCreatedDate()) :
- new DescriptiveTag(createdTagDefinition.getId(), ObjectType.ACCOUNT, objectId, internalCallContext.getCreatedDate());
+ final Tag tag = createdTagDefinition.isControlTag() ? new DefaultControlTag(ControlTagType.getTypeFromId(createdTagDefinition.getId()), objectType, objectId, internalCallContext.getCreatedDate()) :
+ new DescriptiveTag(createdTagDefinition.getId(), objectType, objectId, internalCallContext.getCreatedDate());
tagDao.create(tag, internalCallContext);
// Make sure we can retrieve it via the DAO
diff --git a/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java b/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
index 2e3c386..55891c6 100644
--- a/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
+++ b/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
@@ -25,6 +25,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@@ -77,14 +78,25 @@ public class TestTagStore extends UtilTestSuiteWithEmbeddedDB {
try {
bus.start();
- tagDefinitionDao.create("tag1", "First tag", internalCallContext);
- testTagDefinition = tagDefinitionDao.create("testTagDefinition", "Second tag", internalCallContext);
} catch (Throwable t) {
log.error("Failed to start tag store tests", t);
fail(t.toString());
}
}
+ // We need tag definitions before we start the tests
+ @Override
+ @BeforeMethod(groups = "slow")
+ public void cleanupTablesBetweenMethods() {
+ super.cleanupTablesBetweenMethods();
+ try {
+ tagDefinitionDao.create("tag1", "First tag", internalCallContext);
+ testTagDefinition = tagDefinitionDao.create("testTagDefinition", "Second tag", internalCallContext);
+ } catch (TagDefinitionApiException e) {
+ fail(e.toString());
+ }
+ }
+
@AfterClass(groups = "slow")
public void tearDown() {
bus.stop();