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());
}
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();
}
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());
}
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());
}
Aggregations