Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * JBoss, Home of Professional Open Source.
    * See the COPYRIGHT.txt file distributed with this work for information
    * regarding copyright ownership.  Some portions may be licensed
    * to Red Hat, Inc. under one or more contributor license agreements.
    *
    * This library is free software; you can redistribute it and/or
    * modify it under the terms of the GNU Lesser General Public
    * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this library; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   * 02110-1301 USA.
   */
  package org.teiid.olingo.service;
  
  import java.net.URI;
  import java.sql.Blob;
  import java.sql.Clob;
  import java.sql.SQLXML;
  import java.util.Arrays;
  import java.util.List;
  import java.util.Map;
  
 
 public class ODataSQLBuilder extends RequestURLHierarchyVisitor {
     private final MetadataStore metadata;
     private boolean prepared = true;
     private final ArrayList<SQLParameterparams = new ArrayList<SQLParameter>();
     private FromClause fromClause;
     private Criteria criteria;
     private final ArrayList<TeiidExceptionexceptions = new ArrayList<TeiidException>();
     private Table edmEntityTable;
     private GroupSymbol edmEntityTableGroup;
     private EdmEntityType edmEntityType;
     private SkipOption skipOption;
     private TopOption topOption;
     private boolean countOption;
     private OrderBy orderBy;
     private boolean selectionComplete;
     private String nextToken;
     private boolean aliasedGroups;
     private boolean countQuery = false;
     private boolean reference = false;
     private String baseURI;
     private ServiceMetadata serviceMetadata;
     private boolean distinct = false;
     private ExpandOption expandOption;
     private ExpandInfo expandInfo;
     private ItResource itResource
     
     static class UniqueNameGenerator {
         private final AtomicInteger groupCount = new AtomicInteger(1);
         public String getNextGroup() {
             String aliasGroup = "g"+this..getAndIncrement(); //$NON-NLS-1$
             return aliasGroup;
         }
     }
     
     class ItResource {
         private ElementSymbol referencedProperty;
         private Table referencedTable;
         private ProjectedColumn projectedProperty;
         private FromClause projectedFromClause;
         
         public ItResource(ElementSymbol esTable table) {
             this. = es;
             this. = table;
         }
 
         public ItResource(Table table) {
             this(nulltable);
         }
 
         public ElementSymbol getReferencedProperty() {
             return ;
         }
 
         public Table getReferencedTable() {
             return ;
         }
 
         public ProjectedColumn getProjectedProperty() {
             return ;
         }
 
         public FromClause getProjectedFromClause() {
             return ;
         }
 
         public void setProjectedProperty(ProjectedColumn projectedProperty) {
             this. = projectedProperty;
         }
 
         public void setProjectedFromClause(FromClause projectedFromClause) {
             this. = projectedFromClause;
         }
     }
     
     public ODataSQLBuilder(MetadataStore metadataboolean prepared,
             boolean aliasedGroupsString baseURI,
             ServiceMetadata serviceMetadata) {
         this. = metadata;
         this. = prepared;
         this. = aliasedGroups;
         this. = baseURI;
         this. = serviceMetadata;
     }
 
     public EdmEntityType getEdmEntityType() {
         return this.;
     }
 
     public boolean includeTotalSize() {
         return ;
     }
 
     public Integer getSkip() {
         if ( == null) {
             return null;
         }
         return .getValue();
     }
 
     public Integer getTop() {
         if ( == null) {
             return null;
         }
         return .getValue();
     }
     
         if (this. != null
                 && this..getReferencedProperty() != null
                 && this..getReferencedProperty().equals(pc.getExpression())
                 && .getProjectedProperty() != null) {
             return .getProjectedProperty();
         }
         return pc;
     }
 
     public Query selectQuery() throws TeiidException {
         
         if (this. != null) {
             processExpandOption(this.);
         }
         
         if (!this..isEmpty()) {
             throw this..get(0);
         }
 
         int ordinal = 1;
         Select select = new Select();
         List<ProjectedColumnprojected = getProjectedColumns(this.);
         for (ProjectedColumn column:projected) {
             select.addSymbol(column.getExpression());
             column.setOrdinal(ordinal++);
         }
         if (this. != null) {
             projected = getProjectedColumns(this..getEntityType());
             for (ProjectedColumn column:projected) {
                 select.addSymbol(column.getExpression());
                 column.setOrdinal(ordinal++);
             }
         }
         select.setDistinct(this.);
 
         Query query = new Query();
         From from = new From();
         from.addClause(this.);
         if (this. != null && this..getProjectedFromClause() != null) {
             from.addClause(this..getProjectedFromClause());
         }
         query.setSelect(select);
         query.setFrom(from);
         query.setCriteria(this.);
 
         if (this.) {
             AggregateSymbol aggregateSymbol = new AggregateSymbol(...name(), falsenull);
             select = new Select(Arrays.asList(aggregateSymbol));
             query.setSelect(select);
         }
 
         if (this. != null & !) {
             query.setOrderBy(this.);
         }
         return query;
     }
     
     public ExpandInfo getExpandInfo() {
         return this.;
     }
 
     private void processExpandOption(ExpandOption option) {
         if (option.getExpandItems().size() > 1) {
             return;
         }
         for (ExpandItem ei:option.getExpandItems()) {
             
             ExpandSQLBuilder esb = new ExpandSQLBuilder(ei);
             
             EdmNavigationProperty property = esb.getNavigationProperty();
             EdmEntityType entityType = property.getType();
             
             String aliasGroup = .getNextGroup();
             Table expandTable = findTable(entityTypethis.);
             GroupSymbol expandGroup = new GroupSymbol(aliasGroupexpandTable.getFullName());
             
             joinTable(entityTypeexpandTableexpandGroupnullproperty.isCollection(), .);
             
             this. = new ItResource(expandTable);
             
             // process $filter
             if (ei.getFilterOption() != null) {
                 Criteria expandCriteria = processFilterOption(ei.getFilterOption(), expandTableexpandGroup);
                 if (expandCriteria != null) {
                     if (this. == null) {
                         this. = expandCriteria;
                     }
                     else {
                         this. = new CompoundCriteria(.this.expandCriteria);
                     }
                 }
             }
             
             if (ei.getOrderByOption() != null) {
                 if (this. == null) {
                     this. = new OrderBy();
                 }
                 processOrderBy(this.ei.getOrderByOption().getOrders(), expandTableexpandGroupentityType);
             }
             
             // process $select
             processSelectOption(ei.getSelectOption(), expandTableexpandGroupentityType);
             
             this. = new ExpandInfo(property.getName(), entityType,
                     getProjectedColumns(entityType), property.isCollection());
             
             if (ei.getSkipOption() != null 
                     || ei.getCountOption() != null
                     || ei.getTopOption() != null
                     || ei.getLevelsOption() != null) {
                 this..add(new TeiidException(..gs(..)));
             }
         }
     }
 
     private Criteria processFilterOption(FilterOption optionTable tableGroupSymbol groupSymbol) {
         ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(
                 tablegroupSymbolthis.,
                 getUriInfo(), this.this.this.this.);
         Criteria filterCriteria = null;
         try {
             filterCriteria = (Criteria)visitor.getExpression(option.getExpression());
             if (visitor.getLambda() != null) {
             }
         } catch (TeiidException e) {
             this..add(e);
         }
         return filterCriteria;
     }
 
         List<ProjectedColumncolumns = this..get(type.getName());
         List<ProjectedColumnmodified = new ArrayList<ProjectedColumn>();
         for (ProjectedColumn pccolumns) {
             modified.add(replace$ItExpression(pc));
         }
         return modified;
     }
 
     static Table findTable(EdmEntitySet entitySetMetadataStore store) {
         return findTable(entitySet.getEntityType(), store);
     }
 
     static Table findTable(EdmEntityType entityTypeMetadataStore store) {
         FullQualifiedName fqn = entityType.getFullQualifiedName();
         // remove the vdb name
         String withoutVDB = fqn.getNamespace().substring(fqn.getNamespace().lastIndexOf('.')+1);
         Schema schema = store.getSchema(withoutVDB);
         return schema.getTable(entityType.getName());
     }
 
     static Column findColumn(Table tableString propertyName) {
         return table.getColumnByName(propertyName);
     }
 
     public List<SQLParametergetParameters(){
         return this.;
     }
 
     @Override
     public void visit(UriResourceEntitySet info) {
         this. = findTable(info.getEntitySet(), this.);
         this. = info.getEntitySet().getEntityType();
         if () {
             this. = new GroupSymbol("g0"this..getFullName()); //$NON-NLS-1$
         } else {
             this. = new GroupSymbol(this..getFullName()); //$NON-NLS-1$
         }
         
         this. = new UnaryFromClause(this.);
 
         // URL is like /entitySet(key)s
         if (info.getKeyPredicates() != null && !info.getKeyPredicates().isEmpty()) {
             List<UriParameterkeys = info.getKeyPredicates();
             try {
                 this. = buildEntityKeyCriteria(this.,
                         this.keysgetUriInfo(),
                         this.this.);
             } catch (TeiidException e) {
                 this..add(e);
             }
         }
         this. = new ItResource(this.);        
     }
 
     static Criteria buildEntityKeyCriteria(Table tableGroupSymbol tableGroup,
             List<UriParameterkeysUriInfo uriInfoMetadataStore store,
             UniqueNameGenerator nameGeneratorthrows TeiidException {
         
         KeyRecord pk = table.getPrimaryKey();
         if (keys.size() == 1) {
             if (pk.getColumns().size() != 1) {
                 throw new TeiidException(..,
                         ..gs(..,table.getFullName()));
             }
             Column column = table.getPrimaryKey().getColumns().get(0);
             
             ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(
                     tabletableGroupfalseuriInfostorenameGeneratornullnull);
 
             return new CompareCriteria(new ElementSymbol(column.getName(),
                     tableGroup), .visitor.getExpression(keys.get(0).getExpression()));
         }
 
         // complex (multi-keyed)
         List<CriteriacritList = new ArrayList<Criteria>();
         if (pk.getColumns().size() != keys.size()) {
             throw new TeiidException(..,
                     ..gs(..table.getFullName()));
         }
         for (UriParameter key : keys) {
             Column column = findColumn(tablekey.getName());
             ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(
                     tabletableGroupfalseuriInfostorenameGeneratornullnull);
             critList.add(new CompareCriteria(new ElementSymbol(column.getName(), tableGroup), 
                     .visitor.getExpression(key.getExpression())));
         }
         return new CompoundCriteria(.critList);
     }
 
     @Override
     public void visit(SkipOption option) {
         this. = option;
     }
 
     @Override
     public void visit(TopOption option) {
         this. = option;
     }
 
     @Override
     public void visit(CountOption info) {
         this. = info.getValue();
     }
 
     @Override
     public void visit(SelectOption option) {
         if (this.) {
             return;
         }
         processSelectOption(optionthis.this.this.);
     }
 
     private void processSelectOption(SelectOption optionTable tableGroupSymbol groupSymbolEdmEntityType type) {
         if (option == null) {
             // default select columns
             addAllColumns(tablegroupSymboltype);
         }
         else {
             for (SelectItem si:option.getSelectItems()) {
                 if (si.isStar()) {
                     addAllColumns(tablegroupSymboltype);
                     continue;
                 }
 
                 try {
                     ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(
                             tablegroupSymbolfalse,
                             getUriInfo(), this.this.this.this.);
                     ElementSymbol expr = (ElementSymbol)visitor.getExpression(si.getResourcePath());
                     addVisibleColumn(expr.getShortName(), exprtype);
                 } catch (TeiidException e) {
                     this..add(e);
                 }
             }
         }
     }
 
     private void addAllColumns(Table tableGroupSymbol gsfinal EdmEntityType type) {
         if (this.) {
             for (final Column column : table.getPrimaryKey().getColumns()) {
                 addVisibleColumn(column.getName(), new ElementSymbol(column.getName(), gs), type);
             }            
         }
         else {
             for (final Column column : table.getColumns()) {
                 addVisibleColumn(column.getName(), new ElementSymbol(column.getName(), gs), type);
             }
         }
     }
 
     private void addVisibleColumn(final String columnNamefinal Expression exprfinal EdmEntityType entityType) {
         addEntityColumn(columnNameexprtrueentityType);
     }
     
     private void addEntityColumn(final String columnName,
             final Expression exprboolean visibility,
             final EdmEntityType entityType) {
         EdmPropertyImpl edmProperty = (EdmPropertyImpl)  entityType.getProperty(columnName);
         addProjectedColumn(columnNameexprvisibilityedmProperty.getType(), edmProperty.isCollection(), entityType);
     }    
 
     private void addProjectedColumn(final String columnNamefinal Expression expr,
             final boolean visibilityfinal EdmType typefinal boolean collectionfinal EdmEntityType entityType) {
         
         List<ProjectedColumnprojected = this..get(entityType.getName());
         if (projected == null) {
             projected = new ArrayList<ProjectedColumn>();
             this..put(entityType.getName(), projected);
         }
         
         int i = 0;
         for (i = 0; i < projected.size(); i++) {
             ProjectedColumn pc = projected.get(i);
             if (pc.getExpression().equals(expr)) {
                 projected.remove(i);
                 break;
             }
         }
         projected.add(new ProjectedColumn(exprvisibilitytypecollection));
     }
 
     @Override
     public void visit(OrderByOption option) {
         this. = new OrderBy();
 
         if (option == null || option.getOrders().isEmpty()) {
             // provide implicit ordering for cursor logic
             KeyRecord record = this..getPrimaryKey();
             if (record == null) {
                 // if PK is not available there MUST at least one unique key
                 record = this..getUniqueKeys().get(0);
             }
             // provide implicit ordering for cursor logic
             for (Column column:record.getColumns()) {
                 ElementSymbol expr = new ElementSymbol(column.getName(), this.);
                 this..addVariable(expr);
                 addEntityColumn(column.getName(), exprfalsethis.);
             }
         }
         else {
             List<OrderByItemorderBys = option.getOrders();
             processOrderBy(this.orderBysthis.this.this.);
         }
     }
 
     private void processOrderBy(OrderBy orderByList<OrderByItemorderByItemsTable tableGroupSymbol gsEdmEntityType edmType) {
         for (OrderByItem orderby:orderByItems) {
             ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(
                     tablegsfalse,
                     getUriInfo(), this.this.this.this.);
             try {
                 Expression expr = visitor.getExpression(orderby.getExpression());
                 if (expr instanceof ElementSymbol) {
                     orderBy.addVariable(expr, !orderby.isDescending());
                     addEntityColumn(((ElementSymbol)expr).getShortName(), exprfalseedmType);
                 }
                 else {
                     AliasSymbol alias = new AliasSymbol("_orderByAlias"expr);
                     orderBy.addVariable(alias, !orderby.isDescending());
                     addProjectedColumn("_orderByAlias"aliasfalse, EdmInt32.getInstance(), falseedmType);
                 }
             } catch (TeiidException e) {
                 this..add(e);
             }
         }
     }
 
     @Override
     public void visit(FilterOption info) {
         ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(
                 this.this.this.,
                 getUriInfo(), this.this.this.this.);
         
         Criteria filterCriteria = null;
         try {
              filterCriteria = (Criteria)visitor.getExpression(info.getExpression());
         } catch (TeiidException e) {
             this..add(e);
         }
         
         if (visitor.getLambda() != null) {
             Lambda lambda = visitor.getLambda();
             if (lambda.getKind() == ..) {
                 // olingo does not correctly reflect collection on lambda variable
                 joinTable(lambda.getType(), lambda.getTable(), lambda.getGroupSymbol(), null
                         (joinFK(this.lambda.getTable()) == null), .);
                 
                 this. = lambda.getGroupSymbol();
                 this. = lambda.getTable();
                 this. = lambda.getType();                
                 
                 this. = true;
                 this. = filterCriteria;
             }
             else {
                 this. = filterCriteria;
             }
         }
         else {
             this. = filterCriteria;
         }
     }
 
     static ForeignKey joinFK(Table currentTableTable referenceTable) {
         for (ForeignKey fk : currentTable.getForeignKeys()) {
             String refSchemaName = fk.getReferenceKey().getParent().getParent().getName();
             if (referenceTable.getParent().getName().equals(refSchemaName)
                     && referenceTable.getName().equals(fk.getReferenceTableName())) {
                 return fk;
             }
         }
         return null;
     }
     
     @Override
     public void visit(UriResourceNavigation info) {
         EdmNavigationProperty property = info.getProperty();
         EdmEntityType joinTableType = property.getType();
         
         String aliasGroup = .getNextGroup();
         Table joinTable = findTable(joinTableTypethis.);
         GroupSymbol joinGroup = new GroupSymbol(aliasGroupjoinTable.getFullName());
         
         joinTable(joinTableTypejoinTablejoinGroupinfo.getKeyPredicates(), property.isCollection(), .);
         this. = joinGroup;
         this. = joinTable;
         this. = joinTableType;
         this. = new ItResource(this.);
     }
 
     private void joinTable(EdmEntityType joinTableTypeTable joinTable,
             GroupSymbol joinGroupList<UriParameterkeysboolean isCollectionJoinType joinType) {
         
         ForeignKey fk = null;
         if (isCollection) {
             fk = joinFK(joinTablethis.);    
         }
         else {
             fk = joinFK(this.joinTable);
         }
         
         if (fk == null) {
             this..add(new TeiidException("Fk not found"));
             return;
         }
         
         List<StringrefColumns = fk.getReferenceColumns();
         if (refColumns == null) {
             refColumns = getColumnNames(this..getPrimaryKey().getColumns());
         }
 
         try {
             if (keys != null && keys.size() > 0) {
                 // here the previous entityset is verbose; need to be canonicalized
                 this. = buildEntityKeyCriteria(joinTablejoinGroup,
                         keysgetUriInfo(), this.this.);
                    this. = new UnaryFromClause(joinGroup);
             }
             else {
                 this. = addJoinTable(joinTypejoinGroup,
                         this.refColumns,
                         getColumnNames(fk.getColumns()));
             }
         } catch (TeiidException e) {
             this..add(e);
         }
     }
 
     private FromClause addJoinTable(final JoinType joinType,
             final GroupSymbol joinGroupfinal GroupSymbol entityGroupList<StringpkColumns,
             List<StringrefColumns) {
 
         List<CriteriacritList = new ArrayList<Criteria>();
 
         for (int i = 0; i < refColumns.size(); i++) {
             critList.add(new CompareCriteria(new ElementSymbol(pkColumns.get(i), entityGroup), .new ElementSymbol(refColumns.get(i), joinGroup)));
         }
 
         Criteria crit = critList.get(0);
         for (int i = 1; i < critList.size(); i++) {
             crit = new CompoundCriteria(.critcritList.get(i));
         }
         return new JoinPredicate(this.new UnaryFromClause(joinGroup), joinTypecrit);
     }
 
     static List<StringgetColumnNames(List<Columncolumns){
         ArrayList<StringcolumnNames = new ArrayList<String>();
         for (Column column:columns) {
             columnNames.add(column.getName());
         }
         return columnNames;
     }
 
     @Override
     public void visit(UriResourcePrimitiveProperty info) {
         String propertyName = info.getProperty().getName();
         ElementSymbol es = new ElementSymbol(propertyNamethis.);
         addVisibleColumn(propertyNameesthis.);
         
         this. = new ItResource(esthis.);
         this. = true;
     }
     
     public String getNextToken() {
         return ;
     }
     
     @Override
     public void visit(SkipTokenOption option) {
         if (option != null) {
             this. = option.getValue();
         }
     }
     
     @Override
     public void visit(SearchOption option) {
     }
     
     public Insert insert(EdmEntityType entityTypeEntity entityboolean prepared) {
         Table entityTable = findTable(entityType.getName(), this.);
         this. = entityTable;
         this. = entityType;
         this. = new GroupSymbol(entityTable.getFullName());
         
         List<ReferencereferenceValues = new ArrayList<Reference>();
         List<ConstantconstantValues = new ArrayList<Constant>();
         Insert insert = new Insert();
         insert.setGroup(this.);
         
         int i = 0;
         for (Property prop : entity.getProperties()) {
             EdmProperty edmProp = (EdmProperty)entityType.getProperty(prop.getName());
             Column column = entityTable.getColumnByName(edmProp.getName());
             insert.addVariable(new ElementSymbol(column.getName(), this.));
             
             if (prepared) {
                 referenceValues.add(new Reference(i++));
                 this..add(asParam(edmPropprop.getValue()));
             }
             else {
                 constantValues.add(new Constant(asParam(edmPropprop.getValue()).getValue()));
             }
         }
         
         if (prepared) {
             insert.setValues(referenceValues);
         }
         else {
             insert.setValues(constantValues);
         }
         return insert;
     }
     
     static SQLParameter asParam(EdmProperty edmPropObject value) {
         String teiidType = ODataTypeManager.teiidType((SingletonPrimitiveType)edmProp.getType(), edmProp.isCollection());
         int sqlType = JDBCSQLTypeInfo.getSQLType(teiidType);
         if (value == null) {
             return new SQLParameter(nullsqlType);
         }
         return new SQLParameter(ODataTypeManager.convertToTeiidRuntimeType(DataTypeManager.getDataTypeClass(teiidType), value), sqlType);
     }    
     
     private Table findTable(String tableNameMetadataStore store) {
         int idx = tableName.indexOf('.');
         if (idx > 0) {
             Schema s = store.getSchema(tableName.substring(0, idx));
             if (s != null) {
                 Table t = s.getTable(tableName.substring(idx+1));
                 if (t != null) {
                     return t;
                 }
             }
         }
         for (Schema s : store.getSchemaList()) {
             Table t = s.getTables().get(tableName);
             if (t != null) {
                 return t;
             }
         }        
         return null;
     }
     //TODO: allow the generated key building.
     public Query  selectWithEntityKey(EdmEntityType entityTypeEntity entityMap<StringObjectgeneratedKeys) {
         Table table = findTable(entityType.getName(), this.);
         GroupSymbol tableGroup = new GroupSymbol(table.getFullName());
         
         addAllColumns(tabletableGroupentityType);
         
         Select select = new Select();
         int ordinal = 1;
         for (ProjectedColumn pc : getProjectedColumns(entityType)) {
             select.addSymbol(pc.getExpression());
             pc.setOrdinal(ordinal++);
         }
 
         Query query = new Query();
         From from = new From();
         from.addClause(new UnaryFromClause(tableGroup));
         query.setSelect(select);
         query.setFrom(from);
     
         Criteria criteria = null;
         KeyRecord pk = table.getPrimaryKey();
         for (Column c:pk.getColumns()) {
             Property prop = entity.getProperty(c.getName());
             Constant right = null;
             if (prop != null) {
                 right = new Constant(ODataTypeManager.convertToTeiidRuntimeType(c.getJavaType(), prop.getValue()));
             } else {
                 Object value = generatedKeys.get(c.getName());
                 if (value == null) {
                     // I observed with mysql did not return the label for column, 
                     // this may be workaround in single key case in compound case 
                     // we got to error.
                     if (pk.getColumns().size() == 1 && generatedKeys.size() == 1) {
                         value = generatedKeys.values().iterator().next();
                     }                    
                     if (value == null) {
                         throw new TeiidRuntimeException(..gs(..entityType.getName()));
                     }
                 }
                 right = new Constant(value);
             }
             ElementSymbol left = new ElementSymbol(c.getName(), tableGroup);
             if (criteria == null) {
                 criteria = new CompareCriteria(left,.right);
             }
             else {
                 CompareCriteria rightCC = new CompareCriteria(left,.right);
                 criteria = new CompoundCriteria(.criteriarightCC);
             }
         }
         query.setCriteria(criteria);
         return query;
     }
     
     public Update update(EdmEntityType entityTypeEntity entityboolean prepared) {
         Update update = new Update();
         update.setGroup(this.);
         
         int i = 0;
         for (Property property : entity.getProperties()) {
             EdmProperty edmProperty = (EdmProperty)entityType.getProperty(property.getName());
             Column column = this..getColumnByName(edmProperty.getName());
             ElementSymbol symbol = new ElementSymbol(column.getName(), this.);
             boolean add = true;
             for (Column c : this..getPrimaryKey().getColumns()) {
                 if (c.getName().equals(column.getName())) {
                     add = false;
                     break;
                 }
             }
             if (add) {
                 if (prepared) {
                     update.addChange(symbolnew Reference(i++));
                     this..add(asParam(edmPropertyproperty.getValue()));
                 }
                 else {
                     update.addChange(symbolnew Constant(asParam(edmPropertyproperty.getValue()).getValue()));
                 }
             }
         }
         update.setCriteria(this.);
         return update;
     }
     
     public Update updateProperty(EdmProperty