mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ALF-11670: Add autoincrement boolean property to columns
Columns now have a property to describe whether it has been defined as an auto-increment column, e.g. AUTO_INCREMENT for MySQL. The property is persisted in XML reference files, loaded from XML reference files and compared between schemas. The MySQL reference file has been updated to include autoincrement values. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32711 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -216,6 +216,7 @@ public class DbObjectXMLTransformer
|
|||||||
{
|
{
|
||||||
simpleElement(XML.EL_TYPE, column.getType());
|
simpleElement(XML.EL_TYPE, column.getType());
|
||||||
simpleElement(XML.EL_NULLABLE, Boolean.toString(column.isNullable()));
|
simpleElement(XML.EL_NULLABLE, Boolean.toString(column.isNullable()));
|
||||||
|
simpleElement(XML.EL_AUTOINCREMENT, Boolean.toString(column.isAutoIncrement()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void transformForeignKey(ForeignKey fk) throws SAXException
|
private void transformForeignKey(ForeignKey fk) throws SAXException
|
||||||
|
@@ -105,6 +105,7 @@ public class DbObjectXMLTransformerTest
|
|||||||
public void transformColumn() throws IOException
|
public void transformColumn() throws IOException
|
||||||
{
|
{
|
||||||
Column column = new Column(null, "last_name", "VARCHAR2(100)", true);
|
Column column = new Column(null, "last_name", "VARCHAR2(100)", true);
|
||||||
|
column.setAutoIncrement(true);
|
||||||
column.setOrder(2);
|
column.setOrder(2);
|
||||||
transformer.output(column);
|
transformer.output(column);
|
||||||
|
|
||||||
@@ -114,6 +115,7 @@ public class DbObjectXMLTransformerTest
|
|||||||
assertEquals("<column name=\"last_name\" order=\"2\">", reader.readLine());
|
assertEquals("<column name=\"last_name\" order=\"2\">", reader.readLine());
|
||||||
assertEquals(" <type>VARCHAR2(100)</type>", reader.readLine());
|
assertEquals(" <type>VARCHAR2(100)</type>", reader.readLine());
|
||||||
assertEquals(" <nullable>true</nullable>", reader.readLine());
|
assertEquals(" <nullable>true</nullable>", reader.readLine());
|
||||||
|
assertEquals(" <autoincrement>true</autoincrement>", reader.readLine());
|
||||||
assertEquals("</column>", reader.readLine());
|
assertEquals("</column>", reader.readLine());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -233,6 +233,9 @@ public class ExportDb
|
|||||||
|
|
||||||
column.setOrder(columns.getInt("ORDINAL_POSITION"));
|
column.setOrder(columns.getInt("ORDINAL_POSITION"));
|
||||||
|
|
||||||
|
String autoIncString = columns.getString("IS_AUTOINCREMENT");
|
||||||
|
column.setAutoIncrement(parseBoolean(autoIncString));
|
||||||
|
|
||||||
column.setParent(table);
|
column.setParent(table);
|
||||||
table.getColumns().add(column);
|
table.getColumns().add(column);
|
||||||
}
|
}
|
||||||
|
@@ -44,6 +44,7 @@ import org.springframework.transaction.PlatformTransactionManager;
|
|||||||
* it will run MySQL specific tests. If there is no test available for the configured DBMS then
|
* it will run MySQL specific tests. If there is no test available for the configured DBMS then
|
||||||
* the test will pass - this allows addition of new DBMS-specific tests when available.
|
* the test will pass - this allows addition of new DBMS-specific tests when available.
|
||||||
*
|
*
|
||||||
|
* @see AbstractExportTester
|
||||||
* @author Matt Ward
|
* @author Matt Ward
|
||||||
*/
|
*/
|
||||||
public class ExportDbTest
|
public class ExportDbTest
|
||||||
|
@@ -39,6 +39,7 @@ public abstract class XML
|
|||||||
public static final String EL_SEQUENCE = Sequence.class.getSimpleName().toLowerCase();
|
public static final String EL_SEQUENCE = Sequence.class.getSimpleName().toLowerCase();
|
||||||
public static final String EL_TYPE = "type";
|
public static final String EL_TYPE = "type";
|
||||||
public static final String EL_NULLABLE = "nullable";
|
public static final String EL_NULLABLE = "nullable";
|
||||||
|
public static final String EL_AUTOINCREMENT = "autoincrement";
|
||||||
public static final String EL_COLUMN_NAME = "columnname";
|
public static final String EL_COLUMN_NAME = "columnname";
|
||||||
public static final String EL_COLUMN_NAMES = "columnnames";
|
public static final String EL_COLUMN_NAMES = "columnnames";
|
||||||
public static final String EL_LOCAL_COLUMN = "localcolumn";
|
public static final String EL_LOCAL_COLUMN = "localcolumn";
|
||||||
|
@@ -153,6 +153,11 @@ public class XMLToSchema extends DefaultHandler
|
|||||||
Column column = (Column) stack.peek();
|
Column column = (Column) stack.peek();
|
||||||
column.setNullable(Boolean.parseBoolean(lastText.toString()));
|
column.setNullable(Boolean.parseBoolean(lastText.toString()));
|
||||||
}
|
}
|
||||||
|
else if (qName.equals(XML.EL_AUTOINCREMENT))
|
||||||
|
{
|
||||||
|
Column column = (Column) stack.peek();
|
||||||
|
column.setAutoIncrement(Boolean.parseBoolean(lastText.toString()));
|
||||||
|
}
|
||||||
else if (qName.equals(XML.EL_COLUMN_NAME))
|
else if (qName.equals(XML.EL_COLUMN_NAME))
|
||||||
{
|
{
|
||||||
if (stack.peek() instanceof PrimaryKey)
|
if (stack.peek() instanceof PrimaryKey)
|
||||||
|
@@ -81,18 +81,21 @@ public class XMLToSchemaTest
|
|||||||
assertEquals("NUMBER(10)", table.getColumns().get(0).getType());
|
assertEquals("NUMBER(10)", table.getColumns().get(0).getType());
|
||||||
assertEquals(false, table.getColumns().get(0).isNullable());
|
assertEquals(false, table.getColumns().get(0).isNullable());
|
||||||
assertEquals(1, table.getColumns().get(0).getOrder());
|
assertEquals(1, table.getColumns().get(0).getOrder());
|
||||||
|
assertEquals(true, table.getColumns().get(0).isAutoIncrement());
|
||||||
|
|
||||||
assertSame("Wrong or no parent set", table, table.getColumns().get(1).getParent());
|
assertSame("Wrong or no parent set", table, table.getColumns().get(1).getParent());
|
||||||
assertEquals("nodeRef", table.getColumns().get(1).getName());
|
assertEquals("nodeRef", table.getColumns().get(1).getName());
|
||||||
assertEquals("VARCHAR2(200)", table.getColumns().get(1).getType());
|
assertEquals("VARCHAR2(200)", table.getColumns().get(1).getType());
|
||||||
assertEquals(false, table.getColumns().get(1).isNullable());
|
assertEquals(false, table.getColumns().get(1).isNullable());
|
||||||
assertEquals(3, table.getColumns().get(1).getOrder());
|
assertEquals(3, table.getColumns().get(1).getOrder());
|
||||||
|
assertEquals(false, table.getColumns().get(1).isAutoIncrement());
|
||||||
|
|
||||||
assertSame("Wrong or no parent set", table, table.getColumns().get(2).getParent());
|
assertSame("Wrong or no parent set", table, table.getColumns().get(2).getParent());
|
||||||
assertEquals("name", table.getColumns().get(2).getName());
|
assertEquals("name", table.getColumns().get(2).getName());
|
||||||
assertEquals("VARCHAR2(150)", table.getColumns().get(2).getType());
|
assertEquals("VARCHAR2(150)", table.getColumns().get(2).getType());
|
||||||
assertEquals(true, table.getColumns().get(2).isNullable());
|
assertEquals(true, table.getColumns().get(2).isNullable());
|
||||||
assertEquals(2, table.getColumns().get(2).getOrder());
|
assertEquals(2, table.getColumns().get(2).getOrder());
|
||||||
|
assertEquals(false, table.getColumns().get(2).isAutoIncrement());
|
||||||
|
|
||||||
assertSame("Wrong or no parent set", table, table.getPrimaryKey().getParent());
|
assertSame("Wrong or no parent set", table, table.getPrimaryKey().getParent());
|
||||||
assertEquals("pk_node", table.getPrimaryKey().getName());
|
assertEquals("pk_node", table.getPrimaryKey().getName());
|
||||||
|
@@ -32,6 +32,7 @@ public class Column extends AbstractDbObject
|
|||||||
{
|
{
|
||||||
private String type;
|
private String type;
|
||||||
private boolean nullable;
|
private boolean nullable;
|
||||||
|
private boolean autoIncrement;
|
||||||
private int order;
|
private int order;
|
||||||
|
|
||||||
|
|
||||||
@@ -104,11 +105,30 @@ public class Column extends AbstractDbObject
|
|||||||
this.order = order;
|
this.order = order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return whether the column has an auto-increment flag set.
|
||||||
|
*/
|
||||||
|
public boolean isAutoIncrement()
|
||||||
|
{
|
||||||
|
return this.autoIncrement;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param autoIncrement whether this column has the auto-increment flag set.
|
||||||
|
*/
|
||||||
|
public void setAutoIncrement(boolean autoIncrement)
|
||||||
|
{
|
||||||
|
this.autoIncrement = autoIncrement;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = super.hashCode();
|
int result = super.hashCode();
|
||||||
|
result = prime * result + (this.autoIncrement ? 1231 : 1237);
|
||||||
result = prime * result + (this.nullable ? 1231 : 1237);
|
result = prime * result + (this.nullable ? 1231 : 1237);
|
||||||
result = prime * result + this.order;
|
result = prime * result + this.order;
|
||||||
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
|
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
|
||||||
@@ -122,6 +142,7 @@ public class Column extends AbstractDbObject
|
|||||||
if (!super.equals(obj)) return false;
|
if (!super.equals(obj)) return false;
|
||||||
if (getClass() != obj.getClass()) return false;
|
if (getClass() != obj.getClass()) return false;
|
||||||
Column other = (Column) obj;
|
Column other = (Column) obj;
|
||||||
|
if (this.autoIncrement != other.autoIncrement) return false;
|
||||||
if (this.nullable != other.nullable) return false;
|
if (this.nullable != other.nullable) return false;
|
||||||
if (this.order != other.order) return false;
|
if (this.order != other.order) return false;
|
||||||
if (this.type == null)
|
if (this.type == null)
|
||||||
@@ -138,15 +159,18 @@ public class Column extends AbstractDbObject
|
|||||||
DbProperty thisTypeProp = new DbProperty(this, "type");
|
DbProperty thisTypeProp = new DbProperty(this, "type");
|
||||||
DbProperty thisNullableProp = new DbProperty(this, "nullable");
|
DbProperty thisNullableProp = new DbProperty(this, "nullable");
|
||||||
DbProperty thisOrderProp = new DbProperty(this, "order");
|
DbProperty thisOrderProp = new DbProperty(this, "order");
|
||||||
|
DbProperty thisAutoIncProp = new DbProperty(this, "autoIncrement");
|
||||||
|
|
||||||
Column thatColumn = (Column) right;
|
Column thatColumn = (Column) right;
|
||||||
DbProperty thatTypeProp = new DbProperty(thatColumn, "type");
|
DbProperty thatTypeProp = new DbProperty(thatColumn, "type");
|
||||||
DbProperty thatNullableProp = new DbProperty(thatColumn, "nullable");
|
DbProperty thatNullableProp = new DbProperty(thatColumn, "nullable");
|
||||||
DbProperty thatOrderProp = new DbProperty(thatColumn, "order");
|
DbProperty thatOrderProp = new DbProperty(thatColumn, "order");
|
||||||
|
DbProperty thatAutoIncProp = new DbProperty(thatColumn, "autoIncrement");
|
||||||
|
|
||||||
comparisonUtils.compareSimple(thisTypeProp, thatTypeProp, ctx);
|
comparisonUtils.compareSimple(thisTypeProp, thatTypeProp, ctx);
|
||||||
comparisonUtils.compareSimple(thisNullableProp, thatNullableProp, ctx);
|
comparisonUtils.compareSimple(thisNullableProp, thatNullableProp, ctx);
|
||||||
comparisonUtils.compareSimple(thisOrderProp, thatOrderProp, ctx);
|
comparisonUtils.compareSimple(thisOrderProp, thatOrderProp, ctx);
|
||||||
|
comparisonUtils.compareSimple(thisAutoIncProp, thatAutoIncProp, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -68,6 +68,10 @@ public class ColumnTest extends DbObjectTestBase<Column>
|
|||||||
DbProperty thisOrderProp = new DbProperty(thisColumn, "order");
|
DbProperty thisOrderProp = new DbProperty(thisColumn, "order");
|
||||||
DbProperty thatOrderProp = new DbProperty(thatColumn, "order");
|
DbProperty thatOrderProp = new DbProperty(thatColumn, "order");
|
||||||
inOrder.verify(comparisonUtils).compareSimple(thisOrderProp, thatOrderProp, ctx);
|
inOrder.verify(comparisonUtils).compareSimple(thisOrderProp, thatOrderProp, ctx);
|
||||||
|
|
||||||
|
DbProperty thisAutoIncProp = new DbProperty(thisColumn, "autoIncrement");
|
||||||
|
DbProperty thatAutoIncProp = new DbProperty(thatColumn, "autoIncrement");
|
||||||
|
inOrder.verify(comparisonUtils).compareSimple(thisAutoIncProp, thatAutoIncProp, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNull;
|
|||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import org.alfresco.util.schemacomp.ExportDb;
|
import org.alfresco.util.schemacomp.ExportDb;
|
||||||
|
import org.alfresco.util.schemacomp.ExportDbTest;
|
||||||
import org.alfresco.util.schemacomp.model.DbObject;
|
import org.alfresco.util.schemacomp.model.DbObject;
|
||||||
import org.alfresco.util.schemacomp.model.Schema;
|
import org.alfresco.util.schemacomp.model.Schema;
|
||||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||||
@@ -30,6 +31,7 @@ import org.springframework.transaction.PlatformTransactionManager;
|
|||||||
/**
|
/**
|
||||||
* Base class for DBMS-specific ExportDb tests.
|
* Base class for DBMS-specific ExportDb tests.
|
||||||
*
|
*
|
||||||
|
* @see ExportDbTest
|
||||||
* @author Matt Ward
|
* @author Matt Ward
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractExportTester
|
public abstract class AbstractExportTester
|
||||||
|
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertSame;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.alfresco.util.schemacomp.ExportDb;
|
import org.alfresco.util.schemacomp.ExportDb;
|
||||||
|
import org.alfresco.util.schemacomp.ExportDbTest;
|
||||||
import org.alfresco.util.schemacomp.model.Column;
|
import org.alfresco.util.schemacomp.model.Column;
|
||||||
import org.alfresco.util.schemacomp.model.DbObject;
|
import org.alfresco.util.schemacomp.model.DbObject;
|
||||||
import org.alfresco.util.schemacomp.model.ForeignKey;
|
import org.alfresco.util.schemacomp.model.ForeignKey;
|
||||||
@@ -41,6 +42,7 @@ import org.springframework.transaction.support.TransactionTemplate;
|
|||||||
/**
|
/**
|
||||||
* MySQL specific test for the ExportDb class.
|
* MySQL specific test for the ExportDb class.
|
||||||
*
|
*
|
||||||
|
* @see ExportDbTest
|
||||||
* @author Matt Ward
|
* @author Matt Ward
|
||||||
*/
|
*/
|
||||||
public class MySQLDialectExportTester extends AbstractExportTester
|
public class MySQLDialectExportTester extends AbstractExportTester
|
||||||
@@ -96,6 +98,7 @@ public class MySQLDialectExportTester extends AbstractExportTester
|
|||||||
assertEquals("bigint", col.getType());
|
assertEquals("bigint", col.getType());
|
||||||
assertEquals(false, col.isNullable());
|
assertEquals(false, col.isNullable());
|
||||||
assertEquals(1, col.getOrder());
|
assertEquals(1, col.getOrder());
|
||||||
|
assertEquals(false, col.isAutoIncrement());
|
||||||
|
|
||||||
col = colIt.next();
|
col = colIt.next();
|
||||||
assertSame("Incorrect parent or no parent set", otherTable, col.getParent());
|
assertSame("Incorrect parent or no parent set", otherTable, col.getParent());
|
||||||
@@ -164,6 +167,7 @@ public class MySQLDialectExportTester extends AbstractExportTester
|
|||||||
assertEquals("bigint", col.getType());
|
assertEquals("bigint", col.getType());
|
||||||
assertEquals(false, col.isNullable());
|
assertEquals(false, col.isNullable());
|
||||||
assertEquals(1, col.getOrder());
|
assertEquals(1, col.getOrder());
|
||||||
|
assertEquals(true, col.isAutoIncrement());
|
||||||
|
|
||||||
col = colIt.next();
|
col = colIt.next();
|
||||||
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
|
assertSame("Incorrect parent or no parent set", exampleTable, col.getParent());
|
||||||
@@ -271,7 +275,7 @@ public class MySQLDialectExportTester extends AbstractExportTester
|
|||||||
|
|
||||||
"CREATE TABLE export_test_other" +
|
"CREATE TABLE export_test_other" +
|
||||||
" (" +
|
" (" +
|
||||||
" id BIGINT NOT NULL AUTO_INCREMENT," +
|
" id BIGINT NOT NULL," +
|
||||||
" version BIGINT NOT NULL," +
|
" version BIGINT NOT NULL," +
|
||||||
" ex_id BIGINT NOT NULL," +
|
" ex_id BIGINT NOT NULL," +
|
||||||
" local_name VARCHAR(200) NOT NULL," +
|
" local_name VARCHAR(200) NOT NULL," +
|
||||||
|
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertSame;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.alfresco.util.schemacomp.ExportDb;
|
import org.alfresco.util.schemacomp.ExportDb;
|
||||||
|
import org.alfresco.util.schemacomp.ExportDbTest;
|
||||||
import org.alfresco.util.schemacomp.model.Column;
|
import org.alfresco.util.schemacomp.model.Column;
|
||||||
import org.alfresco.util.schemacomp.model.DbObject;
|
import org.alfresco.util.schemacomp.model.DbObject;
|
||||||
import org.alfresco.util.schemacomp.model.ForeignKey;
|
import org.alfresco.util.schemacomp.model.ForeignKey;
|
||||||
@@ -42,6 +43,7 @@ import org.springframework.transaction.support.TransactionTemplate;
|
|||||||
/**
|
/**
|
||||||
* Test implementation for the PostgreSQL database dialect.
|
* Test implementation for the PostgreSQL database dialect.
|
||||||
*
|
*
|
||||||
|
* @see ExportDbTest
|
||||||
* @author Matt Ward
|
* @author Matt Ward
|
||||||
*/
|
*/
|
||||||
public class PostgreSQLDialectExportTester extends AbstractExportTester
|
public class PostgreSQLDialectExportTester extends AbstractExportTester
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
<column name="id" order="1">
|
<column name="id" order="1">
|
||||||
<type>NUMBER(10)</type>
|
<type>NUMBER(10)</type>
|
||||||
<nullable>false</nullable>
|
<nullable>false</nullable>
|
||||||
|
<autoincrement>true</autoincrement>
|
||||||
</column>
|
</column>
|
||||||
<column name="nodeRef" order="3">
|
<column name="nodeRef" order="3">
|
||||||
<type>VARCHAR2(200)</type>
|
<type>VARCHAR2(200)</type>
|
||||||
|
Reference in New Issue
Block a user