Quantcast
Channel: XWiki Forum - Latest topics
Viewing all articles
Browse latest Browse all 1220

How can get data from not mapped table

$
0
0

Hi,
I’m having trouble accessing a non-mapped table in XWiki, and I’d appreciate any guidance.

Here are the approaches I’ve tried so far (I am using a pre-built version of XWiki as I cannot build it myself)

Add Mapping on xwiki.oracle.hbm.xml with dynamic insert → build failed

<class table="TEMP_USER_DATA" dynamic-insert="true" dynamic-update="true" mutable="false">
        <composite-id>
            <key-property name="USER_ID" column="USER_ID" type="long"/>
        </composite-id>
        <property name="USER_NAME" column="USER_NAME" type="string"/>
        <property name="CREATED_AT" column="CREATED_AT" type="timestamp"/>
    </class>

This is table create SQL

CREATE TABLE TEMP_USER_DATA (
	USER_ID     NUMBER NOT NULL,
	USER_NAME   VARCHAR2(100),
	CREATED_AT  DATE);

Use xwiki.query (Can’t use hql on not mapped table)
->Caused by: org.xwiki.query.QueryException: Language [sql] is not supported

#set($query = "SELECT USER_ID, USER_NAME, CREATED_AT FROM TEMP_USER_DATA")
    #set($results = $services.query.execute($query, "sql"))

Use groovy Script? Write post on Xwiki like this

def connection = xcontext.getDatabase().getConnection()
def sql = "SELECT USER_ID, USER_NAME FROM TEMP_USER_DATA"
def stmt = connection.createStatement()
def resultSet = stmt.executeQuery(sql)

def results = []
while (resultSet.next()) {
    results << [
        userId: resultSet.getInt("USER_ID"),
        userName: resultSet.getString("USER_NAME")
    ]
}

resultSet.close()
stmt.close()
connection.close()

print results
return results
 

and called it in Velocity

#set($result = $xwiki.parseGroovyFromPage("Scripts.MyGroovyScript"))
    $result

#foreach($row in $result)
    <p>User ID: $row.userId, Name: $row.userName</p>

result is

Script_20888a604304cc8b94e5542c1ae6c7bb@1482d965

words after @ keeps changing

I’m feeling stucked. Is there any mistakes or other idea?

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 1220

Trending Articles