Search in sources :

Example 1 with CharSegment

use of org.nutz.lang.segment.CharSegment in project nutz by nutzam.

the class AbstractJdbcExpert method createIndexSql.

public Sql createIndexSql(Entity<?> en, EntityIndex index) {
    StringBuilder sb = new StringBuilder();
    if (index.isUnique())
        sb.append("Create UNIQUE Index ");
    else
        sb.append("Create Index ");
    if (index.getName().contains("$"))
        sb.append(TableName.render(new CharSegment(index.getName())));
    else
        sb.append(index.getName());
    sb.append(" ON ").append(en.getTableName()).append("(");
    for (EntityField field : index.getFields()) {
        if (field instanceof MappingField) {
            MappingField mf = (MappingField) field;
            sb.append(mf.getColumnNameInSql()).append(',');
        } else {
            throw Lang.makeThrow(DaoException.class, "%s %s is NOT a mapping field, can't use as index field!!", en.getClass(), field.getName());
        }
    }
    sb.setCharAt(sb.length() - 1, ')');
    return Sqls.create(sb.toString());
}
Also used : CharSegment(org.nutz.lang.segment.CharSegment) MappingField(org.nutz.dao.entity.MappingField) EntityField(org.nutz.dao.entity.EntityField)

Example 2 with CharSegment

use of org.nutz.lang.segment.CharSegment in project nutz by nutzam.

the class AbstractJdbcExpert method gSQL.

protected static String gSQL(String ptn, String table, String field) {
    CharSegment cs = new CharSegment(ptn);
    cs.set("T", table).set("F", field);
    return cs.toString();
}
Also used : CharSegment(org.nutz.lang.segment.CharSegment)

Example 3 with CharSegment

use of org.nutz.lang.segment.CharSegment in project nutz by nutzam.

the class CharSegmentTest method testClone.

@Test
public void testClone() {
    Segment seg = Segments.create("A${a}B");
    seg.set("a", "A");
    assertEquals("AAB", seg.toString());
    Segment seg2 = (CharSegment) seg.clone();
    seg.set("a", "FF");
    assertEquals("AAB", seg2.toString());
    assertEquals("AFFB", seg.toString());
}
Also used : CharSegment(org.nutz.lang.segment.CharSegment) CharSegment(org.nutz.lang.segment.CharSegment) Segment(org.nutz.lang.segment.Segment) Test(org.junit.Test)

Example 4 with CharSegment

use of org.nutz.lang.segment.CharSegment in project nutz by nutzam.

the class CharSegmentTest method testBorn.

@Test
public void testBorn() {
    Segment seg = Segments.create("A${a}B");
    seg.set("a", "A");
    assertEquals("AAB", seg.toString());
    Segment seg2 = (CharSegment) seg.born();
    assertEquals("AB", seg2.toString());
    assertEquals("AAB", seg.toString());
}
Also used : CharSegment(org.nutz.lang.segment.CharSegment) CharSegment(org.nutz.lang.segment.CharSegment) Segment(org.nutz.lang.segment.Segment) Test(org.junit.Test)

Aggregations

CharSegment (org.nutz.lang.segment.CharSegment)4 Test (org.junit.Test)2 Segment (org.nutz.lang.segment.Segment)2 EntityField (org.nutz.dao.entity.EntityField)1 MappingField (org.nutz.dao.entity.MappingField)1