use of liquibase.statement.SequenceNextValueFunction in project liquibase by liquibase.
the class XMLChangeLogSerializerTest method createNode_AddDefaultValueChange.
@Test
public void createNode_AddDefaultValueChange() throws Exception {
AddDefaultValueChange change = new AddDefaultValueChange();
change.setSchemaName("SCHEMA_NAME");
change.setTableName("TABLE_NAME");
change.setColumnName("COLUMN_NAME");
change.setDefaultValue("DEF STRING");
change.setDefaultValueNumeric("42");
change.setDefaultValueBoolean(true);
change.setDefaultValueDate("2007-01-02");
change.setDefaultValueSequenceNext(new SequenceNextValueFunction("sampleSeq"));
Element node = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change);
assertEquals("addDefaultValue", node.getTagName());
assertEquals("SCHEMA_NAME", node.getAttribute("schemaName"));
assertEquals("TABLE_NAME", node.getAttribute("tableName"));
assertEquals("COLUMN_NAME", node.getAttribute("columnName"));
assertEquals("DEF STRING", node.getAttribute("defaultValue"));
assertEquals("42", node.getAttribute("defaultValueNumeric"));
assertEquals("true", node.getAttribute("defaultValueBoolean"));
assertEquals("2007-01-02", node.getAttribute("defaultValueDate"));
assertEquals("sampleSeq", node.getAttribute("defaultValueSequenceNext"));
}
use of liquibase.statement.SequenceNextValueFunction in project liquibase by liquibase.
the class JsonChangeLogSerializerTest method serialize_changeSet.
@Test
public void serialize_changeSet() {
AddColumnChange addColumnChange = new AddColumnChange();
addColumnChange.setCatalogName("cat");
addColumnChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("col1").setDefaultValueNumeric(3));
addColumnChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("col2").setDefaultValueComputed(new DatabaseFunction("NOW()")));
addColumnChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("col3").setDefaultValueBoolean(true));
addColumnChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("col2").setDefaultValueDate(new Date(0)));
addColumnChange.addColumn((AddColumnConfig) new AddColumnConfig().setName("col2").setDefaultValueSequenceNext(new SequenceNextValueFunction("seq_me")));
ChangeSet changeSet = new ChangeSet("1", "nvoxland", false, false, "path/to/file.json", null, null, null);
changeSet.addChange(addColumnChange);
assertEquals("{\n" + " \"changeSet\": {\n" + " \"id\": \"1\",\n" + " \"author\": \"nvoxland\",\n" + " \"objectQuotingStrategy\": \"LEGACY\",\n" + " \"changes\": [\n" + " {\n" + " \"addColumn\": {\n" + " \"catalogName\": \"cat\",\n" + " \"columns\": [\n" + " {\n" + " \"column\": {\n" + " \"defaultValueNumeric\": 3,\n" + " \"name\": \"col1\"\n" + " }\n" + " },\n" + " {\n" + " \"column\": {\n" + " \"defaultValueComputed\": \"NOW()\",\n" + " \"name\": \"col2\"\n" + " }\n" + " },\n" + " {\n" + " \"column\": {\n" + " \"defaultValueBoolean\": true,\n" + " \"name\": \"col3\"\n" + " }\n" + " },\n" + " {\n" + " \"column\": {\n" + " \"defaultValueDate\": 1970-01-01T00:00:00Z,\n" + " \"name\": \"col2\"\n" + " }\n" + " },\n" + " {\n" + " \"column\": {\n" + " \"defaultValueSequenceNext\": \"seq_me\",\n" + " \"name\": \"col2\"\n" + " }\n" + " }]\n" + " \n" + " }\n" + " }]\n" + " \n" + " }\n" + "}\n", new JsonChangeLogSerializer().serialize(changeSet, true));
}
use of liquibase.statement.SequenceNextValueFunction in project liquibase by liquibase.
the class ChangeParameterMetaData method getExampleValue.
public Object getExampleValue(Database database) {
if (exampleValues != null) {
Object exampleValue = null;
for (Map.Entry<String, Object> entry : exampleValues.entrySet()) {
if (entry.getKey().equalsIgnoreCase("all")) {
exampleValue = entry.getValue();
} else if (DatabaseList.definitionMatches(entry.getKey(), database, false)) {
return entry.getValue();
}
}
if (exampleValue != null) {
return exampleValue;
}
}
Map standardExamples = new HashMap();
standardExamples.put("tableName", "person");
standardExamples.put("schemaName", "public");
standardExamples.put("tableSchemaName", "public");
standardExamples.put("catalogName", "cat");
standardExamples.put("tableCatalogName", "cat");
standardExamples.put("columnName", "id");
standardExamples.put("columnNames", "id, name");
standardExamples.put("indexName", "idx_address");
standardExamples.put("columnDataType", "int");
standardExamples.put("dataType", "int");
standardExamples.put("sequenceName", "seq_id");
standardExamples.put("viewName", "v_person");
standardExamples.put("constraintName", "const_name");
standardExamples.put("primaryKey", "pk_id");
if (standardExamples.containsKey(parameterName)) {
return standardExamples.get(parameterName);
}
for (String prefix : new String[] { "base", "referenced", "new", "old" }) {
if (parameterName.startsWith(prefix)) {
String mainName = StringUtils.lowerCaseFirst(parameterName.replaceFirst("^" + prefix, ""));
if (standardExamples.containsKey(mainName)) {
return standardExamples.get(mainName);
}
}
}
if (dataType.equals("string")) {
return "A String";
} else if (dataType.equals("integer")) {
return 3;
} else if (dataType.equals("boolean")) {
return true;
} else if (dataType.equals("bigInteger")) {
return new BigInteger("371717");
} else if (dataType.equals("list")) {
//"TODO";
return null;
} else if (dataType.equals("sequenceNextValueFunction")) {
return new SequenceNextValueFunction("seq_name");
} else if (dataType.equals("databaseFunction")) {
return new DatabaseFunction("now");
} else if (dataType.equals("list of columnConfig")) {
ArrayList<ColumnConfig> list = new ArrayList<ColumnConfig>();
list.add(new ColumnConfig().setName("id").setType("int"));
return list;
} else if (dataType.equals("list of addColumnConfig")) {
ArrayList<ColumnConfig> list = new ArrayList<ColumnConfig>();
list.add(new AddColumnConfig().setName("id").setType("int"));
return list;
} else if (dataType.equals("list of loadDataColumnConfig")) {
ArrayList<ColumnConfig> list = new ArrayList<ColumnConfig>();
list.add(new LoadDataColumnConfig().setName("id").setType("int"));
return list;
} else {
throw new UnexpectedLiquibaseException("Unknown dataType " + dataType + " for " + getParameterName());
}
}
use of liquibase.statement.SequenceNextValueFunction in project liquibase by liquibase.
the class ColumnConfig method load.
@Override
public void load(ParsedNode parsedNode, ResourceAccessor resourceAccessor) throws ParsedNodeException {
for (ParsedNode child : parsedNode.getChildren()) {
if (!ObjectUtil.hasProperty(this, child.getName())) {
throw new ParsedNodeException("Unexpected node: " + child.getName());
}
}
name = parsedNode.getChildValue(null, "name", String.class);
computed = parsedNode.getChildValue(null, "computed", Boolean.class);
type = parsedNode.getChildValue(null, "type", String.class);
encoding = parsedNode.getChildValue(null, "encoding", String.class);
autoIncrement = parsedNode.getChildValue(null, "autoIncrement", Boolean.class);
startWith = parsedNode.getChildValue(null, "startWith", BigInteger.class);
incrementBy = parsedNode.getChildValue(null, "incrementBy", BigInteger.class);
remarks = parsedNode.getChildValue(null, "remarks", String.class);
descending = parsedNode.getChildValue(null, "descending", Boolean.class);
value = parsedNode.getChildValue(null, "value", String.class);
if (value == null) {
value = StringUtils.trimToNull((String) parsedNode.getValue());
}
setValueNumeric(parsedNode.getChildValue(null, "valueNumeric", String.class));
try {
valueDate = parsedNode.getChildValue(null, "valueDate", Date.class);
} catch (ParsedNodeException e) {
valueComputed = new DatabaseFunction(parsedNode.getChildValue(null, "valueDate", String.class));
}
valueBoolean = parsedNode.getChildValue(null, "valueBoolean", Boolean.class);
valueBlobFile = parsedNode.getChildValue(null, "valueBlobFile", String.class);
valueClobFile = parsedNode.getChildValue(null, "valueClobFile", String.class);
String valueComputedString = parsedNode.getChildValue(null, "valueComputed", String.class);
if (valueComputedString != null) {
valueComputed = new DatabaseFunction(valueComputedString);
}
String valueSequenceNextString = parsedNode.getChildValue(null, "valueSequenceNext", String.class);
if (valueSequenceNextString != null) {
valueSequenceNext = new SequenceNextValueFunction(valueSequenceNextString);
}
String valueSequenceCurrentString = parsedNode.getChildValue(null, "valueSequenceCurrent", String.class);
if (valueSequenceCurrentString != null) {
valueSequenceCurrent = new SequenceCurrentValueFunction(valueSequenceCurrentString);
}
defaultValueConstraintName = parsedNode.getChildValue(null, "defaultValueConstraintName", String.class);
defaultValue = parsedNode.getChildValue(null, "defaultValue", String.class);
setDefaultValueNumeric(parsedNode.getChildValue(null, "defaultValueNumeric", String.class));
try {
defaultValueDate = parsedNode.getChildValue(null, "defaultValueDate", Date.class);
} catch (ParsedNodeException e) {
defaultValueComputed = new DatabaseFunction(parsedNode.getChildValue(null, "defaultValueDate", String.class));
}
defaultValueBoolean = parsedNode.getChildValue(null, "defaultValueBoolean", Boolean.class);
String defaultValueComputedString = parsedNode.getChildValue(null, "defaultValueComputed", String.class);
if (defaultValueComputedString != null) {
defaultValueComputed = new DatabaseFunction(defaultValueComputedString);
}
String defaultValueSequenceNextString = parsedNode.getChildValue(null, "defaultValueSequenceNext", String.class);
if (defaultValueSequenceNextString != null) {
defaultValueSequenceNext = new SequenceNextValueFunction(defaultValueSequenceNextString);
}
loadConstraints(parsedNode.getChild(null, "constraints"));
}
use of liquibase.statement.SequenceNextValueFunction in project liquibase by liquibase.
the class InsertOrUpdateGeneratorOracleTest method testInsertSequenceValWithSchema.
@Test
public void testInsertSequenceValWithSchema() {
OracleDatabase database = new OracleDatabase();
InsertGenerator generator = new InsertGenerator();
InsertStatement statement = new InsertStatement("mycatalog", "myschema", "mytable");
ColumnConfig columnConfig = new ColumnConfig();
columnConfig.setValueSequenceNext(new SequenceNextValueFunction("myschema.my_seq"));
columnConfig.setName("col3");
statement.addColumn(columnConfig);
Sql[] sql = generator.generateSql(statement, database, null);
String theSql = sql[0].toSql();
assertEquals("INSERT INTO mycatalog.mytable (col3) VALUES (\"myschema\".\"my_seq\".nextval)", theSql);
}
Aggregations