use of org.jooq.DSLContext in project waltz by khartec.
the class SoftwarePackageGenerator method main.
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
SoftwarePackageDao softwarePackageDao = ctx.getBean(SoftwarePackageDao.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
List<SoftwarePackage> softwarePackages = ListUtilities.builder(SoftwarePackage.class).addAll(DatabaseSoftwarePackages.dbs).addAll(AppServerSoftwarePackages.appServers).addAll(MiddlewareSoftwarePackages.middleware).build();
System.out.println("-- deleting all software packages");
dsl.deleteFrom(SOFTWARE_PACKAGE).where(SOFTWARE_PACKAGE.PROVENANCE.eq(SampleDataUtilities.SAMPLE_DATA_PROVENANCE)).execute();
System.out.println(" -- storing packages ( " + softwarePackages.size() + " )");
softwarePackageDao.bulkStore(softwarePackages);
System.out.println(" -- done");
}
use of org.jooq.DSLContext in project waltz by khartec.
the class SoftwareUsageGenerator method main.
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
SoftwarePackageDao softwarePackageDao = ctx.getBean(SoftwarePackageDao.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
ApplicationDao applicationDao = ctx.getBean(ApplicationDao.class);
List<SoftwarePackage> allSoftware = softwarePackageDao.findAll();
List<SoftwareUsageRecord> records = applicationDao.getAll().stream().flatMap(app -> IntStream.range(0, new Random().nextInt(4) + 1).mapToObj(x -> new SoftwareUsageRecord(app.id().get(), ListUtilities.randomPick(allSoftware).id().get(), "waltz-random"))).collect(Collectors.toList());
System.out.println("-- deleting all software usages");
dsl.deleteFrom(SOFTWARE_USAGE).where(SOFTWARE_USAGE.PROVENANCE.eq("waltz-sample")).execute();
System.out.println(" -- storing usages ( " + records.size() + " )");
dsl.batchInsert(records).execute();
System.out.println(" -- done");
}
use of org.jooq.DSLContext in project jOOQ by jOOQ.
the class Example_1_5_ColumnExpressions method run.
@Test
public void run() {
DSLContext dsl = DSL.using(connection());
Tools.title("CONCAT() function with prefix notation");
Tools.print(dsl.select(concat(AUTHOR.FIRST_NAME, val(" "), AUTHOR.LAST_NAME)).from(AUTHOR).orderBy(AUTHOR.ID).fetch());
Tools.title("CONCAT() function with infix notation");
Tools.print(dsl.select(AUTHOR.FIRST_NAME.concat(" ").concat(AUTHOR.LAST_NAME)).from(AUTHOR).orderBy(AUTHOR.ID).fetch());
}
use of org.jooq.DSLContext in project jOOQ by jOOQ.
the class LicenseService method run.
// -------------------------------------------------------------------------
// Utilities
// -------------------------------------------------------------------------
/**
* This method encapsulates a transaction and initialises a jOOQ DSLcontext.
* This could also be achieved with Spring and DBCP for connection pooling.
*/
private String run(CtxRunnable runnable) {
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = getConnection("jdbc:postgresql:postgres", "postgres", System.getProperty("pw", "test"));
DSLContext ctx = DSL.using(new DefaultConfiguration().set(new DefaultConnectionProvider(c)).set(SQLDialect.POSTGRES).set(new Settings().withExecuteLogging(false)));
return runnable.run(ctx);
} catch (Exception e) {
e.printStackTrace();
Response.status(Status.SERVICE_UNAVAILABLE);
return "Service Unavailable - Please contact support@datageekery.com for help";
} finally {
JDBCUtils.safeClose(c);
}
}
use of org.jooq.DSLContext in project jOOQ by jOOQ.
the class SparkCRUD method main.
public static void main(String[] args) throws Exception {
final BasicDataSource ds = new BasicDataSource();
final Properties properties = new Properties();
properties.load(SparkCRUD.class.getResourceAsStream("/config.properties"));
ds.setDriverClassName(properties.getProperty("db.driver"));
ds.setUrl(properties.getProperty("db.url"));
ds.setUsername(properties.getProperty("db.username"));
ds.setPassword(properties.getProperty("db.password"));
final DSLContext ctx = DSL.using(ds, SQLDialect.H2);
// Creates a new book resource, will return the ID to the created resource
// author and title are sent as query parameters e.g. /books?author=Foo&title=Bar
post("/books", (request, response) -> {
AuthorRecord author = upsertAuthor(ctx, request);
BookRecord book = ctx.newRecord(BOOK);
book.setAuthorId(author.getId());
book.setTitle(request.queryParams("title"));
book.store();
// 201 Created
response.status(201);
return book.getId();
});
// Gets the book resource for the provided id
get("/books/:id", (request, response) -> {
Record2<String, String> book = ctx.select(BOOK.TITLE, AUTHOR.NAME).from(BOOK).join(AUTHOR).on(BOOK.AUTHOR_ID.eq(AUTHOR.ID)).where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).fetchOne();
if (book != null) {
return "Title: " + book.value1() + ", Author: " + book.value2();
} else {
// 404 Not found
response.status(404);
return "Book not found";
}
});
// Updates the book resource for the provided id with new information
// author and title are sent as query parameters e.g. /books/<id>?author=Foo&title=Bar
put("/books/:id", (request, response) -> {
BookRecord book = ctx.selectFrom(BOOK).where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).fetchOne();
if (book != null) {
AuthorRecord author = upsertAuthor(ctx, request);
String newAuthor = request.queryParams("author");
String newTitle = request.queryParams("title");
if (newAuthor != null) {
book.setAuthorId(author.getId());
}
if (newTitle != null) {
book.setTitle(newTitle);
}
book.update();
return "Book with id '" + book.getId() + "' updated";
} else {
// 404 Not found
response.status(404);
return "Book not found";
}
});
// Deletes the book resource for the provided id
delete("/books/:id", (request, response) -> {
BookRecord book = ctx.deleteFrom(BOOK).where(BOOK.ID.eq(BOOK.ID.getDataType().convert(request.params(":id")))).returning().fetchOne();
if (book != null) {
return "Book with id '" + book.getId() + "' deleted";
} else {
// 404 Not found
response.status(404);
return "Book not found";
}
});
// Gets all available book resources (id's)
get("/books", (request, response) -> {
return ctx.select(BOOK.ID).from(BOOK).fetch(BOOK.ID).stream().map(Object::toString).collect(Collectors.joining(" "));
});
}
Aggregations