use of org.jooq.Schema in project jOOQ by jOOQ.
the class JDBCDatabase method getSequences0.
@Override
protected List<SequenceDefinition> getSequences0() throws SQLException {
List<SequenceDefinition> result = new ArrayList<SequenceDefinition>();
for (Schema schema : getSchemasFromMeta()) {
for (Sequence<?> sequence : schema.getSequences()) {
SchemaDefinition sd = getSchema(schema.getName());
DataTypeDefinition type = new DefaultDataTypeDefinition(this, sd, sequence.getDataType().getTypeName());
result.add(new DefaultSequenceDefinition(sd, sequence.getName(), type));
}
}
return result;
}
use of org.jooq.Schema in project jOOQ by jOOQ.
the class DefaultBinding method pgRenderEnumCast.
private static final void pgRenderEnumCast(RenderContext render, Class<?> type) {
@SuppressWarnings("unchecked") Class<? extends EnumType> enumType = (Class<? extends EnumType>) (type.isArray() ? type.getComponentType() : type);
// [#968] Don't cast "synthetic" enum types (note, val can be null!)
// [#4427] Java Enum agnostic implementation will work for Scala also
EnumType[] enums = Tools.enums(enumType);
if (enums == null || enums.length == 0)
throw new IllegalArgumentException("Not a valid EnumType : " + type);
Schema schema = enums[0].getSchema();
if (schema != null) {
render.sql("::");
schema = using(render.configuration()).map(schema);
if (schema != null && TRUE.equals(render.configuration().settings().isRenderSchema())) {
render.visit(schema);
render.sql('.');
}
render.visit(name(enums[0].getName()));
}
if (type.isArray())
render.sql("[]");
}
use of org.jooq.Schema in project jOOQ by jOOQ.
the class DSL method sequenceByName.
/**
* Create a qualified sequence, given its sequence name.
* <p>
* This constructs a sequence reference given the sequence's qualified name.
* jOOQ will render the sequence name according to your
* {@link Settings#getRenderNameStyle()} settings. Choose
* {@link RenderNameStyle#QUOTED} to prevent syntax errors and/or SQL
* injection.
* <p>
* Example: <code><pre>
* // This sequence...
* sequenceByName("MY_SCHEMA", "MY_SEQUENCE");
*
* // ... will render this SQL on SQL Server with RenderNameStyle.QUOTED set
* [MY_SCHEMA].[MY_SEQUENCE]
* </pre></code>
*
* @param qualifiedName The various parts making up your sequence's
* reference name.
* @param type The type of the returned field
* @return A sequence referenced by <code>sequenceName</code>
* @deprecated - [#3843] - 3.6.0 - use {@link #sequence(Name, DataType)} instead
*/
@Deprecated
@Support({ CUBRID, DERBY, FIREBIRD, H2, HSQLDB, POSTGRES })
public static <T extends Number> Sequence<T> sequenceByName(DataType<T> type, String... qualifiedName) {
if (qualifiedName == null)
throw new NullPointerException();
if (qualifiedName.length < 1 || qualifiedName.length > 2)
throw new IllegalArgumentException("Must provide a qualified name of length 1 or 2 : " + name(qualifiedName));
String name = qualifiedName[qualifiedName.length - 1];
Schema schema = qualifiedName.length == 2 ? schemaByName(qualifiedName[0]) : null;
return new SequenceImpl<T>(name, schema, type);
}
use of org.jooq.Schema in project jOOQ by jOOQ.
the class ParserImpl method parseDropSchema.
private static final DDLQuery parseDropSchema(ParserContext ctx) {
boolean ifExists = parseKeywordIf(ctx, "IF EXISTS");
Schema schemaName = parseSchemaName(ctx);
boolean cascade = parseKeywordIf(ctx, "CASCADE");
boolean restrict = !cascade && parseKeywordIf(ctx, "RESTRICT");
DropSchemaStep s1;
DropSchemaFinalStep s2;
s1 = ifExists ? ctx.dsl.dropSchemaIfExists(schemaName) : ctx.dsl.dropSchema(schemaName);
s2 = cascade ? s1.cascade() : restrict ? s1.restrict() : s1;
return s2;
}
use of org.jooq.Schema in project jOOQ by jOOQ.
the class ParserImpl method parseRename.
private static final DDLQuery parseRename(ParserContext ctx) {
parseKeyword(ctx, "RENAME");
parseWhitespaceIf(ctx);
switch(ctx.character()) {
case 'c':
case 'C':
if (parseKeywordIf(ctx, "COLUMN")) {
TableField<?, ?> oldName = parseFieldName(ctx);
parseKeyword(ctx, "TO");
Field<?> newName = parseFieldName(ctx);
return ctx.dsl.alterTable(oldName.getTable().getName()).renameColumn(oldName).to(newName);
}
break;
case 'i':
case 'I':
if (parseKeywordIf(ctx, "INDEX")) {
Name oldName = parseIndexName(ctx);
parseKeyword(ctx, "TO");
Name newName = parseIndexName(ctx);
return ctx.dsl.alterIndex(oldName).renameTo(newName);
}
break;
case 's':
case 'S':
if (parseKeywordIf(ctx, "SCHEMA")) {
Schema oldName = parseSchemaName(ctx);
parseKeyword(ctx, "TO");
Schema newName = parseSchemaName(ctx);
return ctx.dsl.alterSchema(oldName).renameTo(newName);
} else if (parseKeywordIf(ctx, "SEQUENCE")) {
Sequence<?> oldName = parseSequenceName(ctx);
parseKeyword(ctx, "TO");
Sequence<?> newName = parseSequenceName(ctx);
return ctx.dsl.alterSequence(oldName).renameTo(newName);
}
break;
case 'v':
case 'V':
if (parseKeywordIf(ctx, "VIEW")) {
Table<?> oldName = parseTableName(ctx);
parseKeyword(ctx, "TO");
Table<?> newName = parseTableName(ctx);
return ctx.dsl.alterView(oldName).renameTo(newName);
}
break;
}
// If all of the above fails, we can assume we're renaming a table.
parseKeywordIf(ctx, "TABLE");
Table<?> oldName = parseTableName(ctx);
parseKeyword(ctx, "TO");
Table<?> newName = parseTableName(ctx);
return ctx.dsl.alterTable(oldName).renameTo(newName);
}
Aggregations