use of net.sf.jsqlparser.expression.UserVariable in project JSqlParser by JSQLParser.
the class DeclareStatementTest method testDeclareTable.
@Test
public void testDeclareTable() throws JSQLParserException {
String statement = "DECLARE @MyTableVar TABLE (EmpID int NOT NULL, OldVacationHours int, NewVacationHours int, ModifiedDate datetime)";
Statement parsed = assertSqlCanBeParsedAndDeparsed(statement);
DeclareStatement created = new DeclareStatement().withUserVariable(new UserVariable("MyTableVar")).withColumnDefinitions(new ArrayList<>()).addColumnDefinitions(new ColumnDefinition("EmpID", new ColDataType().withDataType("int"), asList("NOT", "NULL")), new ColumnDefinition("OldVacationHours", new ColDataType("int"))).addColumnDefinitions(asList(new ColumnDefinition("NewVacationHours", new ColDataType("int")), new ColumnDefinition("ModifiedDate", new ColDataType("datetime")))).withDeclareType(DeclareType.TABLE);
assertDeparse(created, statement);
assertEqualsObjectTree(parsed, created);
}
use of net.sf.jsqlparser.expression.UserVariable in project jans by JanssenProject.
the class SpannerOperationServiceImpl method lookupImpl.
private List<AttributeData> lookupImpl(TableMapping tableMapping, String key, String... attributes) throws SearchException, EntryConvertationException {
try {
String tableName = tableMapping.getTableName();
// If all requested attributes belong to one table get row by primary key
Set<String> childTables = connectionProvider.getTableChildAttributes(tableName);
List<AttributeData> result = null;
if (childTables == null) {
// All attributes in one table
if (attributes == null) {
// Request all attributes
try (ResultSet resultSet = databaseClient.singleUse().read(tableName, KeySet.singleKey(Key.of(key)), tableMapping.getColumTypes().keySet())) {
result = getAttributeDataList(tableMapping.getObjectClass(), resultSet, true);
}
} else {
// Request only required attributes
try (ResultSet resultSet = databaseClient.singleUse().read(tableName, KeySet.singleKey(Key.of(key)), Arrays.asList(attributes))) {
result = getAttributeDataList(tableMapping.getObjectClass(), resultSet, true);
}
}
} else {
Table table = buildTable(tableMapping);
PlainSelect sqlSelectQuery = new PlainSelect();
sqlSelectQuery.setFromItem(table);
List<SelectItem> selectItems = buildSelectAttributes(tableMapping, key, attributes);
sqlSelectQuery.addSelectItems(selectItems);
Column leftColumn = new Column(tableAlias, DOC_ID);
UserVariable rightValue = new UserVariable(DOC_ID);
EqualsTo whereExp = new EqualsTo(leftColumn, rightValue);
sqlSelectQuery.setWhere(whereExp);
Limit limit = new Limit();
limit.setRowCount(new LongValue(1));
sqlSelectQuery.setLimit(limit);
Statement statement = Statement.newBuilder(sqlSelectQuery.toString()).bind(DOC_ID).to(key).build();
LOG.debug("Executing lookup query: '{}'", statement);
try (ResultSet resultSet = databaseClient.singleUse().executeQuery(statement)) {
result = getAttributeDataList(tableMapping.getObjectClass(), resultSet, true);
}
}
if (result != null) {
return result;
}
} catch (SpannerException ex) {
throw new SearchException(String.format("Failed to lookup query by key: '%s'", key), ex);
}
throw new SearchException(String.format("Failed to lookup entry by key: '%s'", key));
}
use of net.sf.jsqlparser.expression.UserVariable in project JSqlParser by JSQLParser.
the class DeclareStatementTest method testDeclareTypeList.
@Test
public void testDeclareTypeList() throws JSQLParserException {
String statement = "DECLARE @group nvarchar (50), @sales money";
Statement parsed = assertSqlCanBeParsedAndDeparsed(statement);
DeclareStatement created = new DeclareStatement().addTypeDefExprList(asList(new TypeDefExpr(new UserVariable().withName("group"), new ColDataType().withDataType("nvarchar").addArgumentsStringList("50"), null), new TypeDefExpr(new UserVariable().withName("sales"), new ColDataType().withDataType("money"), null))).withDeclareType(DeclareType.TYPE);
assertDeparse(created, statement);
assertEqualsObjectTree(parsed, created);
}
use of net.sf.jsqlparser.expression.UserVariable in project JSqlParser by JSQLParser.
the class DeclareStatementTest method testDeclareTypeWithDefault.
@Test
public void testDeclareTypeWithDefault() throws JSQLParserException {
String statement = "DECLARE @find varchar (30) = 'Man%'";
Statement parsed = assertSqlCanBeParsedAndDeparsed(statement);
DeclareStatement created = new DeclareStatement().addTypeDefExprList(new TypeDefExpr(new UserVariable().withName("find"), new ColDataType().withDataType("varchar").addArgumentsStringList("30"), new StringValue().withValue("Man%"))).withDeclareType(DeclareType.TYPE);
assertDeparse(created, statement);
assertEqualsObjectTree(parsed, created);
}
use of net.sf.jsqlparser.expression.UserVariable in project JSqlParser by JSQLParser.
the class DeclareStatementTest method testDeclareType.
@Test
public void testDeclareType() throws JSQLParserException {
String statement = "DECLARE @find nvarchar (30)";
Statement parsed = assertSqlCanBeParsedAndDeparsed(statement);
DeclareStatement created = new DeclareStatement().addTypeDefExprList(new TypeDefExpr(new UserVariable().withName("find"), new ColDataType().withDataType("nvarchar").addArgumentsStringList("30"), null)).withDeclareType(DeclareType.TYPE);
assertDeparse(created, statement);
assertEqualsObjectTree(parsed, created);
}
Aggregations