diff --git a/core/src/main/java/lucee/runtime/type/QueryImpl.java b/core/src/main/java/lucee/runtime/type/QueryImpl.java index c31cd74a96..e6fcbd9d74 100755 --- a/core/src/main/java/lucee/runtime/type/QueryImpl.java +++ b/core/src/main/java/lucee/runtime/type/QueryImpl.java @@ -1153,13 +1153,14 @@ public Object getAt(Collection.Key key, int row) throws PageException { } @Override - public synchronized int removeRow(int row) throws PageException { + public int removeRow(int row) throws PageException { // disconnectCache(); - - for (int i = 0; i < columns.length; i++) { - columns[i].removeRow(row); + synchronized (this){ + for (int i = 0; i < columns.length; i++) { + columns[i].removeRow(row); + } + return recordcount.decrementAndGet(); } - return recordcount.decrementAndGet(); } @Override @@ -1200,30 +1201,31 @@ public QueryColumn removeColumnEL(String key) { } @Override - public synchronized QueryColumn removeColumnEL(Collection.Key key) { + public QueryColumn removeColumnEL(Collection.Key key) { // TODO should in that case not all method accessing columnNames,columns been locked down? - - int index = getIndexFromKey(key); - if (index != -1) { - int current = 0; - QueryColumn removed = null; - Collection.Key[] newColumnNames = new Collection.Key[columnNames.length - 1]; - QueryColumnImpl[] newColumns = new QueryColumnImpl[columns.length - 1]; - for (int i = 0; i < columns.length; i++) { - if (i == index) { - removed = columns[i]; - } - else { - newColumnNames[current] = columnNames[i]; - newColumns[current++] = columns[i]; + synchronized (this){ + int index = getIndexFromKey(key); + if (index != -1) { + int current = 0; + QueryColumn removed = null; + Collection.Key[] newColumnNames = new Collection.Key[columnNames.length - 1]; + QueryColumnImpl[] newColumns = new QueryColumnImpl[columns.length - 1]; + for (int i = 0; i < columns.length; i++) { + if (i == index) { + removed = columns[i]; + } + else { + newColumnNames[current] = columnNames[i]; + newColumns[current++] = columns[i]; + } } + columnNames = newColumnNames; + columns = newColumns; + columncount--; + return removed; } - columnNames = newColumnNames; - columns = newColumns; - columncount--; - return removed; + return null; } - return null; } @Override @@ -1395,15 +1397,19 @@ public void sort(Collection.Key column) throws PageException { * @throws PageException */ @Override - public synchronized void sort(String strColumn, int order) throws PageException { + public void sort(String strColumn, int order) throws PageException { // disconnectCache(); - sort(getColumn(strColumn), order); + synchronized (this) { + sort(getColumn(strColumn), order); + } } @Override - public synchronized void sort(Collection.Key keyColumn, int order) throws PageException { + public void sort(Collection.Key keyColumn, int order) throws PageException { // disconnectCache(); - sort(getColumn(keyColumn), order); + synchronized (this) { + sort(getColumn(keyColumn), order); + } } public void sort(int[] rows) throws PageException { @@ -1464,8 +1470,10 @@ public boolean addColumn(Collection.Key columnName, Array content) throws PageEx } @Override - public synchronized boolean addColumn(String columnName, Array content, int type) throws DatabaseException { - return addColumn(KeyImpl.init(columnName.trim()), content, type); + public boolean addColumn(String columnName, Array content, int type) throws DatabaseException { + synchronized (this) { + return addColumn(KeyImpl.init(columnName.trim()), content, type); + } } @Override @@ -1520,22 +1528,25 @@ public Collection duplicate(boolean deepCopy) { } @Override - public synchronized int[] getTypes() { - int[] types = new int[columns.length]; - for (int i = 0; i < columns.length; i++) { - types[i] = columns[i].getType(); + public int[] getTypes() { + synchronized (this){ + int[] types = new int[columns.length]; + for (int i = 0; i < columns.length; i++) { + types[i] = columns[i].getType(); + } + return types; } - return types; } @Override - public synchronized Map getTypesAsMap() { - - Map map = new HashMap(); - for (int i = 0; i < columns.length; i++) { - map.put(columnNames[i], columns[i].getTypeAsString()); + public Map getTypesAsMap() { + synchronized (this){ + Map map = new HashMap(); + for (int i = 0; i < columns.length; i++) { + map.put(columnNames[i], columns[i].getTypeAsString()); + } + return map; } - return map; } @Override @@ -1565,13 +1576,15 @@ private void renameEL(Collection.Key src, Collection.Key trg) { } @Override - public synchronized void rename(Collection.Key columnName, Collection.Key newColumnName) throws ExpressionException { - int index = getIndexFromKey(columnName); - if (index == -1) { - throw new ExpressionException("Cannot rename Column [" + columnName.getString() + "] to [" + newColumnName.getString() + "], original column doesn't exist"); + public void rename(Collection.Key columnName, Collection.Key newColumnName) throws ExpressionException { + synchronized (this){ + int index = getIndexFromKey(columnName); + if (index == -1) { + throw new ExpressionException("Cannot rename Column [" + columnName.getString() + "] to [" + newColumnName.getString() + "], original column doesn't exist"); + } + columnNames[index] = newColumnName; + columns[index].setKey(newColumnName); } - columnNames[index] = newColumnName; - columns[index].setKey(newColumnName); } @Override @@ -1751,18 +1764,19 @@ public void setExecutionTime(long exeTime) { * @param maxrows * @return has cutted or not */ - public synchronized boolean cutRowsTo(int maxrows) { + public boolean cutRowsTo(int maxrows) { // disconnectCache(); - - if (maxrows > -1 && maxrows < getRecordcount()) { - for (int i = 0; i < columns.length; i++) { - QueryColumn column = columns[i]; - column.cutRowsTo(maxrows); + synchronized (this){ + if (maxrows > -1 && maxrows < getRecordcount()) { + for (int i = 0; i < columns.length; i++) { + QueryColumn column = columns[i]; + column.cutRowsTo(maxrows); + } + recordcount.set(maxrows); + return true; } - recordcount.set(maxrows); - return true; + return false; } - return false; } @Override @@ -1973,17 +1987,19 @@ public int compareTo(String str) throws PageException { } @Override - public synchronized Array getMetaDataSimple() { - Array cols = new ArrayImpl(); - Struct column; - for (int i = 0; i < columns.length; i++) { - column = new StructImpl(); - column.setEL(KeyConstants._name, columnNames[i].getString()); - column.setEL("isCaseSensitive", Boolean.FALSE); - column.setEL("typeName", columns[i].getTypeAsString()); - cols.appendEL(column); + public Array getMetaDataSimple() { + synchronized (this){ + Array cols = new ArrayImpl(); + Struct column; + for (int i = 0; i < columns.length; i++) { + column = new StructImpl(); + column.setEL(KeyConstants._name, columnNames[i].getString()); + column.setEL("isCaseSensitive", Boolean.FALSE); + column.setEL("typeName", columns[i].getTypeAsString()); + cols.appendEL(column); + } + return cols; } - return cols; } /** @@ -3329,9 +3345,11 @@ private SQLException notSupported() { } @Override - public synchronized void enableShowQueryUsage() { - if (columns != null) for (int i = 0; i < columns.length; i++) { - columns[i] = columns[i]._toDebugColumn(); + public void enableShowQueryUsage() { + synchronized (this){ + if (columns != null) for (int i = 0; i < columns.length; i++) { + columns[i] = columns[i]._toDebugColumn(); + } } } diff --git a/core/src/main/java/lucee/runtime/type/query/SimpleQuery.java b/core/src/main/java/lucee/runtime/type/query/SimpleQuery.java index 0b6e54d444..e1154e8e35 100644 --- a/core/src/main/java/lucee/runtime/type/query/SimpleQuery.java +++ b/core/src/main/java/lucee/runtime/type/query/SimpleQuery.java @@ -437,33 +437,41 @@ public Object setAtEL(Key key, int row, Object value) { } @Override - public synchronized boolean next() { - try { - return next(getPid()); - } - catch (DatabaseException e) { - throw new PageRuntimeException(e); + public boolean next() { + synchronized (this){ + try { + return next(getPid()); + } + catch (DatabaseException e) { + throw new PageRuntimeException(e); + } } } @Override - public synchronized boolean next(int pid) throws DatabaseException { - throwIfClosed(); - if (recordcount >= (arrCurrentRow.set(pid, arrCurrentRow.get(pid, 0) + 1))) { - return true; + public boolean next(int pid) throws DatabaseException { + synchronized (this){ + throwIfClosed(); + if (recordcount >= (arrCurrentRow.set(pid, arrCurrentRow.get(pid, 0) + 1))) { + return true; + } + arrCurrentRow.set(pid, 0); + return false; } - arrCurrentRow.set(pid, 0); - return false; } @Override - public synchronized void reset() { - reset(getPid()); + public void reset() { + synchronized (this){ + reset(getPid()); + } } @Override - public synchronized void reset(int pid) { - arrCurrentRow.set(pid, 0); + public void reset(int pid) { + synchronized (this){ + arrCurrentRow.set(pid, 0); + } } @Override @@ -483,8 +491,10 @@ public boolean isEmpty() { @Override - public synchronized int getCurrentrow(int pid) { - return arrCurrentRow.get(pid, 1); + public int getCurrentrow(int pid) { + synchronized (this){ + return arrCurrentRow.get(pid, 1); + } } public String getColumnlist(boolean upperCase) { @@ -600,29 +610,33 @@ public QueryImpl cloneQuery(boolean deepCopy) { @Override - public synchronized int[] getTypes() { - if (_types == null) { - _types = new int[columns.size()]; - int i = 0; - Iterator> it = columns.entrySet().iterator(); - while (it.hasNext()) { - _types[i++] = it.next().getValue().getType(); + public int[] getTypes() { + synchronized (this){ + if (_types == null) { + _types = new int[columns.size()]; + int i = 0; + Iterator> it = columns.entrySet().iterator(); + while (it.hasNext()) { + _types[i++] = it.next().getValue().getType(); + } } + return _types; } - return _types; } @Override - public synchronized Map getTypesAsMap() { - Map map = new HashMap(); - Iterator it = columns.values().iterator(); - SimpleQueryColumn c; - while (it.hasNext()) { - c = it.next(); - map.put(c.getKey(), c.getTypeAsString()); + public Map getTypesAsMap() { + synchronized (this){ + Map map = new HashMap(); + Iterator it = columns.values().iterator(); + SimpleQueryColumn c; + while (it.hasNext()) { + c = it.next(); + map.put(c.getKey(), c.getTypeAsString()); + } + return map; } - return map; } @Override @@ -752,25 +766,27 @@ public String[] getColumnNamesAsString() { @Override - public synchronized String getData(int row, int col) throws IndexOutOfBoundsException { - try { - int rowBefore = res.getRow(); + public String getData(int row, int col) throws IndexOutOfBoundsException { + synchronized (this){ try { - res.absolute(row); - if (col < 1 || col > columnNames.length) { - new IndexOutOfBoundsException("invalid column index to retrieve Data from query, valid index goes from 1 to " + columnNames.length); - } - return Caster.toString(get(columnNames[col])); + int rowBefore = res.getRow(); + try { + res.absolute(row); + if (col < 1 || col > columnNames.length) { + new IndexOutOfBoundsException("invalid column index to retrieve Data from query, valid index goes from 1 to " + columnNames.length); + } + return Caster.toString(get(columnNames[col])); + } + finally { + res.absolute(rowBefore); + } } - finally { - res.absolute(rowBefore); + catch (Throwable t) { + ExceptionUtil.rethrowIfNecessary(t); + throw toRuntimeExc(t); } } - catch (Throwable t) { - ExceptionUtil.rethrowIfNecessary(t); - throw toRuntimeExc(t); - } } @Override @@ -876,20 +892,22 @@ public int compareTo(String str) throws PageException { } @Override - public synchronized lucee.runtime.type.Array getMetaDataSimple() { - lucee.runtime.type.Array cols = new ArrayImpl(); - SimpleQueryColumn sqc; - Struct column; - Iterator it = columns.values().iterator(); - while (it.hasNext()) { - sqc = it.next(); - column = new StructImpl(); - column.setEL(KeyConstants._name, sqc.getKey()); - column.setEL("isCaseSensitive", Boolean.FALSE); - column.setEL("typeName", sqc.getTypeAsString()); - cols.appendEL(column); + public lucee.runtime.type.Array getMetaDataSimple() { + synchronized (this){ + lucee.runtime.type.Array cols = new ArrayImpl(); + SimpleQueryColumn sqc; + Struct column; + Iterator it = columns.values().iterator(); + while (it.hasNext()) { + sqc = it.next(); + column = new StructImpl(); + column.setEL(KeyConstants._name, sqc.getKey()); + column.setEL("isCaseSensitive", Boolean.FALSE); + column.setEL("typeName", sqc.getTypeAsString()); + cols.appendEL(column); + } + return cols; } - return cols; } @Override @@ -977,49 +995,63 @@ public boolean wasNull() { @Override - public synchronized boolean absolute(int row) throws SQLException { - return res.absolute(row); + public boolean absolute(int row) throws SQLException { + synchronized (this){ + return res.absolute(row); + } } @Override - public synchronized void afterLast() throws SQLException { - res.afterLast(); + public void afterLast() throws SQLException { + synchronized (this){ + res.afterLast(); + } } @Override - public synchronized void beforeFirst() throws SQLException { - res.beforeFirst(); + public void beforeFirst() throws SQLException { + synchronized (this){ + res.beforeFirst(); + } } @Override - public synchronized void cancelRowUpdates() throws SQLException { - res.cancelRowUpdates(); + public void cancelRowUpdates() throws SQLException { + synchronized (this){ + res.cancelRowUpdates(); + } } @Override - public synchronized void clearWarnings() throws SQLException { - res.clearWarnings(); + public void clearWarnings() throws SQLException { + synchronized (this){ + res.clearWarnings(); + } } @Override - public synchronized void close() throws SQLException { - if (res != null && !res.isClosed()) { - res.close(); - } - if (stat != null && !stat.isClosed()) { - stat.close(); + public void close() throws SQLException { + synchronized (this){ + if (res != null && !res.isClosed()) { + res.close(); + } + if (stat != null && !stat.isClosed()) { + stat.close(); + } } } @Override - public synchronized void deleteRow() throws SQLException { - res.deleteRow(); + public void deleteRow() throws SQLException { + synchronized (this){ + res.deleteRow(); + } } @Override @@ -1030,8 +1062,10 @@ public int findColumn(String columnName) throws SQLException { @Override - public synchronized boolean first() throws SQLException { - return res.first(); + public boolean first() throws SQLException { + synchronized (this){ + return res.first(); + } } @Override diff --git a/loader/build.xml b/loader/build.xml index 2bb5426e67..d420a0e543 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index a95900bf42..1e9fa399d2 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.2.0.260-SNAPSHOT + 6.2.0.261-SNAPSHOT jar Lucee Loader Build