XmlType Field for mapper?

62 views
Skip to first unread message

Paul Dale

unread,
Apr 11, 2011, 1:13:36 PM4/11/11
to lif...@googlegroups.com
Hi everyone,

Has anyone tried or thought about making an MappedXml field utilizing native xml types for postgres or oracle?

Looking at doing this now for Oracle 11gR2.

Basically like MappedText but returns native xml.

Possibly also adding the ability to find(ByXpath(xpath)) ...

Paul

David Pollak

unread,
Apr 12, 2011, 4:24:39 PM4/12/11
to lif...@googlegroups.com
Looks interesting.  Please open a ticket.

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.



--
Lift, the simply functional web framework http://liftweb.net

Todd O'Bryan

unread,
May 24, 2011, 1:08:08 AM5/24/11
to Lift
Are you still willing to consider adding a MappedXml field? I didn't
want to create the ticket without checking to make sure...

I'd like it for a couple of reasons:

1. I'm making a big database of different kinds of questions--multiple
choice, matching, fill-in-the-blank, short answer, etc., and it seems
like it would be easier to just have one field with all the question
data in it, rather than trying to come up with a system that's
flexible enough to handle every conceivable kind of question ahead of
time.

2. I need a way to store user-created marked-up text, and I've pretty
much decided to use HTML and try to sanitize on the way in and out of
the database. (The jSoup jar is only 145kb and has a sanitizer that
walks the DOM, only letting white-listed tags through.) I considered
using some other form of markup, but they all have holes, and friendly
editors like CKeditor produce HTML, not other markup. (I am, by the
way, very willing to be talked out of this. Just realize that I'm
trying to create a way for teachers and students to create content,
and I know I'll get grief if they can't include colors, tables, fonts,
and every other imaginable gaudy web page creation that sane designers
know not to use.) At any rate, being able to subclass MappedXml to a
MappedHtml that does sanitizing all over the place would be lovely.

Thanks!
Todd

P.S. My school year ends in eight days, and several students and I
will be using Lift over the summer for a project. Now that I'm not
responsible for the intellectual development of 140 adolescents, I'd
like to give back a bit (at least for the 10 weeks until my life gets
crazy again), and ideas for places we should concentrate are welcome.

On Apr 12, 4:24 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> Looks interesting.  Please open a ticket.
>
>
>
>
>
>
>
>
>
> On Mon, Apr 11, 2011 at 10:13 AM, Paul Dale <paul.d...@gmail.com> wrote:
> > Hi everyone,
>
> > Has anyone tried or thought about making an MappedXml field utilizing
> > native xml types for postgres or oracle?
>
> > Looking at doing this now for Oracle 11gR2.
>
> > Basically like MappedText but returns native xml.
>
> > Possibly also adding the ability to find(ByXpath(xpath)) ...
>
> > Paul
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Lift" group.
> > To post to this group, send email to lif...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > liftweb+u...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Simply Lifthttp://simply.liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890

pauldale

unread,
May 25, 2011, 1:30:45 PM5/25/11
to Lift

Ticket created - https://www.assembla.com/spaces/liftweb/tickets/1023-mappedxml-field

Sorry for the delay, I missed the response.

For our initial project we ended up going straight jdbc, but this
xmltype feature seems to be really useful - I expect we'll be using it
more in the future and mapper support would be great.


The main attraction is the xmlindex that comes as of 11gR2. The
xmltype and related query functions have been around since 9, but are
way too slow to be much use unless you can really shrink the data set
down. With the xmlindex you can do an xpath based search across say
50k xml documents in about 1.5-2 seconds.

On Apr 12, 10:24 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> Looks interesting.  Please open a ticket.
>
>
>
>
>
>
>
>
>
> On Mon, Apr 11, 2011 at 10:13 AM, Paul Dale <paul.d...@gmail.com> wrote:
> > Hi everyone,
>
> > Has anyone tried or thought about making an MappedXml field utilizing
> > native xml types for postgres or oracle?
>
> > Looking at doing this now for Oracle 11gR2.
>
> > Basically like MappedText but returns native xml.
>
> > Possibly also adding the ability to find(ByXpath(xpath)) ...
>
> > Paul
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Lift" group.
> > To post to this group, send email to lif...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > liftweb+u...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Simply Lifthttp://simply.liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890

Todd O'Bryan

unread,
May 29, 2011, 11:45:19 AM5/29/11
to lif...@googlegroups.com
I created a MappedNodeSeq. It's very preliminary, as it saves the
content in a CLOB, rather than an XML type, if the database supports
that, and I'm sure I made some mistakes, but in very simple testing it
seems to work. One problem is that if the value in the db is set to be
something that won't parse as a NodeSeq, you'll have problems, but as
long as you only set the value through the Mapper interface, it won't
let you set the value to anything but a NodeSeq.

The code is below. I just modified MappedDecimal from Exploring Lift,
so feel free to use this or modify it in any way that you're inclined
to.

Todd

/**
* <p>
* A field that maps to a NodeSeq.
* </p>
*
*/
abstract class MappedNodeSeq[T <: Mapper[T]] (val fieldOwner : T)
extends MappedField[NodeSeq,T] {
def defaultValue = NodeSeq.Empty

def dbFieldClass = classOf[NodeSeq]

private var data : NodeSeq = defaultValue
private var orgData : NodeSeq = defaultValue

private def st(in : NodeSeq) = {
data = in
orgData = in
}

protected def i_is_! = data
protected def i_was_! = orgData

override def doneWithSave() {
orgData = data
}

override def readPermission_? = true
override def writePermission_? = true

protected def i_obscure_!(in : NodeSeq) = defaultValue

protected def real_i_set_!(value : NodeSeq): NodeSeq = {
if (value != data) {
data = value
dirty_?(true)
}
data
}

def asJsExp: JsExp = JE.Str(is.toString)
def asJsonValue: Box[JsonAST.JString] = Full(JsonAST.JString(is.toString))

def setFromAny(in : Any) : NodeSeq =
in match {
case ns: NodeSeq => set(ns)
case n :: _ => setFromString(n.toString)
case Some(n) => setFromString(n.toString)
case Full(n) => setFromString(n.toString)
case None | Empty | Failure(_, _, _) | null => set(NodeSeq.Empty)
case n => setFromString(n.toString)
}

private def parseNodeSeq(in: String): NodeSeq = {
val el: Elem = XML.loadString("<dummy>" + in + "</dummy>")
el.child
}

def setFromString(in : String) : NodeSeq = {
this.set(parseNodeSeq(in))
data
}

def targetSQLType = Types.CLOB

def jdbcFriendly(field : String) = i_is_!.toString

def real_convertToJDBCFriendly(value: NodeSeq): Object = value.toString

def buildSetBooleanValue(accessor : Method, columnName : String) :
(T, Boolean, Boolean) => Unit = null

def buildSetDateValue(accessor : Method, columnName : String) : (T,
Date) => Unit = null

def buildSetStringValue(accessor: Method, columnName: String): (T, String) =>
Unit = (inst, v) => doField(inst, accessor, {case f:
MappedNodeSeq[T] => f.set(if (v == null) defaultValue else
parseNodeSeq(v))})

def buildSetLongValue(accessor: Method, columnName : String) : (T,
Long, Boolean) =>
Unit = null

def buildSetActualValue(accessor: Method, data: AnyRef, columnName:
String) : (T, AnyRef) =>
Unit = (inst, v) => doField(inst, accessor, {case f:
MappedNodeSeq[T] => f.set(if (v == null) defaultValue else
parseNodeSeq(v.toString))})

def fieldCreatorString(dbType: DriverType, colName: String): String
= colName + " " + dbType.clobColumnType + notNullAppender()

Reply all
Reply to author
Forward
0 new messages