cristof commented on code in PR #144: URL: https://github.com/apache/openjpa/pull/144#discussion_r3687188286
########## openjpa-kernel/src/main/java/org/apache/openjpa/kernel/exps/Left.java: ########## @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.openjpa.kernel.exps; + +import org.apache.openjpa.kernel.StoreContext; + +/** + * Take the left part of a string. + * + * @author Abe White + * @author Paulo Cristovão Filho + */ +class Left + extends Val { + + + private static final long serialVersionUID = 1L; + private final Val _val; + private final Val _len; + + /** + * Constructor. Provide substring and length of the left part that must be kept. + */ + public Left(Val val, Val len) { + _val = val; + _len = len; + } + + @Override + public Class getType() { + return String.class; + } + + @Override + public void setImplicitType(Class type) { + } + + @Override + protected Object eval(Object candidate, Object orig, StoreContext ctx, Object[] params) { + Object str = _val.eval(candidate, orig, ctx, params); + Object arg = _len.eval(candidate, orig, ctx, params); + return str.toString().substring(0, ((Number) arg).intValue()); Review Comment: Fixed both Left and Right in-memory, mimicking postgresql behavior when using negative number. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
