[
https://jira.nuxeo.com/browse/NXP-6301?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=89666#action_89666
]
Wojciech Sulejman edited comment on NXP-6301 at 2/25/11 7:35 PM:
-----------------------------------------------------------------
Let me present how I understand this and maybe somebody correct me and get me
back on the track.
1) Firstly, here is my schema definition:
<xs:simpleType name="store">
<xs:restriction base="xs:string">
<xs:maxLength value="8192"/>
</xs:restriction>
</xs:simpleType>
<xs:include schemaLocation="core-types.xsd"/>
<xs:element name="userid" type="xs:string"/>
<xs:element name="certificate" type="xs:string"/>
<xs:element name="keypassword" type="xs:string"/>
<xs:element name="startdate" type="xs:date" />
<xs:element name="enddate" type="xs:date" />
<xs:element name="revocationdate" type="xs:date" />
<xs:element name="keystore" type="cert:store"/>
</xs:schema>
where I defined a SimpleType store that is used to represent and store the
keystore field values.
2) The XSDLoader has a method (loadSchema) which in turn arranges for
providing fields to the schema:
Type ecmType = loadType(ecmSchema, el.getType());
if (ecmType != null) {
// add the field to the schema
createField(ecmSchema, el, ecmType);
The ecmType is provided by the loadType-> loadSimpleType(schema, type) methods.
3) A SimpleType (the ecmType above) object is supposed to provide the "string"
type -> resolvable to the DB type: "VARCHAR", plus the "restriction" to be
used by the database for VARCHAR length.
There exists a SimpleType implementation (RestrictionSimpleTypeImpl) that has
the "getFacet" method that provides access to the value stored in the
xs:maxLength field.
CODE START====>
private SimpleType loadSimpleType(Schema schema, XSType type)
throws TypeBindingException {
String name = type.getName();
{...}
// HERE'S MY ADDED METHOD:
// add constraints/restrictions to the simple type
if (type instanceof RestrictionSimpleTypeImpl) {
RestrictionSimpleTypeImpl restrictionType=
(RestrictionSimpleTypeImpl)type;
List<Constraint> constraints = new ArrayList<Constraint>();
if(restrictionType.getFacet("maxLength")!=null){
int MIN_LENGTH = 1;
int
MAX_LENGTH=Integer.parseInt(restrictionType.getFacet("maxLength").getValue().toString());
Constraint stringLengthConstraint = new StringLengthConstraint(
MIN_LENGTH, MAX_LENGTH);
constraints.add(stringLengthConstraint);
}
simpleType.setConstraints(constraints.toArray(new Constraint[0]));
}
return simpleType;
}
<====CODEEND
You might notice here that I hard-coded the MIN_LENGTH value as I am not sure
yet how to approach it.
4) The SQLDirectory performs in its constructor SQL Mapping from our schema
fields:
for (Field f : schema.getFields()) {
{...}
fieldSqlType = FieldMapper.getSqlField(f.getType().getName());
the Mapper is looking for one of the following:
if (name.equals("integer")) {
return Types.INTEGER;
} else if (name.equals("long")) {
return Types.INTEGER;
} else if (name.equals("string")) {
return Types.VARCHAR;
} else if (name.equals("date")) {
return Types.TIMESTAMP;
}
Otherwise an exception is thrown.
My field ("store") is not one of acceptable field names so the "warning" is
logged:
try {
fieldSqlType =
FieldMapper.getSqlField(f.getType().getName());
} catch (DirectoryException e) {
log.warn(String.format(
"Field %s of type %s in SQLDirectory %s is not
supported and thus ignored",
As the field is ignored, no database column is created for my field.
Also:
I saw that the default column length used in Nuxeo comes from the following
class: org.nuxeo.ecm.directory.sql.repository.Column
Here's the field: private int length = 255; // Hibernate default
There is a public mutator: setLength(int length) so I would think that that
would be the path to consider.
====
Now, for my questions:
Am I on the right path in general?
TD: Looks ok to me.
How do you recommend mapping my field name and its length to the FieldMapper?
TD: I would probably make the FieldMapper directly return a Column (containing
both data type and size)
was (Author: wsulejman):
Let me present how I understand this and maybe somebody correct me and get
me back on the track.
1) Firstly, here is my schema definition:
<xs:simpleType name="store">
<xs:restriction base="xs:string">
<xs:maxLength value="8192"/>
</xs:restriction>
</xs:simpleType>
<xs:include schemaLocation="core-types.xsd"/>
<xs:element name="userid" type="xs:string"/>
<xs:element name="certificate" type="xs:string"/>
<xs:element name="keypassword" type="xs:string"/>
<xs:element name="startdate" type="xs:date" />
<xs:element name="enddate" type="xs:date" />
<xs:element name="revocationdate" type="xs:date" />
<xs:element name="keystore" type="cert:store"/>
</xs:schema>
where I defined a SimpleType store that is used to represent and store the
keystore field values.
2) The XSDLoader has a method (loadSchema) which in turn arranges for
providing fields to the schema:
Type ecmType = loadType(ecmSchema, el.getType());
if (ecmType != null) {
// add the field to the schema
createField(ecmSchema, el, ecmType);
The ecmType is provided by the loadType-> loadSimpleType(schema, type) methods.
3) A SimpleType (the ecmType above) object is supposed to provide the "string"
type -> resolvable to the DB type: "VARCHAR", plus the "restriction" to be
used by the database for VARCHAR length.
There exists a SimpleType implementation (RestrictionSimpleTypeImpl) that has
the "getFacet" method that provides access to the value stored in the
xs:maxLength field.
CODE START====>
private SimpleType loadSimpleType(Schema schema, XSType type)
throws TypeBindingException {
String name = type.getName();
{...}
// HERE'S MY ADDED METHOD:
// add constraints/restrictions to the simple type
if (type instanceof RestrictionSimpleTypeImpl) {
RestrictionSimpleTypeImpl restrictionType=
(RestrictionSimpleTypeImpl)type;
List<Constraint> constraints = new ArrayList<Constraint>();
if(restrictionType.getFacet("maxLength")!=null){
int MIN_LENGTH = 1;
int
MAX_LENGTH=Integer.parseInt(restrictionType.getFacet("maxLength").getValue().toString());
Constraint stringLengthConstraint = new StringLengthConstraint(
MIN_LENGTH, MAX_LENGTH);
constraints.add(stringLengthConstraint);
}
simpleType.setConstraints(constraints.toArray(new Constraint[0]));
}
return simpleType;
}
<====CODEEND
You might notice here that I hard-coded the MIN_LENGTH value as I am not sure
yet how to approach it.
4) The SQLDirectory performs in its constructor SQL Mapping from our schema
fields:
for (Field f : schema.getFields()) {
{...}
fieldSqlType = FieldMapper.getSqlField(f.getType().getName());
the Mapper is looking for one of the following:
if (name.equals("integer")) {
return Types.INTEGER;
} else if (name.equals("long")) {
return Types.INTEGER;
} else if (name.equals("string")) {
return Types.VARCHAR;
} else if (name.equals("date")) {
return Types.TIMESTAMP;
}
Otherwise an exception is thrown.
My field ("store") is not one of acceptable field names so the "warning" is
logged:
try {
fieldSqlType =
FieldMapper.getSqlField(f.getType().getName());
} catch (DirectoryException e) {
log.warn(String.format(
"Field %s of type %s in SQLDirectory %s is not
supported and thus ignored",
As the field is ignored, no database column is created for my field.
Also:
I saw that the default column length used in Nuxeo comes from the following
class: org.nuxeo.ecm.directory.sql.repository.Column
Here's the field: private int length = 255; // Hibernate default
There is a public mutator: setLength(int length) so I would think that that
would be the path to consider.
====
Now, for my questions:
Am I on the right path in general?
Looks ok to me.
How do you recommend mapping my field name and its length to the FieldMapper?
I would probably make the FieldMapper directly return a Column (containing both
data type and size)
> length of field in schema should be configurable
> ------------------------------------------------
>
> Key: NXP-6301
> URL: https://jira.nuxeo.com/browse/NXP-6301
> Project: Nuxeo Enterprise Platform
> Issue Type: Improvement
> Affects Versions: 5.4.0.1
> Reporter: Alexandre Russel
> Assignee: Wojciech Sulejman
> Fix For: 5.4.1
>
>
> I should be able to do:
> <simpleType name="myString">
> <restriction base="string">
> <maxLength value="200"/>
> </restriction>
> </simpleType>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.nuxeo.com/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
ECM-tickets mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/ecm-tickets