Changes for new ODATA lib, and psql case fixes

This commit is contained in:
michaelpede 2021-07-22 16:25:14 -07:00
parent 0d8b8efaab
commit d726f30fdd
8 changed files with 46 additions and 15 deletions

View File

@ -251,7 +251,7 @@ public class GenericEntityCollectionProcessor implements EntityCollectionProcess
if (uriResource instanceof UriResourcePrimitiveProperty) if (uriResource instanceof UriResourcePrimitiveProperty)
{ {
EdmProperty edmProperty = ((UriResourcePrimitiveProperty) uriResource).getProperty(); EdmProperty edmProperty = ((UriResourcePrimitiveProperty) uriResource).getProperty();
final String sortPropertyName = edmProperty.getName(); final String sortPropertyName = edmProperty.getName().toLowerCase();
queryString = queryString + " ORDER BY "+sortPropertyName; queryString = queryString + " ORDER BY "+sortPropertyName;
if(orderByItem.isDescending()) if(orderByItem.isDescending())
{ {
@ -260,7 +260,7 @@ public class GenericEntityCollectionProcessor implements EntityCollectionProcess
} }
} }
} }
LOG.debug("SQL Query: "+queryString); LOG.info("SQL Query: "+queryString);
ResultSet resultSet = statement.executeQuery(queryString); ResultSet resultSet = statement.executeQuery(queryString);
// special return logic for $count // special return logic for $count

View File

@ -103,7 +103,7 @@ public class GenericEntityProcessor implements EntityProcessor
for (final UriParameter key : keyPredicates) for (final UriParameter key : keyPredicates)
{ {
// key // key
String keyName = key.getName(); String keyName = key.getName().toLowerCase();
String keyValue = key.getText(); String keyValue = key.getText();
if (sqlCriteria==null) if (sqlCriteria==null)
{ {
@ -122,7 +122,7 @@ public class GenericEntityProcessor implements EntityProcessor
queryString = queryString + " WHERE " + sqlCriteria; queryString = queryString + " WHERE " + sqlCriteria;
} }
LOG.debug("SQL Query: "+queryString); LOG.info("SQL Query: "+queryString);
ResultSet resultSet = statement.executeQuery(queryString); ResultSet resultSet = statement.executeQuery(queryString);
String primaryFieldName = resource.getPrimaryKeyName(); String primaryFieldName = resource.getPrimaryKeyName();

View File

@ -1,13 +1,11 @@
package org.reso.service.data.common; package org.reso.service.data.common;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.Property;
import org.apache.olingo.commons.api.data.ValueType; import org.apache.olingo.commons.api.data.ValueType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.ex.ODataRuntimeException; import org.apache.olingo.commons.api.ex.ODataRuntimeException;
import org.reso.service.data.GenericEntityCollectionProcessor;
import org.reso.service.data.meta.FieldInfo; import org.reso.service.data.meta.FieldInfo;
import org.reso.service.data.meta.ResourceInfo; import org.reso.service.data.meta.ResourceInfo;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -15,12 +13,10 @@ import org.slf4j.LoggerFactory;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
public class CommonDataProcessing public class CommonDataProcessing
{ {
@ -38,7 +34,7 @@ public class CommonDataProcessing
{ {
value = resultSet.getTimestamp(fieldName); value = resultSet.getTimestamp(fieldName);
} }
else if (field.getFieldName().equals("EnumTest")) // @TEST CODE else if (field.getODATAFieldName().equals("EnumTest")) // @TEST CODE
{ {
ArrayList<Integer> responses = new ArrayList(); ArrayList<Integer> responses = new ArrayList();
responses.add(1); responses.add(1);
@ -65,7 +61,7 @@ public class CommonDataProcessing
Entity ent = new Entity(); Entity ent = new Entity();
for (FieldInfo field : fields) for (FieldInfo field : fields)
{ {
String fieldName = field.getFieldName(); String fieldName = field.getODATAFieldName();
Object value = null; Object value = null;
if (selectLookup==null || selectLookup.containsKey(fieldName) ) if (selectLookup==null || selectLookup.containsKey(fieldName) )
{ {

View File

@ -40,6 +40,10 @@ public class FieldInfo
*/ */
public String getFieldName() public String getFieldName()
{
return fieldName.toLowerCase();
}
public String getODATAFieldName()
{ {
return fieldName; return fieldName;
} }

View File

@ -23,7 +23,8 @@ import java.util.*;
/** /**
* $filter * $filter
*/ */
public class MySQLFilterExpressionVisitor implements ExpressionVisitor<String> { public class MySQLFilterExpressionVisitor implements ExpressionVisitor<String>
{
private static final Logger LOG = LoggerFactory.getLogger(MySQLFilterExpressionVisitor.class); private static final Logger LOG = LoggerFactory.getLogger(MySQLFilterExpressionVisitor.class);
private static final Map<BinaryOperatorKind, String> BINARY_OPERATORS = new HashMap<BinaryOperatorKind, String>() {{ private static final Map<BinaryOperatorKind, String> BINARY_OPERATORS = new HashMap<BinaryOperatorKind, String>() {{
put(BinaryOperatorKind.ADD, " + "); put(BinaryOperatorKind.ADD, " + ");
@ -63,6 +64,17 @@ public class MySQLFilterExpressionVisitor implements ExpressionVisitor<String> {
return left + strOperator + right; return left + strOperator + right;
} }
// @TODO I'm unsure where this would be called.
@Override public String visitBinaryOperator(BinaryOperatorKind operator, String s, List<String> list)
throws ExpressionVisitException, ODataApplicationException
{
String strOperator = BINARY_OPERATORS.get(operator);
throw new ODataApplicationException("Unsupported binary operation: " + operator.name(),
operator == BinaryOperatorKind.HAS ?
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode() :
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ENGLISH);
}
@Override @Override
public String visitUnaryOperator(UnaryOperatorKind operator, String operand) public String visitUnaryOperator(UnaryOperatorKind operator, String operand)
throws ExpressionVisitException, ODataApplicationException { throws ExpressionVisitException, ODataApplicationException {

View File

@ -60,6 +60,17 @@ public class PostgreSQLFilterExpressionVisitor implements ExpressionVisitor<Stri
return left + strOperator + right; return left + strOperator + right;
} }
// @TODO I'm unsure where this would be called.
@Override public String visitBinaryOperator(BinaryOperatorKind operator, String s, List<String> list)
throws ExpressionVisitException, ODataApplicationException
{
String strOperator = BINARY_OPERATORS.get(operator);
throw new ODataApplicationException("Unsupported binary operation: " + operator.name(),
operator == BinaryOperatorKind.HAS ?
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode() :
HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ENGLISH);
}
@Override @Override
public String visitUnaryOperator(UnaryOperatorKind operator, String operand) public String visitUnaryOperator(UnaryOperatorKind operator, String operand)
throws ExpressionVisitException, ODataApplicationException { throws ExpressionVisitException, ODataApplicationException {

View File

@ -71,13 +71,21 @@ public class ResourceInfo
String pkColumnName = pkColumns.getString("COLUMN_NAME"); String pkColumnName = pkColumns.getString("COLUMN_NAME");
Integer pkPosition = pkColumns.getInt("KEY_SEQ"); Integer pkPosition = pkColumns.getInt("KEY_SEQ");
LOG.debug(""+pkColumnName+" is the "+pkPosition+". column of the primary key of the table "+tableName); LOG.debug(""+pkColumnName+" is the "+pkPosition+". column of the primary key of the table "+tableName);
primaryKey = pkColumnName; primaryKey = pkColumnName.toLowerCase();
} }
String[] splitKey = primaryKey.split("Numeric"); String[] splitKey = primaryKey.split("numeric");
if (splitKey.length>=1) if (splitKey.length>=1)
primaryKey = splitKey[0]; primaryKey = splitKey[0];
ArrayList<FieldInfo> fields = this.getFieldList();
for (FieldInfo field : fields)
{
String fieldName = field.getFieldName();
if (primaryKey.equals(fieldName))
primaryKey = field.getODATAFieldName();
}
this.primaryKeyName = primaryKey; this.primaryKeyName = primaryKey;
} }

View File

@ -61,7 +61,7 @@ public class RESOedmProvider extends CsdlAbstractEdmProvider
for (FieldInfo field : fields) if (field.isComplex()) for (FieldInfo field : fields) if (field.isComplex())
{ {
String fieldName = field.getFieldName(); String fieldName = field.getODATAFieldName();
CsdlProperty property = new CsdlProperty().setName(fieldName).setType(field.getType()).setCollection(field.isCollection()); CsdlProperty property = new CsdlProperty().setName(fieldName).setType(field.getType()).setCollection(field.isCollection());
Integer maxLength = field.getMaxLength(); Integer maxLength = field.getMaxLength();
@ -124,7 +124,7 @@ public class RESOedmProvider extends CsdlAbstractEdmProvider
for (FieldInfo field : fields) if (!field.isComplex()) for (FieldInfo field : fields) if (!field.isComplex())
{ {
String fieldName = field.getFieldName(); String fieldName = field.getODATAFieldName();
CsdlProperty property = new CsdlProperty().setName(fieldName).setType(field.getType()).setCollection(field.isCollection()); CsdlProperty property = new CsdlProperty().setName(fieldName).setType(field.getType()).setCollection(field.isCollection());
Integer maxLength = field.getMaxLength(); Integer maxLength = field.getMaxLength();