Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import org.apache.cayenne.map.ObjAttribute;
import org.apache.cayenne.map.ObjEntity;
import org.apache.cayenne.query.SelectQuery;
import org.apache.cayenne.test.jdbc.DBHelper;
import org.junit.Test;

import java.sql.Connection;
import java.sql.Types;
import java.util.List;

Expand All @@ -49,6 +51,8 @@ public class ValueForNullIT extends MergeCase {

@Inject
private DataContext context;
@Inject
DBHelper dbHelper;

@Test
public void test() throws Exception {
Expand All @@ -59,6 +63,7 @@ public void test() throws Exception {

// insert some rows before adding "not null" column
final int nrows = 10;

for (int i = 0; i < nrows; i++) {
DataObject o = (DataObject) context.newObject("Painting");
o.writeProperty("paintingTitle", "ptitle" + i);
Expand Down Expand Up @@ -92,6 +97,11 @@ public void test() throws Exception {
// check that is was merged
assertTokensAndExecute(0, 0);

//used to REORG TABLE only for db2
try(Connection con = dbHelper.getConnection()) {
accessStackAdapter.cleanDB(con, dbEntity.getFullyQualifiedName());
}

// check values for null
Expression qual = ExpressionFactory.matchExp(objAttr.getName(), DEFAULT_VALUE_STRING);
SelectQuery query = new SelectQuery("Painting", qual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,30 @@

package org.apache.cayenne.dbsync.merge.token.db;

import java.sql.Connection;
import java.sql.Types;

import org.apache.cayenne.dbsync.merge.MergeCase;
import org.apache.cayenne.di.Inject;
import org.apache.cayenne.map.DbAttribute;
import org.apache.cayenne.map.DbEntity;
import org.apache.cayenne.test.jdbc.DBHelper;
import org.junit.Test;

public class SetPrimaryKeyToDbIT extends MergeCase {

@Inject
DBHelper dbHelper;
@Test
public void test() throws Exception {

dropTableIfPresent("NEW_TABLE");
assertTokensAndExecute(0, 0);

DbEntity dbEntity1 = new DbEntity("NEW_TABLE");

DbAttribute e1col1 = new DbAttribute("ID1", Types.INTEGER, dbEntity1);
e1col1.setMandatory(true);

e1col1.setPrimaryKey(true);
dbEntity1.addAttribute(e1col1);
map.addDbEntity(dbEntity1);
Expand All @@ -51,6 +57,11 @@ public void test() throws Exception {
assertTokensAndExecute(2, 0);
assertTokensAndExecute(0, 0);

//used to REORG TABLE only for db2
try(Connection con = dbHelper.getConnection()) {
accessStackAdapter.cleanDB(con, dbEntity1.getFullyQualifiedName());
}

e1col1.setPrimaryKey(false);
e1col2.setPrimaryKey(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@ public boolean supportsExpressionInHaving() {
public boolean supportsSelectBooleanExpression() {
return false;
}

@Override
public void cleanDB(Connection conn, String tableName) throws Exception {
StringBuffer sql = new StringBuffer();
sql.append("Call Sysproc.admin_cmd ('reorg Table ").append(tableName).append(" ')");
executeDDL(conn,sql.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.cayenne.configuration.RuntimeProperties;
import org.apache.cayenne.dba.DbAdapter;
import org.apache.cayenne.dba.QuotingStrategy;
import org.apache.cayenne.dba.db2.DB2Adapter;
import org.apache.cayenne.di.Inject;
import org.apache.cayenne.exp.parser.ASTExtract;
import org.apache.cayenne.map.DataMap;
Expand Down Expand Up @@ -403,4 +404,6 @@ public boolean supportsSelectBooleanExpression() {
public boolean supportsExtractPart(ASTExtract.DateTimePart part) {
return true;
}

public void cleanDB(Connection conn, String tableName) throws Exception {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.cayenne.unit.UnitDbAdapter;

import java.net.URL;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

Expand All @@ -52,7 +53,7 @@ public DBCleaner(FlavoredDBHelper dbHelper, String location) {
this.location = location;
}

public void clean() throws SQLException {
public void clean() throws Exception {
XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
injector.injectMembers(loader);

Expand All @@ -63,6 +64,9 @@ public void clean() throws SQLException {
List<DbEntity> entities = schemaBuilder.dbEntitiesInDeleteOrder(map);

for (DbEntity entity : entities) {
try(Connection con = dbHelper.getConnection()) {
accessStackAdapter.cleanDB(con, entity.getName());
}
dbHelper.deleteAll(entity.getName());
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/doc/src/main/resources/RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CAY-2346 Field-based data object with Map-based storage fallback
CAY-2351 Remove commons-collections usage completely

Bug Fixes:

CAY-2200 Update DB2 support. Many tests cases are failing now.
CAY-2312 Modeler: Undo does not work for checkboxes
CAY-2318 Modeler: Query. Exception after Undo clicking
CAY-2319 Modeler: Embeddable > Attributes. Undo does not cancel pasted objects
Expand Down