RingJavafor Ring

Function index

Every function and class method of the Ring library, generated from the source files, with the comment that documents it.

This page is generated from the comments in libraries/javalib/*.ring. Search it with the box at the top of the page. The functions that start with jv are internal and are not listed.

Core (functions.ring)#

FunctionDescription
jUseJDK(j_cHome)The folder of a JDK to use (before the first Java call). Without it: RINGJAVA_HOME, JAVA_HOME, then the java on the PATH
jOptions(j_aOptions)Options of the JVM (before the first Java call): jOptions(["-Xmx1g","-Djava.awt.headless=true"])
jStart()Start the JVM now (it starts by itself at the first Java call)
jStarted()true when the JVM is running
jInfo()[the Java home, the JVM library, the bridge jar] that are in use
jVersion()The version of Java: "25.0.5.1"
jProperty(j_cName)A system property of Java: jProperty("java.home")
jClasspath(j_cPath)Add a jar, a folder of jars or a folder of classes to the class path of the program
jHandles()Number of Java objects that the bridge holds for the program (it falls when Ring objects are dropped)
jGC()Run the garbage collector of Java and release the Java objects that Ring dropped
jFinish(j_xAnswer)The answer of the extension as Ring values: a Java object comes as [C_JAVA_MARK, handle, class] and is wrapped in its Ring class
jWrap(j_aInfo)A Java object (handle and class) as a Ring object of the generated class of its Java class
jRegisterClass(j_cJava, j_cRing)Called by the generated files: the Java class and its Ring class
jImport(j_cPackage)Load the generated Ring classes of a Java package: jImport("java.util")
jImportFrom(j_cFolder, j_cPackage)Load the Ring classes made by tools/javatools for your own package: jImportFrom("myclasses/","com.mycompany.tools")
jFolderOf(j_cPath)The folder of a path, with the trailing /
jNew(j_cClass, j_aArgs)Make a Java object: jNew("java.util.ArrayList",[]) or jNew("java.lang.StringBuilder",["text"])
jStatic(j_cClass, j_cMethod, j_aArgs)Call a static method: jStatic("java.lang.Math","max",[3,9])
jCall(j_oObject, j_cMethod, j_aArgs)Call a method of an object: jCall(oObject,"add",["x"])
jParamNames(j_cClass, j_cMethod)The names of the parameters of every version of a method: jParamNames("java.util.ArrayList","add")
jGetStatic(j_cClass, j_cField)A static field: jGetStatic("java.lang.Math","PI")
jSetStatic(j_cClass, j_cField, j_xValue)Set a static field of a class: jSetStatic("pkg.Class","field",value)
jClass(j_cClass)A class: oMath = jClass("java.lang.Math") oMath.callStatic("max",[3,9]) oMath.getStatic("PI")
jExists(j_cClass)true when the Java class exists (on the class path)
jInstanceOf(j_oObject, j_cClass)true when the object is an instance of the Java class (or of a class that extends it or implements it)
jDescribe(j_cClass)The members of a Java class as a list of texts
jSupers(j_cClass)The super classes and interfaces of a Java class
jNull()The null reference
jIsNull(j_xValue)true for the null reference (and for the Java null that a method returned)
jArray(j_cType, j_xSizeOrItems)A Java array: jArray("int",5) (5 zeros), jArray("java.lang.String",["a","b"]) (with items)
jToList(j_oObject)The items of a Java array, a collection, an iterable, an iterator or a map (a list of [key, value]) as a Ring list
jBox(j_cClass, j_xValue)A value as an object of a Java class (the Java object, not a Ring number or text): jBox("java.lang.Long",5)
jInt(j_nValue)Values of a type that Ring has no word for (the matching of the arguments is by type, so a number is an int, a long or a double by its value): oList.remove(jInt(1)) Math.abs(jLong(5)) jChar("a") jFloat(1.5)
jLong(j_nValue)A typed value for an argument: a Java long (jLong(5)); the same for jShort, jByte, jFloat, jDouble, jChar, jBool
jShort(j_nValue)A Java short
jByte(j_nValue)A Java byte
jFloat(j_nValue)A Java float
jDouble(j_nValue)A Java double
jChar(j_xValue)A Java char (from a text of one character or a number)
jBool(j_xValue)A Java boolean
jBigInteger(j_xValue)A java.math.BigInteger from a text or a number
jBigDecimal(j_xValue)A java.math.BigDecimal from a text or a number
jCallback(j_cCode)Ring code that Java can run (an interface of Java is made from it): jCallback("myFunction") the function gets the list of the Java arguments and returns the result jCallback('xJavaResult = aJavaArgs[1] * 2') Ring code that reads aJavaArgs and cJavaMethod and sets xJavaResult jCallbackAll("name") also runs the default methods of the interface by the function.
jCallbackAll(j_cCode)Like jCallback, and the default methods of the interface also run the Ring function
jLastException()The last Java exception (an object), after a try/catch of the error
jDispatchCallback()Runs one Ring callback that Java asked for (called by the extension: a program does not call it). The request is [code, method name, arguments...]; the answer is what the function returns, or xJavaResult for Ring code.
jPump(j_nMillis)Java code that runs on its own threads (a Thread, an executor, a timer, a window) can call Ring callbacks only when the Ring program runs them: jPump(n) runs the callbacks that other threads asked for, and waits up to n milliseconds for one when none is waiting. It gives the number of callbacks that ran.
jSleep(j_nMillis)Wait n milliseconds and run the callbacks of other Java threads meanwhile (a Ring sleep that does not block callbacks)
jJoin(j_oThread)Wait for a Java thread to end, and run its callbacks meanwhile (the Thread.join of Java blocks the Ring program, so a thread that calls a Ring callback could never finish)
jWaitUntil(j_cFunction, j_nMillis)Wait until a Ring function returns true (it is called with no values), running the callbacks of other threads meanwhile. Gives false after n milliseconds when the function did not return true.
jCallbackTimeout(j_nMillis)How long (milliseconds) a Java thread waits for the Ring program to run a callback before it gets an error (30000 at the start)

JavaObject and friends (classes.ring)#

FunctionDescription
JavaObject.init(pHandle)(the parameter has another name: "this.nHandle = ..." would run Ring's property setter machinery)
JavaObject.isNull()true for the null reference
JavaObject.callMethod(cMethod, aParameters)Call a method by its name: oObject.callMethod("add", ["text"]). It works for every Java object and every overload (also the arities that the class has no Ring method for), also when no class was generated.
JavaObject.getField(cField)Read a public field
JavaObject.setField(cField, xValue)Write a public field
JavaObject.toString()toString() of the object
JavaObject.javaClassName()The name of the Java class of the object: "java.util.ArrayList" (the Ring function classname() is the name of the Ring class)
JavaObject.instanceOf(cClass)true when the object is an instance of the Java class or interface
JavaObject.equalsTo(oOther)equals() of Java: oObject.equalsTo(oOther)
JavaObject.hashCodeOf()hashCode() of Java
JavaObject.toList()Copy the items of an array, a collection, an iterable, an iterator or a map (a list of [key, value]) to a Ring list
JavaObject.construct(xParameters)The same as @New: oObject.construct([ 10 ])
JavaObject.item(nIndex)A Java array item (for an object that is an array): oArray.item(1) is the first item (Ring counts from 1)
JavaObject.setItem(nIndex, xValue)Set the item nIndex (from 1) of a Java list or array
JavaObject.arrayLength()The number of items of a Java array
JavaObject.javaRelease()Release the reference kept by the bridge now (the object is not used after this). Ring releases it by itself when the last variable that holds the object is gone (see oJavaGuard); this is only needed to let go of a big object at once.
JavaObject.jvReplace(nNewHandle)Use the handle of another object (the one that this object had is released)
JavaObject.jvConstruct(aRequest)Make the object with the constructor of the request ([class, values...]): the default object that the class body asked for is dropped first (when it was not made yet, it never is)
JavaObject.jvAttach(nNewHandle)Take the handle of a Java object that was just returned: this is what makes a copy of a prototype object (see jWrap) the Ring object of it (the guard is made inside a method of the object: Ring does not free a guard that is assigned from outside)
JavaOwned.init(pHandle)
JavaClass.init(pName)
JavaClass.callStatic(cMethod, aParameters)Call a static method: oMath.callStatic("max",[3,9])
JavaClass.getStatic(cField)Read a static field: oMath.getStatic("PI")
JavaClass.setStatic(cField, xValue)Write a static field
JavaClass.newInstance(aParameters)Make an object: oClass.newInstance([ "text" ])
JavaClass.describe()The members of the class as texts
JavaTyped.init(pType, pValue)
JavaCallback.init(pCode)

Queries (query.ring)#

FunctionDescription
jQuery(j_xSource)A query on xSource: a Ring list, a Java collection, array, stream, iterator or map (as [key, value] pairs), or another query
jRange(j_nFrom, j_nTo)The numbers from nFrom to nTo, as a Ring list (counts down when nTo is smaller): jQuery(jRange(1,10)).filter("x % 2 = 0").toList()
JavaValueSet.where(q_xValue)the position of the value in the set, or 0
JavaValueSet.add(q_xValue)put the value in the set when it is not there; the position of the value
JavaValueSet.has(q_xValue)
JavaValueSet.isNew(q_xValue)
JavaQuery.init(q_xSource)
JavaQuery.items()the items, in the order of sortBy / thenBy
JavaQuery.jvNew(q_aItems)
JavaQuery.filter(q_xCode)the items for which the code gives true
JavaQuery.map(q_xCode)the code applied to each item: the results are the new items
JavaQuery.flatMap(q_xCode)the code gives a list (or a Java collection) for each item: the lists are joined into one
JavaQuery.sortBy(q_xCode)sort by the value that the code gives for an item (stable: items with the same value keep their order)
JavaQuery.sortByDesc(q_xCode)sort by the value that the code gives, the largest first
JavaQuery.thenBy(q_xCode)after sortBy: items with the same value are sorted by another value
JavaQuery.thenByDesc(q_xCode)after sortBy: items with the same value are sorted by another value, the largest first
JavaQuery.jvThen(q_xCode, q_nDesc)
JavaQuery.sorted()the items in their natural order (numbers by value, texts like strcmp, objects with compareTo())
JavaQuery.reverse()the items in the opposite order
JavaQuery.limit(q_nCount)only the first nCount items
JavaQuery.skip(q_nCount)leave out the first nCount items
JavaQuery.takeWhile(q_xCode)the items from the start while the code gives true
JavaQuery.dropWhile(q_xCode)leave out the items from the start while the code gives true
JavaQuery.distinct()each value once (the first one stays)
JavaQuery.concat(q_xOther)the items followed by the items of another source (a query, a list or a Java collection)
JavaQuery.union(q_xOther)the values of both sources, each one once
JavaQuery.intersect(q_xOther)the values that both sources have (each one once, in the order of this source)
JavaQuery.except(q_xOther)the values of this source that the other source does not have (each one once)
JavaQuery.groupBy(q_xCode)the items in groups: a query of [key, [items...]] (the keys in the order of their first item)
JavaQuery.each(q_xCode)run the code for each item (a query is still returned)
JavaQuery.toList()the items as a Ring list
JavaQuery.toJava()the items as a Java ArrayList
JavaQuery.toMap(q_xKeyCode, q_xValueCode)the items as a list of [key, value] pairs: the code gives the key (and the second code the value: the item when it is missing)
JavaQuery.count()the number of items
JavaQuery.countWhere(q_xCode)the number of items for which the code gives true
JavaQuery.isEmpty()True when the query has no items
JavaQuery.anyMatch(q_xCode)true when the code gives true for at least one item
JavaQuery.allMatch(q_xCode)true when the code gives true for every item (also when there are none)
JavaQuery.noneMatch(q_xCode)true when the code gives true for no item
JavaQuery.contains(q_xValue)true when the source has the value
JavaQuery.first()the first item (an error when there is none)
JavaQuery.firstWhere(q_xCode)the first item for which the code gives true (an error when there is none)
JavaQuery.firstOr(q_xDefault)the first item, or the value when there is none
JavaQuery.last()the last item (an error when there is none)
JavaQuery.elementAt(q_nIndex)the item at the position nIndex (Ring counts from 1)
JavaQuery.jvSelected(q_xCode)the values that the code selects (the items themselves for ""), as a Ring list: used by sum, average, min and max
JavaQuery.sum(q_xCode)the sum of the selected values ("" for the items themselves)
JavaQuery.average(q_xCode)the average of the selected values (an error when there are none)
JavaQuery.min(q_xCode)the smallest of the selected values (numbers, texts, or objects with compareTo)
JavaQuery.max(q_xCode)the largest of the selected values
JavaQuery.reduce(q_xStart, q_xCode)fold the items into one value: the code gets the result so far (x) and the item (y): reduce(0,"x + y")
JavaQuery.join(q_cSeparator)the items as one text, with the separator between them (the objects with toString())

Windows and events (gui.ring)#

FunctionDescription
jGui()Make the calls of Ring to Java run on the event thread of Swing/AWT. jGuiMode(false) puts the usual mode back. The system look and feel is used (jGui() is called before the first window).
jGuiMode(j_lOn)jGuiMode(true) is jGui(); jGuiMode(false) puts the usual mode back
jMainLoop()Run the events of the windows (the Ring functions of the listeners) until the last window is closed or jStopLoop() is called
jStopLoop()End jMainLoop() (call it from an event function)
jInvokeLater(j_cCode)Run a Ring function (or Ring code) on the event thread later: jInvokeLater("myFunction")
jTimer(j_nMillis, j_cCode)A timer of Swing that calls a Ring function every n milliseconds: oTimer = jTimer(500,"tick") then oTimer.start() / oTimer.stop()
jMessage(j_cText, j_cTitle)A message box
jConfirm(j_cText, j_cTitle)A question with Yes and No: true for Yes
jInput(j_cText, j_cTitle)A box where the user types a text: the text, or "" when the box was cancelled
jColor(j_nRed, j_nGreen, j_nBlue)A colour: jColor(255,128,0)
jScreenSize()The size of the screen as [width, height]
jAutoClose()Close the windows after n milliseconds when the environment variable RINGJAVA_AUTOCLOSE is set (for the automatic runs of the samples): the sample calls jAutoClose() once before jMainLoop(). Without the variable nothing happens. When the program is started with the argument --selftest (or RINGJAVA_SELFTEST is set) and defines the function selfTest(), which returns a list of checks [ [name, actual, expected], ... ], the checks run here (the window is built, nothing is pumped yet), each one is printed as "ok" or "FAIL", then the program ends with status 0 (all passed) or 1.

Window builders and JCanvas (swing.ring)#

FunctionDescription
jWindow(j_cTitle, j_nWidth, j_nHeight)A window (JFrame) of the given size, centred, that closes itself (not the program) when the user closes it. A size of 0 leaves it to jPack().
jPack(j_oWindow)Fit the window to its contents and centre it
jShow(j_oWindow)Show the window
jLabel(j_cText)A label
jButton(j_cText, j_cHandler)A button; the handler is the name of a Ring function, or ""
jField(j_cText, j_nColumns, j_cHandler)A text field with the given number of columns (the handler runs on Enter)
jTextArea(j_cText, j_nRows, j_nColumns)A text area inside a scroll pane: oArea = jTextArea("",8,30) (the area is oScroll.getViewport().getView(), or use jTextAreaOf(oScroll))
jCheck(j_cText, j_lOn, j_cHandler)A check box (lOn: selected at the start); the handler runs when it changes
jCombo(j_aItems, j_cHandler)A drop-down list of texts (the handler runs when the choice changes)
jListBox(j_aItems)A list of texts: oList = jListBox(["a","b"]) ; oList.getSelectedValue() ; its model is oList.getModel()
jSlider(j_nMin, j_nMax, j_nValue, j_cHandler)A slider (the handler runs when the value changes)
jRow(j_aItems, j_nGap)The controls side by side, with a gap (in pixels) between them
jColumn(j_aItems, j_nGap)The controls one below the other (left aligned), with a gap between them
jGrid(j_nRows, j_nCols, j_aItems, j_nGap)A grid of equal cells: jGrid(2,3,[...6 controls...],4) ; rows or columns 0 mean "as many as needed"
jForm(j_aPairs, j_nGap)A form: a list of [label text, control] pairs in two columns
jBorder(j_oCenter, j_oNorth, j_oSouth, j_oWest, j_oEast)The five areas of a window: jBorder(center, north, south, west, east) (NULL or 0 for an area that is not used)
jPad(j_oItem, j_nSize)Space (in pixels) around a control
jTitled(j_oItem, j_cTitle)A control with a border and a title
jScroll(j_oItem)A control with scroll bars
jMenuBar(j_oWindow, j_aMenus)The window gets a menu bar: [["File",[["Open","onOpen","ctrl O"],"-",["Exit","onExit"]]],["Help",[["About","onAbout"]]]] An item is [text, handler, shortcut (optional)]; "-" is a separator.
jOpenFile(j_cTitle)A file chosen by the user to open: the path, or "" when the box was cancelled
jSaveFile(j_cTitle)A file chosen by the user to save: the path, or "" when the box was cancelled
jChooseColor(j_cTitle, j_xStart)A colour chosen by the user: a Java Color, or NULL when the box was cancelled
JCanvas.init(nW, nH)A drawing surface of nW x nH pixels, white, with a black pen
JCanvas.component()The Swing control that shows the picture
JCanvas.width()The width of the picture in pixels
JCanvas.height()The height of the picture in pixels
JCanvas.color(xColor)The colour of the next shapes
JCanvas.clear(xColor)Fill the whole surface with a colour (the drawing colour is not changed)
JCanvas.lineWidth(nWidthOfLine)The width of the lines
JCanvas.font(cName, nSize, lBold)The font of the next texts: oCanvas.font("SansSerif",18,true)
JCanvas.line(nX1, nY1, nX2, nY2)A line from (nX1,nY1) to (nX2,nY2)
JCanvas.rect(nX, nY, nW, nH)The outline of a rectangle
JCanvas.fillRect(nX, nY, nW, nH)A filled rectangle
JCanvas.oval(nX, nY, nW, nH)The outline of an oval in the rectangle
JCanvas.fillOval(nX, nY, nW, nH)A filled oval in the rectangle
JCanvas.arc(nX, nY, nW, nH, nStart, nSweep)The outline of an arc of the oval in the rectangle: the start angle in degrees (0 is at 3 o'clock, positive is counter-clockwise) and the sweep
JCanvas.fillArc(nX, nY, nW, nH, nStart, nSweep)A filled slice of the oval in the rectangle (a piece of a pie): the angles as in arc()
JCanvas.roundRect(nX, nY, nW, nH, nArc)The outline of a rectangle with round corners (nArc is the diameter of the corners)
JCanvas.fillRoundRect(nX, nY, nW, nH, nArc)A filled rectangle with round corners
JCanvas.polygon(aPoints)The outline of a polygon: a list of points [ [x1,y1], [x2,y2], ... ] (the last point is joined to the first one)
JCanvas.fillPolygon(aPoints)A filled polygon
JCanvas.polyline(aPoints)The lines that join the points one after the other (the last point is not joined to the first one)
JCanvas.textWidth(cText)The width of a text in pixels, in the current font
JCanvas.textHeight()The height of a line of text in pixels, in the current font
JCanvas.text(cText, nX, nY)A text with its base line at nY
JCanvas.pixel(nX, nY)The colour of a point as a number (0xRRGGBB)
JCanvas.setPixel(nX, nY, nRed, nGreen, nBlue)One pixel from its red, green and blue parts (0 to 255). For many pixels use setPixels(): every call into Java costs some microseconds
JCanvas.setPixels(nX, nY, nW, nH, cRgb)A rectangle of pixels in one call, from one text of 3 bytes for each pixel (char(red) + char(green) + char(blue)), row after row: for a picture that a formula makes (a fractal, a colour wheel). 70,000 pixels take about a millisecond, setPixel() for each pixel takes seconds
JCanvas.getPixels(nX, nY, nW, nH)A rectangle of pixels as one text of 3 bytes for each pixel (see setPixels)
JCanvas.loadImage(cFile)Load a picture file (png, jpg, gif, bmp) to draw with drawImage: oPicture = oCanvas.loadImage("wall.jpg")
JCanvas.drawImage(oPicture, nX, nY, nW, nH)Draw a loaded picture, scaled to the rectangle: oCanvas.drawImage(oPicture,x,y,width,height)
JCanvas.update()Show what has been drawn
JCanvas.save(cFile)Save the picture: oCanvas.save("picture.png") (the format is the extension: png, jpg, bmp, gif). An error when the picture could not be written
JCanvas.onPress(cHandler)Handlers of the mouse: a Ring function with the position in the picture, func onPress nX, nY
JCanvas.onRelease(cHandler)The Ring function cHandler(nX, nY) runs when a mouse button is released
JCanvas.onMove(cHandler)The Ring function cHandler(nX, nY) runs when the mouse moves
JCanvas.onDrag(cHandler)The Ring function cHandler(nX, nY) runs when the mouse moves with a button down
JCanvas.finish()Release the drawing resources (call it when the canvas is not used any more)

Charts (charts.ring)#

FunctionDescription
JChart.init(nW, nH)A chart of nW x nH pixels, white, without a title
JChart.title(cText)The title above the chart
JChart.axisTitles(cX, cY)The titles of the axes (bars, lines and scatter)
JChart.showValues(lShow)Write the value over each bar and each pie slice (true), or not (false, the default)
JChart.canvas()The drawing surface (a JCanvas) for more drawing, saving or the mouse
JChart.component()The Swing control: add it to a window
JChart.save(cFile)Save the picture (png, jpg, bmp, gif)
JChart.bars(aLabels, aSeriesList)Bars: one group for each label, one bar of each series in a group. oChart.bars(["A","B"],[3,5]) or oChart.bars(aLabels,[[name,values],...])
JChart.lines(aLabels, aSeriesList)Lines: the values of each series joined, over the labels. The same data as bars()
JChart.scatter(aSeriesList)Scatter: each series is [name, [ [x,y], [x,y], ... ]]; both axes are numbers
JChart.pie(aLabels, aValues)A pie: one slice for each label, as large as its value; the legend shows the share of each slice

Databases: JDBC (jdbc.ring)#

FunctionDescription
jSqlConnect(j_cUrl)Connect to a database. The driver is found among the jars of the class path (also the ones that jMaven or jClasspath added).
jSqlConnectAs(j_cUrl, j_cUser, j_cPassword)Connect to a database with a user name and a password
jSqlExec(j_oDb, j_cSql, j_aParams)Run INSERT / UPDATE / DELETE / CREATE ...: the number of rows that changed. aParams: the values of the ? marks.
jSqlQuery(j_oDb, j_cSql, j_aParams)Run a SELECT: a list of rows. A row is a list of [name, value] pairs: aRow[:name] (names in lower case). A null is "".
jSqlScript(j_oDb, j_cScript)Run many statements separated by ; (a script): the number of statements
jSqlValue(j_oDb, j_cSql, j_aParams)The value of the first column of the first row of a SELECT ("" when there is no row)

JavaDatabase (data.ring)#

FunctionDescription
jDbValue(j_aRow, j_cColumn)The value of a column in a row: jDbValue(aRow,"Name") ("" when the row has no such column)
JavaDatabase.init(cUrl, aTables)cUrl is a JDBC URL (or a java.sql.Connection); db_aSchema is the model (it may be empty when the tables exist)
JavaDatabase.connection()the java.sql.Connection
JavaDatabase.dialect()The kind of database: h2, sqlite, postgres, mysql, hsqldb or generic
JavaDatabase.columns(cTable)the columns of a table: [[name, type, isKey, options], ...] (the name of the table is not case sensitive)
JavaDatabase.keys(cTable)the names of the key columns of a table
JavaDatabase.option(aColumn, cName)The value of an option of a column ("" when it has none)
JavaDatabase.sqlType(aColumn)The SQL type of a column of the model
JavaDatabase.createTables()Create the tables of the model that do not exist
JavaDatabase.createTable(aTable)Create one table of the model if it does not exist
JavaDatabase.keyCondition(cTable, xKey)the condition "key1 = ? and key2 = ?" and the values for the key xKey
JavaDatabase.insert(cTable, aValues)add a row: aValues = [[name, value], ...]. The key is returned (the one that the database made when the table has an int key).
JavaDatabase.byKey(cTable, xKey)the row with the key, or "" when there is none
JavaDatabase.all(cTable)all the rows of a table
JavaDatabase.where(cTable, cCondition, aParams)the rows that match a SQL condition with {0} {1} ... parameters
JavaDatabase.update(cTable, xKey, aValues)change columns of the row with the key: aValues = [[name, value], ...]. The number of rows that changed.
JavaDatabase.remove(cTable, xKey)delete the row with the key: the number of rows
JavaDatabase.count(cTable)the number of rows of a table
JavaDatabase.execute(cSql, aParams)a statement that changes data, with {0} {1} ... parameters: the number of rows
JavaDatabase.scalar(cSql, aParams)the first value of a SELECT, with {0} {1} ... parameters
JavaDatabase.sqlRows(cSql, aParams)the rows of any SELECT (any columns, joins, groups), with {0} {1} ... parameters
JavaDatabase.query(cTable, aSpec)a query as data (the values are parameters of the statement): db_oConn.query("Customers",[ ["where",["and",["Age",">",30],["City","in",["Cairo","Giza"]]]], ["orderby",[["Age","desc"]]], ["skip",10], ["take",5], ["select",["Name","Age"]] ]) conditions: [column, op, value] with op = != < <= > >= contains startswith endswith in isnull notnull ; ["and",c1,c2,...] ["or",c1,c2,...] ["not",c]
JavaDatabase.aggregate(cTable, cFunction, cColumn, aCondition)count, sum, min, max or avg ("average" too) of a column for the rows that match a condition ([] = all rows)
JavaDatabase.countWhere(cTable, aCondition)The number of rows that match the condition ([] = all rows)
JavaDatabase.sum(cTable, cColumn, aCondition)The sum of a column for the rows that match the condition ([] = all rows)
JavaDatabase.min(cTable, cColumn, aCondition)The smallest value of a column for the rows that match the condition
JavaDatabase.max(cTable, cColumn, aCondition)The largest value of a column for the rows that match the condition
JavaDatabase.average(cTable, cColumn, aCondition)The average of a column for the rows that match the condition
JavaDatabase.groupCount(cTable, cColumn, aCondition)[[value, count], ...] for each value of a column
JavaDatabase.referenceColumn(cChildTable, cParentTable)The column of the child table that references the parent table
JavaDatabase.children(cParentTable, xKey, cChildTable)the rows of cChildTable that belong to the row cParentTable/xKey
JavaDatabase.parent(cChildTable, xKey, cParentTable)the row of cParentTable that the row cChildTable/xKey belongs to, or ""
JavaDatabase.begin()the changes are made together by commit() (or dropped by rollback())
JavaDatabase.commit()Make the changes of the transaction permanent
JavaDatabase.rollback()Drop the changes of the transaction
JavaDatabase.tables()the names of the tables of the database
JavaDatabase.close()Close the connection

Web server, HTTP client and JSON (web.ring)#

FunctionDescription
jJsonText(j_xValue)The JSON text of a Ring value: a number, a text, a list of [name, value] pairs (an object) or any other list (an array). A list of rows that each are [text, value] looks like an object: make it an array with jJsonArray(rows).
jJsonArray(j_aItems)A list that is always written as a JSON array, also when its items are [text, value] pairs: jJsonArray(aRows)
jWebJson(j_xValue)The response of a handler as JSON
jHttpGet(j_cUrl)The status and the body of a GET request: [200, "text"]. The callbacks of other threads run while it waits (a server of this program works).
jHttpPost(j_cUrl, j_cBody, j_cContentType)A POST request with a body: [status, "text"]
jHttpSend(j_cMethod, j_cUrl, j_cBody, j_cContentType)A request of any method (PUT, DELETE ...): [status, "text"]
JavaRequest.init(rq_oNew)A request that the server received: its HttpExchange
JavaRequest.exchange()the HttpExchange of the JDK, for everything else
JavaRequest.method()the HTTP method: "GET", "POST" ...
JavaRequest.path()the path of the address, without the query string: "/api/echo"
JavaRequest.queryString()the whole query string: "q=ring&page=2"
JavaRequest.query(cName)a value of the query string ("" when there is none): /search?q=ring --> query("q")
JavaRequest.param(cName)the part :name of the route that matched: the route "/user/:id" and the path "/user/7" give param("id") = "7"
JavaRequest.body()the body of the request as a text
JavaRequest.header(cName)the value of a header of the request ("" when there is none)
JavaRequest.form(cName)the value of a field of a posted form (application/x-www-form-urlencoded)
JavaRequest.setHeader(cName, cValue)add a header to the response
JavaRequest.respond(nStatus, cType, cText)send the response now: the status code, the content type and the text
JavaWebServer.init(j_xUrl)start the server at j_xUrl: "http://localhost:8080", or a port number (0 chooses a free port: see url())
JavaWebServer.url()the real address: "http://127.0.0.1:50321"
JavaWebServer.requests()the number of requests that were handled
JavaWebServer.route(cMethod, cPath, cHandler)the Ring function cHandler answers the requests of the method cMethod to the path cPath (":name" is a part that any text can fill)
JavaWebServer.onGet(cPath, cHandler)The Ring function cHandler answers the GET requests of the path cPath
JavaWebServer.onPost(cPath, cHandler)The Ring function cHandler answers the POST requests of the path cPath
JavaWebServer.onPut(cPath, cHandler)The Ring function cHandler answers the PUT requests of the path cPath
JavaWebServer.onDelete(cPath, cHandler)The Ring function cHandler answers the DELETE requests of the path cPath
JavaWebServer.showErrors(lShow)Send the text of the error of a handler to the client in the answer 500 (true; the default is false: the answer says only "Internal Server Error" and the text is printed by the server)
JavaWebServer.notFound(cHandler)the Ring function cHandler answers the requests that no route has
JavaWebServer.serveOne(nMilliseconds)handle the requests that wait, for up to nMilliseconds; true when a request was handled
JavaWebServer.run()serve requests until stop() is called
JavaWebServer.stop()make run() end (call it from a handler)
JavaWebServer.close()stop serving and shut the server down
JavaJsonArray.init(pItems)

Maven (maven.ring)#

FunctionDescription
jMaven(j_cCoords)Find an artifact and its dependencies, add the jars to the class path and give the list of jars (the artifact first)
jMavenClasses(j_cCoords, j_aPackages)jMaven and the Ring classes of the artifact: the classes of the packages in aPackages (every package of the jar when the list is empty)
jMavenClassesAll(j_cCoords)jMavenClasses with all the packages of the jar
jGenerateClasses(j_aJars, j_aPackages, j_cFolder)The Ring classes of the packages of a jar (aJars: the jar first, then the jars it needs): they are made into the folder (once: a folder that has classindex.txt is kept) and loaded. Gives the list of the packages.
jGenerateClassesAvoiding(j_aJars, j_aPackages, j_cFolder, j_aAvoid)The same, with the class indexes (classindex.txt files) whose Ring class names the new classes must not take: a class that has the name of one of them gets the name of its package in front (the JDK classes are in the first index; the artifacts that were made before are always avoided)
jMavenRepository(j_cUrl)Another repository (an https address or a folder): it is tried before the ones that were added earlier
jMavenOnlyMyRepositories()Only the repositories that jMavenRepository adds (not Maven Central)
jMavenCache(j_cFolder)The folder where the jars are kept
jMavenOffline(j_lOn)true: no download, only what the cache has
jMavenVerbose(j_lOn)false: no message when a jar is downloaded

JavaFX (javafx.ring)#

FunctionDescription
jJavaFX(j_cVersion)Download JavaFX (the jars of the platform), add it to the class path, start the toolkit. cVersion: "21.0.2". aModules (optional, with jJavaFXModules): also "fxml", "media", "web", "swing".
jJavaFXModules(j_aModules)More modules of JavaFX before jJavaFX(): jJavaFXModules(["base","graphics","controls","fxml"])
jJavaFXClasses(j_cVersion)The Ring classes of JavaFX (the public packages javafx.*) for the version of jJavaFX(): they are made once and kept in the cache
jFXRunLater(j_cCode)Run a Ring function on the JavaFX thread later (Platform.runLater)
jFXMessage(j_cText)A message box of JavaFX (an Alert); it waits until it is closed

Generated classes#

The wrapper classes are generated: there is one file for each Java package in libraries/javalib/generated/. The members of a class are the members of the Java class, named by the rules. See the class reference for every class of the JDK, or call jDescribe("java.util.ArrayList") to list the members of a class.

RingJava - use Java classes and methods from Ring programs.