use of org.jooq.Configuration in project jOOQ by jOOQ.
the class AbstractRoutine method execute.
@Override
public final int execute() {
Configuration config = configurationOrThrow(this);
SQLDialect family = config.family();
results.clear();
outValues.clear();
// [#8431] PG 11 procedures, however, must be called with CallableStatement
if (isSQLUsable() && REQUIRE_SELECT_FROM.contains(config.dialect())) {
return executeSelectFromPOSTGRES();
} else // Procedures (no return value) are always executed as CallableStatement
if (type == null) {
return executeCallableStatement();
} else {
switch(family) {
// syntax for functions. Select functions from DUAL instead
case HSQLDB:
// returns a cursor. Instead, SELECT * FROM table(f()) works
if (SQLDataType.RESULT.equals(type.getSQLDataType())) {
return executeSelectFromHSQLDB();
} else // Fall through
{
}
case FIREBIRD:
case H2:
return executeSelect();
// DML statements
default:
return executeCallableStatement();
}
}
}
use of org.jooq.Configuration in project jOOQ by jOOQ.
the class JavaGenerator method printConvenienceMethodProcedure.
protected void printConvenienceMethodProcedure(JavaWriter out, RoutineDefinition procedure, boolean instance) {
// [#281] - Java can't handle more than 255 method parameters
if (procedure.getInParameters().size() > 254) {
log.info("Too many parameters", "Procedure " + procedure + " has more than 254 in parameters. Skipping generation of convenience method.");
return;
}
final String className = out.ref(getStrategy().getFullJavaClassName(procedure));
final String configurationArgument = disambiguateJavaMemberName(procedure.getInParameters(), "configuration");
final String localVar = disambiguateJavaMemberName(procedure.getInParameters(), "p");
final List<ParameterDefinition> outParams = list(procedure.getReturnValue(), procedure.getOutParameters());
final String methodName = getStrategy().getJavaMethodName(procedure, Mode.DEFAULT);
final String firstOutParamType = outParams.size() == 1 ? out.ref(getJavaType(outParams.get(0).getType(resolver(out)), out)) : "";
if (!printDeprecationIfUnknownTypes(out, procedure.getAllParameters()))
out.javadoc("Call <code>%s</code>", procedure.getQualifiedOutputName());
if (scala)
out.println("%sdef %s(", visibility(), methodName);
else if (kotlin)
out.println("%sfun %s(", visibility(), methodName);
else {
out.println("%s%s%s %s(", visibility(), !instance ? "static " : "", outParams.size() == 0 ? "void" : outParams.size() == 1 ? firstOutParamType : className, methodName);
}
String separator = " ";
if (!instance) {
if (scala)
out.println("%s%s: %s", separator, scalaWhitespaceSuffix(configurationArgument), Configuration.class);
else if (kotlin)
out.println("%s%s: %s", separator, configurationArgument, Configuration.class);
else
out.println("%s%s %s", separator, Configuration.class, configurationArgument);
separator = ", ";
}
for (ParameterDefinition parameter : procedure.getInParameters()) {
// Skip SELF parameter
if (instance && parameter.equals(procedure.getInParameters().get(0)))
continue;
final String memberName = getStrategy().getJavaMemberName(parameter);
final String typeName = refNumberType(out, parameter.getType(resolver(out)));
if (scala)
out.println("%s%s: %s", separator, scalaWhitespaceSuffix(memberName), typeName);
else if (kotlin)
out.println("%s%s: %s?", separator, memberName, typeName);
else
out.println("%s%s %s", separator, typeName, memberName);
separator = ", ";
}
if (scala) {
out.println("): %s = {", outParams.size() == 0 ? "Unit" : outParams.size() == 1 ? firstOutParamType : className);
out.println("val %s = new %s", localVar, className);
} else if (kotlin) {
out.println("): %s%s {", outParams.size() == 0 ? "Unit" : outParams.size() == 1 ? firstOutParamType : className, outParams.size() == 1 ? "?" : "");
out.println("val %s = %s()", localVar, className);
} else {
out.println(") {");
out.println("%s %s = new %s();", className, localVar, className);
}
for (ParameterDefinition parameter : procedure.getInParameters()) {
final String setter = getStrategy().getJavaSetterName(parameter, Mode.DEFAULT);
final String arg = (instance && parameter.equals(procedure.getInParameters().get(0))) ? "this" : getStrategy().getJavaMemberName(parameter);
out.println("%s.%s(%s)%s", localVar, setter, arg, semicolon);
}
out.println();
out.println("%s.execute(%s)%s", localVar, instance ? "configuration()" : configurationArgument, semicolon);
if (outParams.size() > 0) {
final ParameterDefinition parameter = outParams.get(0);
// Avoid disambiguation for RETURN_VALUE getter
final String getter = parameter == procedure.getReturnValue() ? "getReturnValue" : getStrategy().getJavaGetterName(parameter, Mode.DEFAULT);
final boolean isUDT = parameter.getType(resolver(out)).isUDT();
if (instance) {
// [#3117] Avoid funny call-site ambiguity if this is a UDT that is implemented by an interface
if (generateInterfaces() && isUDT) {
final String columnTypeInterface = out.ref(getJavaType(parameter.getType(resolver(out, Mode.INTERFACE)), out, Mode.INTERFACE));
if (scala)
out.println("from(%s.%s.asInstanceOf[%s])", localVar, getter, columnTypeInterface);
else if (kotlin)
out.println("from(%s.%s() as %s);", localVar, getter, columnTypeInterface);
else
out.println("from((%s) %s.%s());", columnTypeInterface, localVar, getter);
} else {
out.println("from(%s.%s%s)%s", localVar, getter, emptyparens, semicolon);
}
}
if (outParams.size() == 1)
out.println("return %s.%s%s%s", localVar, getter, emptyparens, semicolon);
else if (outParams.size() > 1)
out.println("return %s%s", localVar, semicolon);
}
out.println("}");
}
use of org.jooq.Configuration in project curiostack by curioswitch.
the class DatabaseModule method dbContext.
@Provides
@Singleton
static DSLContext dbContext(DataSource dataSource, @ForDatabase ListeningExecutorService dbExecutor) {
Configuration configuration = new DefaultConfiguration().set(dbExecutor).set(SQLDialect.MYSQL).set(new Settings().withRenderSchema(false)).set(new DataSourceConnectionProvider(dataSource)).set(DatabaseUtil.sfmRecordMapperProvider());
DSLContext ctx = DSL.using(configuration);
// Eagerly trigger JOOQ classinit for better startup performance.
ctx.select().from("curio_server_framework_init").getSQL();
return ctx;
}
use of org.jooq.Configuration in project keywhiz by square.
the class ClientDAO method sawClient.
public void sawClient(Client client, @Nullable Principal principal) {
Instant now = Instant.now();
Instant lastSeen = Optional.ofNullable(client.getLastSeen()).map(ls -> Instant.ofEpochSecond(ls.toEpochSecond())).orElse(EPOCH);
final Instant expiration;
if (principal instanceof CertificatePrincipal) {
expiration = ((CertificatePrincipal) principal).getCertificateExpiration();
} else {
expiration = EPOCH;
}
// this way we can have less granularity on lastSeen and save DB writes
if (now.isAfter(lastSeen.plus(LAST_SEEN_THRESHOLD))) {
dslContext.transaction(configuration -> {
Param<Long> lastSeenValue = DSL.val(now.getEpochSecond(), CLIENTS.LASTSEEN);
Param<Long> expirationValue = DSL.val(expiration.getEpochSecond(), CLIENTS.EXPIRATION);
DSL.using(configuration).update(CLIENTS).set(CLIENTS.LASTSEEN, when(CLIENTS.LASTSEEN.isNull(), lastSeenValue).otherwise(greatest(CLIENTS.LASTSEEN, lastSeenValue))).set(CLIENTS.EXPIRATION, expirationValue).where(CLIENTS.ID.eq(client.getId())).execute();
});
}
}
use of org.jooq.Configuration in project SimpleFlatMapper by arnaudroger.
the class JooqUnmapperTest method testUnmapping.
@Test
public void testUnmapping() throws Exception {
Connection conn = DbHelper.objectDb();
Configuration cfg = new DefaultConfiguration().set(conn).set(SQLDialect.HSQLDB);
cfg.set(JooqMapperFactory.newInstance().newRecordUnmapperProvider(new DSLContextProvider() {
@Override
public DSLContext provide() {
return DSL.using(cfg);
}
}));
DSLContext dsl = DSL.using(cfg);
Label label = new Label(1, UUID.randomUUID(), "label", false);
LabelsRecord labelsRecord = dsl.newRecord(Labels.LABELS, label);
assertEquals(label.getId(), labelsRecord.getId());
assertEquals(label.getName(), labelsRecord.getName());
assertEquals(label.getUuid(), labelsRecord.getUuid());
assertEquals(label.getObsolete(), labelsRecord.getObsolete());
}
Aggregations