List of usage examples for org.hibernate.dialect Dialect getTypeName
public String getTypeName(int code, long length, int precision, int scale) throws HibernateException
From source file:com.github.gekoh.yagen.ddl.CreateDDL.java
License:Apache License
private static String formatColumn(Dialect dialect, String colTemplate, Integer length, Integer precision, Integer scale) {//from w w w. j a v a 2 s . co m int intLen = length != null ? length : 0; int intPrec = precision != null ? precision : 0; int intScale = scale != null ? scale : 0; VelocityContext context = new VelocityContext(); context.put("timestampType", dialect.getTypeName(Types.TIMESTAMP, intLen, intPrec, intScale)); context.put("varcharType", dialect.getTypeName(Types.VARCHAR, intLen, intPrec, intScale)); StringWriter wr = new StringWriter(); Velocity.evaluate(context, wr, CreateDDL.class.getName() + "#formatColumn", colTemplate); return wr.toString(); }
From source file:com.github.gekoh.yagen.ddl.CreateDDL.java
License:Apache License
private String getHistTriggerSource(Dialect dialect, String objectName, String tableName, String histTableName, String histColName, Set<String> columns, List<String> pkColumns, List<String> histRelevantCols) { checkObjectName(dialect, objectName); VelocityContext context = new VelocityContext(); Set<String> hstNoNullColumns = new HashSet<String>(); TableConfig tableConfig = tblNameToConfig.get(tableName); IntervalPartitioning partitioning = tableConfig != null ? tableConfig.getTableAnnotationOfType(IntervalPartitioning.class) : null;//from w w w . j ava2 s . c om if (partitioning != null) { hstNoNullColumns.add(partitioning.columnName().toLowerCase()); } Set<String> nonPkColumns = new HashSet<String>(columns); nonPkColumns.removeAll(pkColumns); context.put("VERSION_COLUMN_NAME", VERSION_COLUMN_NAME); context.put("MODIFIER_COLUMN_NAME", AuditInfo.LAST_MODIFIED_BY); context.put("dialect", dialect); context.put("objectName", objectName); context.put("liveTableName", tableName); context.put("hstTableName", histTableName); context.put("columns", columns); context.put("histColName", histColName); context.put("pkColumns", pkColumns); context.put("nonPkColumns", nonPkColumns); context.put("noNullColumns", hstNoNullColumns); context.put("histRelevantCols", histRelevantCols); context.put("varcharType", dialect.getTypeName(Types.VARCHAR, 64, 0, 0)); setNewOldVar(dialect, context); StringWriter wr = new StringWriter(); mergeTemplateFromResource("HstTrigger.vm.pl.sql", wr, context); return wr.toString(); }
From source file:com.krawler.workflow.module.dao.ModuleProperty.java
License:Open Source License
public String getAttributeString(Dialect dialectObj) { StringBuilder attributeString = new StringBuilder(); attributeString.append(" "); attributeString.append(this.fieldName); attributeString.append(" "); attributeString//from ww w . j a va 2 s . c o m .append(dialectObj.getTypeName(this.fieldType, (this.length == 0 ? 255 : this.length), 4, 0)); if (!StringUtil.isNullOrEmpty(this.defaultValue)) { attributeString.append(" default "); attributeString.append(this.defaultValue); } return attributeString.toString(); }
From source file:com.literatejava.hibernate.allocator.LinearBlockAllocator.java
License:Open Source License
public String[] sqlCreateStrings(Dialect dialect) throws HibernateException { // create Sequence Table // SPEC - always output, skips with error if already exist in DB String tableStr = "create table " + dialect.quote(tableName) + " (" + dialect.quote(sequenceColumn) + " " + dialect.getTypeName(Types.VARCHAR, DEFAULT_SEQUENCE_COLUMNLENGTH, 0, 0) + ", " + dialect.quote(allocColumn) + " " + dialect.getTypeName(Types.BIGINT) + ", " + "primary key (" + dialect.quote(sequenceColumn) + ")" + ")"; // create Row for this Sequence. String valueStr = "insert into " + tableName + "(" + dialect.quote(sequenceColumn) + "," + dialect.quote(allocColumn) + ") values ( '" + sequenceName + "', " + blockSize + " )"; // done.// ww w . j a va 2 s. c o m return new String[] { tableStr, valueStr }; }
From source file:de.innovationgate.webgate.api.mysql.GaleraClusterTableGenerator.java
License:Open Source License
@Override public String[] sqlCreateStrings(Dialect dialect) throws HibernateException { return new String[] { new StringBuilder().append(dialect.getCreateTableString()).append(' ') .append(tableName).append(" ( ").append(segmentColumnName).append(' ') .append(dialect.getTypeName(Types.VARCHAR, segmentValueLength, 0, 0)).append(" not null ") .append(", ").append(valueColumnName).append(' ').append(dialect.getTypeName(Types.BIGINT)) .append(", primary key ( ").append(segmentColumnName).append(" ) ) ").toString() }; }
From source file:net.e6tech.elements.persist.hibernate.ModifiedTableGenerator.java
License:Apache License
@Override public String[] sqlCreateStrings(Dialect dialect) throws HibernateException { return new String[] { dialect.getCreateTableString() + ' ' + renderedTableName + " ( " + segmentColumnName + ' ' + dialect.getTypeName(Types.VARCHAR, segmentValueLength, 0, 0) + " not null " + ", " + valueColumnName + ' ' + dialect.getTypeName(Types.BIGINT) + ", primary key ( " + segmentColumnName + " ) )" + dialect.getTableTypeString() }; }
From source file:net.e6tech.elements.persist.hibernate.ModifiedTableGenerator.java
License:Apache License
@Override public void registerExportables(Database database) { final Dialect dialect = database.getJdbcEnvironment().getDialect(); final Namespace namespace = database.locateNamespace(qualifiedTableName.getCatalogName(), qualifiedTableName.getSchemaName()); Table table = namespace.locateTable(qualifiedTableName.getObjectName()); if (table == null) { table = namespace.createTable(qualifiedTableName.getObjectName(), false); // todo : note sure the best solution here. do we add the columns if missing? other? final Column segmentColumn = new ExportableColumn(database, table, segmentColumnName, StringType.INSTANCE, dialect.getTypeName(Types.VARCHAR, segmentValueLength, 0, 0)); segmentColumn.setNullable(false); table.addColumn(segmentColumn);//ww w. jav a 2 s. com // lol table.setPrimaryKey(new PrimaryKey(table)); table.getPrimaryKey().addColumn(segmentColumn); final Column valueColumn = new ExportableColumn(database, table, valueColumnName, LongType.INSTANCE); table.addColumn(valueColumn); } // allow physical naming strategies a chance to kick in this.renderedTableName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter() .format(table.getQualifiedTableName(), dialect); this.selectQuery = buildSelectQuery(dialect); this.updateQuery = buildUpdateQuery(); this.insertQuery = buildInsertQuery(); }
From source file:net.lshift.hibernate.migrations.SQLStringHelpers.java
License:Apache License
/** * Note to the unassuming maintenance developer: * * What happens with Oracle a dialect is when a varchar2 is larger than 4000, * the type name returned for java.sql.Type.VARCHAR is a long, which can be very confusing. * * I'm not sure that this is significant enough to warrant patching. * *///from www .j a v a 2s .c o m private static String getTypeName(Dialect dialect, Column col) { return dialect.getTypeName(col.getSqlTypeCode(), col.getLength(), col.getPrecision(), col.getScale()); }
From source file:org.hyperic.hibernate.id.HQMultipleHiLoPerTableGenerator.java
License:Open Source License
public String[] sqlCreateStrings(Dialect dialect) throws HibernateException { return new String[] { new StringBuffer().append("create table ").append(tableName).append(" ( ") .append(pkColumnName).append(" ").append(dialect.getTypeName(Types.VARCHAR, keySize, 0, 0)) .append(", ").append(valueColumnName).append(" ").append(dialect.getTypeName(Types.INTEGER)) .append(", ").append("primary key (" + pkColumnName + ") ").append(" ) ").toString() }; }
From source file:org.nuxeo.ecm.directory.sql.repository.Column.java
License:Open Source License
public String getSqlTypeString(Dialect dialect) { return dialect.getTypeName(sqlType, length, precision, scale); }