Skip to content

Instantly share code, notes, and snippets.

View brunkb's full-sized avatar

Ben Brunk brunkb

  • Minnesota
View GitHub Profile
@brunkb
brunkb / PricingService.groovy
Last active August 29, 2015 14:12
Solving Tricky Problems With the Help of Groovy Closures
class InventorySystem {
boolean open(String token) {
// open a socket connection to some back-end mainframe system
println "opening connection to mainframe, token: ${token}"
true
}
BigDecimal pricingLookup(String clientId, String itemUuid)
{
@brunkb
brunkb / InventorySystem.groovy
Created January 6, 2015 05:11
Mock Inventory System
class InventorySystem {
boolean open(String token) {
// open a socket connection to some back-end mainframe system
println "opening connection to mainframe, token: ${token}"
true
}
BigDecimal pricingLookup(String clientId, String itemUuid)
{
@brunkb
brunkb / AuthenticationProvider.groovy
Created January 6, 2015 05:12
Mock Authentication Provider
class AuthenticationProvider {
String authenticateUser(String username, String password) {
"validToken"
}
}
@brunkb
brunkb / InventoryApiConnectionFactory.groovy
Last active August 29, 2015 14:12
The meat of the example
class InventoryApiConnectionFactory {
// these properties would ordinarily be injected
def authenticationProvider = new AuthenticationProvider()
String username = "username"
String password = "password"
def logError(String msg) { println msg } // simulated logger
def withInventoryConnection(Closure c) {
@brunkb
brunkb / PricingService.groovy
Created January 6, 2015 05:14
The PricingService
class PricingService {
// would be injected
InventoryApiConnectionFactory fac = new InventoryApiConnectionFactory()
def priceLookup(String clientId, String itemUUID) {
fac.withInventoryConnection { connection ->
connection.pricingLookup(clientId, itemUUID)
}
@brunkb
brunkb / DriverCode.groovy
Created January 6, 2015 05:15
Driver code
PricingService ps = new PricingService() // probably injected into a controller if this isn't a batch app
println ps.priceLookup("client1", "item-11-22-33")
class PricingServiceFirstTry {
// these dependencies would normally be injected
AuthenticationProvider auth = new AuthenticationProvider()
InventorySystem inv = new InventorySystem()
String username = 'test'
String password = 'test'
def logError(String msg) { println msg } // simulated logger
@brunkb
brunkb / clob_advanced_update.sql
Last active August 29, 2015 14:22
CLOB Advanced Update
INSERT INTO myclobs (data, date_created) VALUES('<attrs><attr name="name"><string>Barney</string></attr></attrs>',
SYSDATE);
UPDATE myclobs m SET data=UPDATEXML(
XMLTYPE.createXML(data),'/attrs/attr[@name="name"]/string /text()','Gumble').getClobVal()
WHERE m.id=26;
update myclobs set data = '{ "changingTheJSON": "Test" }' where id=2
@brunkb
brunkb / clob_delete.sql
Created June 8, 2015 04:06
Delete CLOB
DELETE FROM myclobs where id=21