Skip to content

Commit

Permalink
cherry pick ortus changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Jun 3, 2023
1 parent bff3660 commit 815f1e8
Show file tree
Hide file tree
Showing 18 changed files with 1,914 additions and 621 deletions.
15 changes: 10 additions & 5 deletions source/java/src/org/lucee/extension/orm/hibernate/ColumnInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public String getName() {
}

/**
* @param name the name to set
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
Expand All @@ -39,7 +40,8 @@ public int getType() {
}

/**
* @param type the type to set
* @param type
* the type to set
*/
public void setType(int type) {
this.type = type;
Expand All @@ -53,7 +55,8 @@ public String getTypeName() {
}

/**
* @param typeName the typeName to set
* @param typeName
* the typeName to set
*/
public void setTypeName(String typeName) {
this.typeName = typeName;
Expand All @@ -67,7 +70,8 @@ public int getSize() {
}

/**
* @param size the size to set
* @param size
* the size to set
*/
public void setSize(int size) {
this.size = size;
Expand All @@ -81,7 +85,8 @@ public boolean isNullable() {
}

/**
* @param nullable the nullable to set
* @param nullable
* the nullable to set
*/
public void setNullable(boolean nullable) {
this.nullable = nullable;
Expand Down
146 changes: 122 additions & 24 deletions source/java/src/org/lucee/extension/orm/hibernate/CommonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
import java.io.Writer;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.Date;
import java.nio.charset.Charset;
import java.sql.ResultSet;
import java.sql.Clob;
import java.util.Map;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
Expand Down Expand Up @@ -49,12 +52,15 @@
import lucee.runtime.type.Struct;
import lucee.runtime.type.dt.DateTime;
import lucee.runtime.type.scope.Argument;
import lucee.runtime.ext.function.Function;
import lucee.runtime.util.Cast;
import lucee.runtime.util.Creation;
import lucee.runtime.util.DBUtil;
import lucee.runtime.util.Decision;
import lucee.runtime.util.ORMUtil;
import lucee.runtime.util.Operation;
import lucee.runtime.op.Castable;
import lucee.runtime.type.ObjectWrap;

public class CommonUtil {

Expand Down Expand Up @@ -228,7 +234,9 @@ public static String toString(long l) {
*
* @param file
* @param charset
*
* @return readed string
*
* @throws IOException
*/
public static String toString(Resource file, Charset charset) throws IOException {
Expand Down Expand Up @@ -511,6 +519,68 @@ public static boolean isStruct(Object obj) {
return decision().isStruct(obj);
}

/**
* See if a given value is coercable to a string.
* <p>
* Blatantly copied from Lucee core because it's not in the Lucee loader, so we don't have access to run it without
* reflection.
*
* @link https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/lucee/runtime/op/Decision.java#L964
*
* @param o
* Value to compare
*
* @return Boolean, true if value is a String or castable to a String.
*/
public static boolean isString(Object o) {
if (o instanceof String)
return true;
else if (o instanceof Boolean)
return true;
else if (o instanceof Number)
return true;
else if (o instanceof Date)
return true;
else if (o instanceof Castable) {
return ((Castable) o).castToString("this is a unique string") != "this is a unique string";

} else if (o instanceof Clob)
return true;
else if (o instanceof Node)
return true;
else if (o instanceof Map || o instanceof List || o instanceof Function)
return false;
else if (o == null)
return true;
else if (o instanceof ObjectWrap)
return isString(((ObjectWrap) o).getEmbededObject(""));
return true;
}

public static boolean isSimpleValue(Object obj) {
return decision().isSimpleValue(obj);
}

public static boolean isCastableToBoolean(Object obj) {
return decision().isCastableToBoolean(obj);
}

public static boolean isCastableToArray(Object o) {
return decision().isCastableToArray(o);
}

public static boolean isCastableToStruct(Object o) {
return decision().isCastableToStruct(o);
}

public static boolean isBinary(Object obj) {
return decision().isBinary(obj);
}

public static boolean isBoolean(Object obj) {
return decision().isBoolean(obj);
}

public static boolean isAnyType(String type) {
return decision().isAnyType(type);
}
Expand Down Expand Up @@ -612,7 +682,8 @@ static class SQLImpl implements SQL {
/**
* Constructor only with SQL String
*
* @param strSQL SQL String
* @param strSQL
* SQL String
*/
public SQLImpl(String strSQL) {
this.strSQL = strSQL;
Expand Down Expand Up @@ -704,24 +775,23 @@ public String toString() {
}
}

public static DataSource getDataSource(PageContext pc, String dsn, DataSource defaultValue) {
if (Util.isEmpty(dsn, true) || dsn.equals("__default__")) return orm().getDefaultDataSource(pc, defaultValue);
return pc.getDataSource(dsn.trim(), defaultValue);
}

/**
* Get the datasource defined for the provided name, or the default if name is null.
*
* @param pc
* Lucee's PageContext object.
* @param name
* Datasource name, or <code>null</code> to retrieve the default
*
* @return A Datasource object
*
* @throws PageException
*/
public static DataSource getDataSource(PageContext pc, String name) throws PageException {
if (Util.isEmpty(name, true)) return orm().getDefaultDataSource(pc);
return pc.getDataSource(name);
}

/*
* private static Object getDatasourceManager(PageContext pc) throws PageException { try { if
* (mGetDataSourceManager == null || pc.getClass() != mGetDataSourceManager.getDeclaringClass())
* mGetDataSourceManager = pc.getClass().getMethod("getDataSourceManager", ZEROC); return
* mGetDataSourceManager.invoke(pc, ZEROO); } catch (Exception e) { throw
* CFMLEngineFactory.getInstance().getCastUtil().toPageException(e); } }
*/

public static DatasourceConnection getDatasourceConnection(PageContext pc, DataSource ds, String user, String pass, boolean transactionSensitive) throws PageException {
if (transactionSensitive) {
return pc.getDataSourceManager().getConnection(pc, ds, user, pass);
Expand Down Expand Up @@ -793,14 +863,6 @@ public static String[] trimItems(String[] arr) {
return arr;
}

public static Document getDocument(Node node) {
return XMLUtil.getDocument(node);
}

public static Document newDocument() throws PageException {
return XMLUtil.newDocument();
}

public static void setFirst(Node parent, Node node) {
XMLUtil.setFirst(parent, node);
}
Expand Down Expand Up @@ -935,8 +997,8 @@ public static Object getPropertyValue(Component cfc, String name, Object default
return orm().getPropertyValue(cfc, name, defaultValue);
}

public static String toString(Node node, boolean omitXMLDecl, boolean indent, String publicId, String systemId, String encoding) throws PageException {
return XMLUtil.toString(node, omitXMLDecl, indent, publicId, systemId, encoding);
public static String toBase64(Object o) throws PageException {
return caster().toBase64(o);
}

public static Locale toLocale(String strLocale) throws PageException {
Expand All @@ -958,4 +1020,40 @@ public static DateTime toDate(Object value, TimeZone timeZone) throws PageExcept
public static Calendar toCalendar(DateTime date, TimeZone timeZone, Locale locale) {
return caster().toCalendar(date.getTime(), timeZone, locale);
}

/**
* Tests if this string starts with the specified prefix.
* <p>
* Blatantly copied from the Lucee core, since we don't have access to this method without reflection.
*
* @link https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/lucee/commons/lang/StringUtil.java#L870
*
* @param str
* string to check first char
* @param prefix
* the prefix.
*
* @return is first of given type
*/
public static boolean startsWith(String str, char prefix) {
return str != null && str.length() > 0 && str.charAt(0) == prefix;
}

/**
* Tests if this string ends with the specified suffix.
* <p>
* Blatantly copied from the Lucee core, since we don't have access to this method without reflection.
*
* @link https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/lucee/commons/lang/StringUtil.java#L870
*
* @param str
* string to check first char
* @param suffix
* the suffix.
*
* @return is last of given type
*/
public static boolean endsWith(String str, char suffix) {
return str != null && str.length() > 0 && str.charAt(str.length() - 1) == suffix;
}
}
Loading

0 comments on commit 815f1e8

Please sign in to comment.