Skip to content

Commit f526e62

Browse files
authored
Merge pull request #37 from lucee/refactor-ortus-pr
cherry pick java changes from ortus pr
2 parents 7dfa394 + 5280e1f commit f526e62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2693
-662
lines changed

source/java/src/org/lucee/extension/orm/hibernate/ColumnInfo.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public String getName() {
2525
}
2626

2727
/**
28-
* @param name the name to set
28+
* @param name
29+
* the name to set
2930
*/
3031
public void setName(String name) {
3132
this.name = name;
@@ -39,7 +40,8 @@ public int getType() {
3940
}
4041

4142
/**
42-
* @param type the type to set
43+
* @param type
44+
* the type to set
4345
*/
4446
public void setType(int type) {
4547
this.type = type;
@@ -53,7 +55,8 @@ public String getTypeName() {
5355
}
5456

5557
/**
56-
* @param typeName the typeName to set
58+
* @param typeName
59+
* the typeName to set
5760
*/
5861
public void setTypeName(String typeName) {
5962
this.typeName = typeName;
@@ -67,7 +70,8 @@ public int getSize() {
6770
}
6871

6972
/**
70-
* @param size the size to set
73+
* @param size
74+
* the size to set
7175
*/
7276
public void setSize(int size) {
7377
this.size = size;
@@ -81,7 +85,8 @@ public boolean isNullable() {
8185
}
8286

8387
/**
84-
* @param nullable the nullable to set
88+
* @param nullable
89+
* the nullable to set
8590
*/
8691
public void setNullable(boolean nullable) {
8792
this.nullable = nullable;

source/java/src/org/lucee/extension/orm/hibernate/CommonUtil.java

Lines changed: 122 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
import java.io.Writer;
1414
import java.lang.reflect.Method;
1515
import java.math.BigDecimal;
16+
import java.util.Date;
1617
import java.nio.charset.Charset;
1718
import java.sql.ResultSet;
19+
import java.sql.Clob;
20+
import java.util.Map;
1821
import java.util.ArrayList;
1922
import java.util.Calendar;
2023
import java.util.Iterator;
@@ -49,12 +52,15 @@
4952
import lucee.runtime.type.Struct;
5053
import lucee.runtime.type.dt.DateTime;
5154
import lucee.runtime.type.scope.Argument;
55+
import lucee.runtime.ext.function.Function;
5256
import lucee.runtime.util.Cast;
5357
import lucee.runtime.util.Creation;
5458
import lucee.runtime.util.DBUtil;
5559
import lucee.runtime.util.Decision;
5660
import lucee.runtime.util.ORMUtil;
5761
import lucee.runtime.util.Operation;
62+
import lucee.runtime.op.Castable;
63+
import lucee.runtime.type.ObjectWrap;
5864

5965
public class CommonUtil {
6066

@@ -228,7 +234,9 @@ public static String toString(long l) {
228234
*
229235
* @param file
230236
* @param charset
237+
*
231238
* @return readed string
239+
*
232240
* @throws IOException
233241
*/
234242
public static String toString(Resource file, Charset charset) throws IOException {
@@ -511,6 +519,68 @@ public static boolean isStruct(Object obj) {
511519
return decision().isStruct(obj);
512520
}
513521

522+
/**
523+
* See if a given value is coercable to a string.
524+
* <p>
525+
* Blatantly copied from Lucee core because it's not in the Lucee loader, so we don't have access to run it without
526+
* reflection.
527+
*
528+
* @link https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/lucee/runtime/op/Decision.java#L964
529+
*
530+
* @param o
531+
* Value to compare
532+
*
533+
* @return Boolean, true if value is a String or castable to a String.
534+
*/
535+
public static boolean isString(Object o) {
536+
if (o instanceof String)
537+
return true;
538+
else if (o instanceof Boolean)
539+
return true;
540+
else if (o instanceof Number)
541+
return true;
542+
else if (o instanceof Date)
543+
return true;
544+
else if (o instanceof Castable) {
545+
return ((Castable) o).castToString("this is a unique string") != "this is a unique string";
546+
547+
} else if (o instanceof Clob)
548+
return true;
549+
else if (o instanceof Node)
550+
return true;
551+
else if (o instanceof Map || o instanceof List || o instanceof Function)
552+
return false;
553+
else if (o == null)
554+
return true;
555+
else if (o instanceof ObjectWrap)
556+
return isString(((ObjectWrap) o).getEmbededObject(""));
557+
return true;
558+
}
559+
560+
public static boolean isSimpleValue(Object obj) {
561+
return decision().isSimpleValue(obj);
562+
}
563+
564+
public static boolean isCastableToBoolean(Object obj) {
565+
return decision().isCastableToBoolean(obj);
566+
}
567+
568+
public static boolean isCastableToArray(Object o) {
569+
return decision().isCastableToArray(o);
570+
}
571+
572+
public static boolean isCastableToStruct(Object o) {
573+
return decision().isCastableToStruct(o);
574+
}
575+
576+
public static boolean isBinary(Object obj) {
577+
return decision().isBinary(obj);
578+
}
579+
580+
public static boolean isBoolean(Object obj) {
581+
return decision().isBoolean(obj);
582+
}
583+
514584
public static boolean isAnyType(String type) {
515585
return decision().isAnyType(type);
516586
}
@@ -612,7 +682,8 @@ static class SQLImpl implements SQL {
612682
/**
613683
* Constructor only with SQL String
614684
*
615-
* @param strSQL SQL String
685+
* @param strSQL
686+
* SQL String
616687
*/
617688
public SQLImpl(String strSQL) {
618689
this.strSQL = strSQL;
@@ -704,24 +775,23 @@ public String toString() {
704775
}
705776
}
706777

707-
public static DataSource getDataSource(PageContext pc, String dsn, DataSource defaultValue) {
708-
if (Util.isEmpty(dsn, true) || dsn.equals("__default__")) return orm().getDefaultDataSource(pc, defaultValue);
709-
return pc.getDataSource(dsn.trim(), defaultValue);
710-
}
711-
778+
/**
779+
* Get the datasource defined for the provided name, or the default if name is null.
780+
*
781+
* @param pc
782+
* Lucee's PageContext object.
783+
* @param name
784+
* Datasource name, or <code>null</code> to retrieve the default
785+
*
786+
* @return A Datasource object
787+
*
788+
* @throws PageException
789+
*/
712790
public static DataSource getDataSource(PageContext pc, String name) throws PageException {
713791
if (Util.isEmpty(name, true)) return orm().getDefaultDataSource(pc);
714792
return pc.getDataSource(name);
715793
}
716794

717-
/*
718-
* private static Object getDatasourceManager(PageContext pc) throws PageException { try { if
719-
* (mGetDataSourceManager == null || pc.getClass() != mGetDataSourceManager.getDeclaringClass())
720-
* mGetDataSourceManager = pc.getClass().getMethod("getDataSourceManager", ZEROC); return
721-
* mGetDataSourceManager.invoke(pc, ZEROO); } catch (Exception e) { throw
722-
* CFMLEngineFactory.getInstance().getCastUtil().toPageException(e); } }
723-
*/
724-
725795
public static DatasourceConnection getDatasourceConnection(PageContext pc, DataSource ds, String user, String pass, boolean transactionSensitive) throws PageException {
726796
if (transactionSensitive) {
727797
return pc.getDataSourceManager().getConnection(pc, ds, user, pass);
@@ -793,14 +863,6 @@ public static String[] trimItems(String[] arr) {
793863
return arr;
794864
}
795865

796-
public static Document getDocument(Node node) {
797-
return XMLUtil.getDocument(node);
798-
}
799-
800-
public static Document newDocument() throws PageException {
801-
return XMLUtil.newDocument();
802-
}
803-
804866
public static void setFirst(Node parent, Node node) {
805867
XMLUtil.setFirst(parent, node);
806868
}
@@ -935,8 +997,8 @@ public static Object getPropertyValue(Component cfc, String name, Object default
935997
return orm().getPropertyValue(cfc, name, defaultValue);
936998
}
937999

938-
public static String toString(Node node, boolean omitXMLDecl, boolean indent, String publicId, String systemId, String encoding) throws PageException {
939-
return XMLUtil.toString(node, omitXMLDecl, indent, publicId, systemId, encoding);
1000+
public static String toBase64(Object o) throws PageException {
1001+
return caster().toBase64(o);
9401002
}
9411003

9421004
public static Locale toLocale(String strLocale) throws PageException {
@@ -958,4 +1020,40 @@ public static DateTime toDate(Object value, TimeZone timeZone) throws PageExcept
9581020
public static Calendar toCalendar(DateTime date, TimeZone timeZone, Locale locale) {
9591021
return caster().toCalendar(date.getTime(), timeZone, locale);
9601022
}
1023+
1024+
/**
1025+
* Tests if this string starts with the specified prefix.
1026+
* <p>
1027+
* Blatantly copied from the Lucee core, since we don't have access to this method without reflection.
1028+
*
1029+
* @link https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/lucee/commons/lang/StringUtil.java#L870
1030+
*
1031+
* @param str
1032+
* string to check first char
1033+
* @param prefix
1034+
* the prefix.
1035+
*
1036+
* @return is first of given type
1037+
*/
1038+
public static boolean startsWith(String str, char prefix) {
1039+
return str != null && str.length() > 0 && str.charAt(0) == prefix;
1040+
}
1041+
1042+
/**
1043+
* Tests if this string ends with the specified suffix.
1044+
* <p>
1045+
* Blatantly copied from the Lucee core, since we don't have access to this method without reflection.
1046+
*
1047+
* @link https://github.com/lucee/Lucee/blob/6.0/core/src/main/java/lucee/commons/lang/StringUtil.java#L870
1048+
*
1049+
* @param str
1050+
* string to check first char
1051+
* @param suffix
1052+
* the suffix.
1053+
*
1054+
* @return is last of given type
1055+
*/
1056+
public static boolean endsWith(String str, char suffix) {
1057+
return str != null && str.length() > 0 && str.charAt(str.length() - 1) == suffix;
1058+
}
9611059
}

0 commit comments

Comments
 (0)