repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/NullArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/NullArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; class NullArgument implements Argument { private final int sqlType; NullArgument(int sqlType) { this.sqlType = sqlType; } @Override public void apply(final int position, PreparedStatement statement, StatementContext ctx) throws SQLException { statement.setNull(position, sqlType); } @Override public String toString() { return "NULL"; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Binding.java
jdbi/src/main/java/org/skife/jdbi/v2/Binding.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import org.skife.jdbi.v2.tweak.NamedArgumentFinder; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Represents the arguments bound to a particular statement */ public class Binding { private Map<Integer, Argument> positionals = new HashMap<Integer, Argument>(); private Map<String, Argument> named = new HashMap<String, Argument>(); private List<NamedArgumentFinder> namedArgumentFinder = new ArrayList<NamedArgumentFinder>(); void addPositional(int position, Argument parameter) { positionals.put(position, parameter); } /** * Look up an argument by name * * @param name the key to lookup the value of * * @return the bound Argument */ public Argument forName(String name) { if (named.containsKey(name)) { return named.get(name); } else { for (NamedArgumentFinder arguments : namedArgumentFinder) { Argument arg = arguments.find(name); if (arg != null) { return arg; } } } return null; } /** * Look up an argument by position * * @param position starts at 0, not 1 * * @return argument bound to that position */ public Argument forPosition(int position) { return positionals.get(position); } void addNamed(String name, Argument argument) { this.named.put(name, argument); } void addNamedArgumentFinder(NamedArgumentFinder args) { namedArgumentFinder.add(args); } @Override public String toString() { boolean wrote = false; StringBuilder b = new StringBuilder(); b.append("{ positional:{"); for (Map.Entry<Integer, Argument> entry : positionals.entrySet()) { wrote = true; b.append(entry.getKey()).append(":").append(entry.getValue()).append(","); } if (wrote) { wrote = false; b.deleteCharAt(b.length() - 1); } b.append("}"); b.append(", named:{"); for (Map.Entry<String, Argument> entry : named.entrySet()) { wrote = true; b.append(entry.getKey()).append(":").append(entry.getValue()).append(","); } if (wrote) { wrote = false; b.deleteCharAt(b.length() - 1); } b.append("}"); b.append(", finder:["); for (NamedArgumentFinder argument : namedArgumentFinder) { wrote = true; b.append(argument).append(","); } if (wrote) { b.deleteCharAt(b.length() - 1); } b.append("]"); b.append("}"); return b.toString(); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ObjectArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/ObjectArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; class ObjectArgument implements Argument { private final Object value; ObjectArgument(Object value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setObject(position, value); } else { statement.setNull(position, Types.NULL); } } @Override public String toString() { return String.valueOf(value); } public Object getValue() { return value; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/SQLStatement.java
jdbi/src/main/java/org/skife/jdbi/v2/SQLStatement.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.ResultSetException; import org.skife.jdbi.v2.exceptions.UnableToCreateStatementException; import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; import org.skife.jdbi.v2.tweak.Argument; import org.skife.jdbi.v2.tweak.ArgumentFactory; import org.skife.jdbi.v2.tweak.ContainerFactory; import org.skife.jdbi.v2.tweak.NamedArgumentFinder; import org.skife.jdbi.v2.tweak.RewrittenStatement; import org.skife.jdbi.v2.tweak.SQLLog; import org.skife.jdbi.v2.tweak.StatementBuilder; import org.skife.jdbi.v2.tweak.StatementCustomizer; import org.skife.jdbi.v2.tweak.StatementLocator; import org.skife.jdbi.v2.tweak.StatementRewriter; import java.io.InputStream; import java.io.Reader; import java.math.BigDecimal; import java.net.URL; import java.sql.Blob; import java.sql.Clob; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; import java.sql.Types; import java.util.ArrayList; import java.util.Collection; import java.util.Map; /** * This class provides the common functions between <code>Query</code> and * <code>Update</code>. It defines most of the argument binding functions * used by its subclasses. */ public abstract class SQLStatement<SelfType extends SQLStatement<SelfType>> extends BaseStatement { private final Binding params; private final Handle handle; private final String sql; private final StatementBuilder statementBuilder; private final Collection<StatementCustomizer> customizers = new ArrayList<StatementCustomizer>(); private StatementLocator locator; private StatementRewriter rewriter; /** * This will be set on execution, not before */ private RewrittenStatement rewritten; private PreparedStatement stmt; private final SQLLog log; private final TimingCollector timingCollector; private final ContainerFactoryRegistry containerMapperRegistry; SQLStatement(Binding params, StatementLocator locator, StatementRewriter rewriter, Handle handle, StatementBuilder statementBuilder, String sql, ConcreteStatementContext ctx, SQLLog log, TimingCollector timingCollector, Collection<StatementCustomizer> statementCustomizers, Foreman foreman, ContainerFactoryRegistry containerFactoryRegistry) { super(ctx, foreman); // [OPTIMIZATION] Costly check //assert verifyOurNastyDowncastIsOkay(); addCustomizers(statementCustomizers); this.log = log; this.statementBuilder = statementBuilder; this.rewriter = rewriter; this.handle = handle; this.sql = sql; this.timingCollector = timingCollector; this.params = params; this.locator = locator; this.containerMapperRegistry = containerFactoryRegistry.createChild(); ctx.setConnection(handle.getConnection()); ctx.setRawSql(sql); ctx.setBinding(params); } protected ContainerFactoryRegistry getContainerMapperRegistry() { return containerMapperRegistry; } public SelfType registerContainerFactory(ContainerFactory<?> containerFactory) { this.getContainerMapperRegistry().register(containerFactory); return (SelfType) this; } public SelfType registerArgumentFactory(ArgumentFactory<?> argumentFactory) { //getForeman().register(argumentFactory); //return (SelfType) this; throw new UnsupportedOperationException("[OPTIMIZATION] Registering a custom ArgumentFactory on a SQLStatement is disabled"); } /** * Override the statement locator used for this statement */ public void setStatementLocator(StatementLocator locator) { this.locator = locator; } /** * Exactly the same as setStatementLocator but returns self. */ public SelfType setStatementLocator2(StatementLocator locator) { setStatementLocator(locator); return (SelfType) this; } /** * Override the statement rewriter used for this statement */ public void setStatementRewriter(StatementRewriter rewriter) { this.rewriter = rewriter; } /** * Exactly the same as setStatementRewriter but returns self */ public SelfType setStatementRewriter2(StatementRewriter rewriter) { setStatementRewriter(rewriter); return (SelfType) this; } /** * Define a value on the {@link StatementContext}. * * @param key Key to access this value from the StatementContext * @param value Value to setAttribute on the StatementContext * * @return this */ @SuppressWarnings("unchecked") public SelfType define(String key, Object value) { getContext().setAttribute(key, value); return (SelfType) this; } /** * Adds all key/value pairs in the Map to the {@link StatementContext}. * * @param values containing key/value pairs. * * @return this */ @SuppressWarnings("unchecked") public SelfType define(final Map<String, ? extends Object> values) { final StatementContext context = getContext(); if (values != null) { for (Map.Entry<String, ? extends Object> entry : values.entrySet()) { context.setAttribute(entry.getKey(), entry.getValue()); } } return (SelfType) this; } /** * Provides a means for custom statement modification. Common cusotmizations * have their own methods, such as {@link Query#setMaxRows(int)} * * @param customizer instance to be used to cstomize a statement * * @return modified statement */ @SuppressWarnings("unchecked") public SelfType addStatementCustomizer(StatementCustomizer customizer) { super.addCustomizer(customizer); return (SelfType) this; } private boolean verifyOurNastyDowncastIsOkay() { if (this.getClass().getTypeParameters().length == 0) { return true; } else { Class<?> parameterized_type = this.getClass().getTypeParameters()[0].getGenericDeclaration(); return parameterized_type.isAssignableFrom(this.getClass()); } } protected StatementBuilder getStatementBuilder() { return statementBuilder; } protected StatementLocator getStatementLocator() { return this.locator; } protected StatementRewriter getRewriter() { return rewriter; } protected Binding getParams() { return params; } protected Handle getHandle() { return handle; } /** * The un-translated SQL used to create this statement */ protected String getSql() { return sql; } protected Binding getParameters() { return params; } /** * Set the query timeout, in seconds, on the prepared statement * * @param seconds number of seconds before timing out * * @return the same instance */ public SelfType setQueryTimeout(final int seconds) { return addStatementCustomizer(new StatementCustomizers.QueryTimeoutCustomizer(seconds)); } /** * Close the handle when the statement is closed. */ @SuppressWarnings("unchecked") public SelfType cleanupHandle() { super.addCleanable(Cleanables.forHandle(handle, TransactionState.ROLLBACK)); return (SelfType) this; } /** * Force transaction state when the statement is cleaned up. */ public SelfType cleanupHandle(final TransactionState state) { super.addCleanable(Cleanables.forHandle(handle, state)); return (SelfType) this; } /** * Used if you need to have some exotic parameter bound. * * @param position position to bindBinaryStream this argument, starting at 0 * @param argument exotic argument factory * * @return the same Query instance */ @SuppressWarnings("unchecked") public SelfType bind(int position, Argument argument) { getParams().addPositional(position, argument); return (SelfType) this; } /** * Used if you need to have some exotic parameter bound. * * @param name name to bindBinaryStream this argument * @param argument exotic argument factory * * @return the same Query instance */ @SuppressWarnings("unchecked") public SelfType bind(String name, Argument argument) { getParams().addNamed(name, argument); return (SelfType) this; } /** * Binds named parameters from JavaBean properties on o. * * @param o source of named parameter values to use as arguments * * @return modified statement */ public SelfType bindFromProperties(Object o) { return bindNamedArgumentFinder(new BeanPropertyArguments(o, getContext(), getForeman())); } /** * Binds named parameters from a map of String to Object instances * * @param args map where keys are matched to named parameters in order to bind arguments. * Can be null, in this case, the binding has no effect. * * @return modified statement */ @SuppressWarnings("unchecked") public SelfType bindFromMap(Map<String, ? extends Object> args) { if (args != null) { return bindNamedArgumentFinder(new MapArguments(getForeman(), getContext(), args)); } else { return (SelfType) this; } } /** * Binds a new {@link NamedArgumentFinder}. * * @param namedArgumentFinder A NamedArgumentFinder to bind. Can be null. */ @SuppressWarnings("unchecked") public SelfType bindNamedArgumentFinder(final NamedArgumentFinder namedArgumentFinder) { if (namedArgumentFinder != null) { getParams().addNamedArgumentFinder(namedArgumentFinder); } return (SelfType) this; } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Character value) { return bind(position, getForeman().waffle(Character.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the parameter to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Character value) { return bind(name, getForeman().waffle(Character.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, String value) { return bind(position, getForeman().waffle(String.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, String value) { return bind(name, getForeman().waffle(String.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, int value) { return bind(position, getForeman().waffle(int.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Integer value) { return bind(position, getForeman().waffle(Integer.class, value, getContext())); } /** * Bind an argument by name * * @param name name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, int value) { return bind(name, getForeman().waffle(int.class, value, getContext())); } /** * Bind an argument by name * * @param name name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Integer value) { return bind(name, getForeman().waffle(Integer.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, char value) { return bind(position, getForeman().waffle(char.class, value, getContext())); } /** * Bind an argument by name * * @param name name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, char value) { return bind(name, getForeman().waffle(char.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * @param length how long is the stream being bound? * * @return the same Query instance */ public final SelfType bindASCIIStream(int position, InputStream value, int length) { return bind(position, new InputStreamArgument(value, length, true)); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * @param length bytes to read from value * * @return the same Query instance */ public final SelfType bindASCIIStream(String name, InputStream value, int length) { return bind(name, new InputStreamArgument(value, length, true)); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, BigDecimal value) { return bind(position, getForeman().waffle(BigDecimal.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, BigDecimal value) { return bind(name, getForeman().waffle(BigDecimal.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bindBinaryStream(int position, InputStream value, int length) { return bind(position, new InputStreamArgument(value, length, false)); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * @param length bytes to read from value * * @return the same Query instance */ public final SelfType bindBinaryStream(String name, InputStream value, int length) { return bind(name, new InputStreamArgument(value, length, false)); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Blob value) { return bind(position, getForeman().waffle(Blob.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Blob value) { return bind(name, getForeman().waffle(Blob.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, boolean value) { return bind(position, getForeman().waffle(boolean.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Boolean value) { return bind(position, getForeman().waffle(Boolean.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, boolean value) { return bind(name, getForeman().waffle(boolean.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Boolean value) { return bind(name, getForeman().waffle(Boolean.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bindAsInt(int position, boolean value) { return bind(position, new BooleanIntegerArgument(value)); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bindAsInt(int position, Boolean value) { if (value != null) { return bind(position, new BooleanIntegerArgument(value)); } else { return bind(position, new NullArgument(Types.INTEGER)); } } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bindAsInt(String name, boolean value) { return bind(name, new BooleanIntegerArgument(value)); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bindAsInt(String name, Boolean value) { if (value != null) { return bind(name, new BooleanIntegerArgument(value)); } else { return bind(name, new NullArgument(Types.INTEGER)); } } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, byte value) { return bind(position, getForeman().waffle(byte.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Byte value) { return bind(position, getForeman().waffle(Byte.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, byte value) { return bind(name, getForeman().waffle(byte.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Byte value) { return bind(name, getForeman().waffle(Byte.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, byte[] value) { return bind(position, getForeman().waffle(byte[].class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, byte[] value) { return bind(name, getForeman().waffle(byte[].class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * @param length number of characters to read * * @return the same Query instance */ public final SelfType bind(int position, Reader value, int length) { return bind(position, new CharacterStreamArgument(value, length)); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * @param length number of characters to read * * @return the same Query instance */ public final SelfType bind(String name, Reader value, int length) { return bind(name, new CharacterStreamArgument(value, length)); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Clob value) { return bind(position, getForeman().waffle(Clob.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Clob value) { return bind(name, getForeman().waffle(Clob.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, java.sql.Date value) { return bind(position, getForeman().waffle(java.sql.Date.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, java.sql.Date value) { return bind(name, getForeman().waffle(java.sql.Date.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, java.util.Date value) { return bind(position, getForeman().waffle(java.util.Date.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, java.util.Date value) { return bind(name, getForeman().waffle(java.util.Date.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, double value) { return bind(position, getForeman().waffle(double.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Double value) { return bind(position, getForeman().waffle(Double.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, double value) { return bind(name, getForeman().waffle(double.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Double value) { return bind(name, getForeman().waffle(Double.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, float value) { return bind(position, getForeman().waffle(float.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Float value) { return bind(position, getForeman().waffle(Float.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, float value) { return bind(name, getForeman().waffle(float.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Float value) { return bind(name, getForeman().waffle(Float.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, long value) { return bind(position, getForeman().waffle(long.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Long value) { if (value != null) { return bind(position, getForeman().waffle(Long.class, value, getContext())); } else { return bind(position, new NullArgument(Types.BIGINT)); } } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, long value) { return bind(name, getForeman().waffle(long.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Long value) { return bind(name, getForeman().waffle(Long.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Short value) { return bind(position, getForeman().waffle(Short.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, short value) { return bind(position, getForeman().waffle(short.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, short value) { return bind(name, getForeman().waffle(short.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Short value) { return bind(name, getForeman().waffle(short.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Object value) { return bind(position, getForeman().waffle(value != null ? value.getClass() : Object.class, value, getContext())); } /** * Bind an argument by name * * @param name token name to bind the paramater to * @param value to bind * * @return the same Query instance */ public final SelfType bind(String name, Object value) { return bind(name, getForeman().waffle(value != null ? value.getClass() : Object.class, value, getContext())); } /** * Bind an argument positionally * * @param position position to bind the paramater at, starting at 0 * @param value to bind * * @return the same Query instance */ public final SelfType bind(int position, Time value) { return bind(position, getForeman().waffle(Time.class, value, getContext())); } /**
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
true
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Batch.java
jdbi/src/main/java/org/skife/jdbi/v2/Batch.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.UnableToCreateStatementException; import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; import org.skife.jdbi.v2.tweak.SQLLog; import org.skife.jdbi.v2.tweak.StatementRewriter; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * Represents a group of non-prepared statements to be sent to the RDMBS in one "request" */ public class Batch extends BaseStatement { private List<String> parts = new ArrayList<String>(); private final StatementRewriter rewriter; private final Connection connection; private final SQLLog log; private final TimingCollector timingCollector; Batch(StatementRewriter rewriter, Connection connection, Map<String, Object> globalStatementAttributes, SQLLog log, TimingCollector timingCollector, Foreman foreman) { super(new ConcreteStatementContext(globalStatementAttributes), foreman); this.rewriter = rewriter; this.connection = connection; this.log = log; this.timingCollector = timingCollector; } /** * Add a statement to the batch * * @param sql SQL to be added to the batch, possibly a named statement * @return the same Batch statement */ public Batch add(String sql) { parts.add(sql); return this; } /** * Specify a value on the statement context for this batch * * @return self */ public Batch define(String key, Object value) { getContext().setAttribute(key, value); return this; } /** * Execute all the queued up statements * * @return an array of integers representing the return values from each statement's execution */ public int[] execute() { // short circuit empty batch if (parts.size() == 0) { return new int[] {}; } Binding empty = new Binding(); Statement stmt = null; try { try { stmt = connection.createStatement(); addCleanable(Cleanables.forStatement(stmt)); } catch (SQLException e) { throw new UnableToCreateStatementException(e, getContext()); } final SQLLog.BatchLogger logger = log.logBatch(); try { for (String part : parts) { final String sql = rewriter.rewrite(part, empty, getContext()).getSql(); logger.add(sql); stmt.addBatch(sql); } } catch (SQLException e) { throw new UnableToExecuteStatementException("Unable to configure JDBC statement", e, getContext()); } try { final long start = System.nanoTime(); final int[] rs = stmt.executeBatch(); final long elapsedTime = System.nanoTime() - start; logger.log(elapsedTime / 1000000L); // Null for statement, because for batches, we don't really have a good way to keep the sql around. timingCollector.collect(elapsedTime, getContext()); return rs; } catch (SQLException e) { throw new UnableToExecuteStatementException(e, getContext()); } } finally { cleanup(); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/BooleanArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/BooleanArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; class BooleanArgument implements Argument { private final Boolean value; BooleanArgument(Boolean value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value == null) { statement.setNull(position, Types.BOOLEAN); } else { statement.setBoolean(position, value); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/EnumArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/EnumArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; class EnumArgument<T extends Enum<T>> implements Argument { private final T value; public EnumArgument(T value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value == null) { statement.setNull(position, Types.VARCHAR); } else { statement.setString(position, value.name()); } } @Override public String toString() { return value != null ? value.toString() : "<null>"; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/IDBI.java
jdbi/src/main/java/org/skife/jdbi/v2/IDBI.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.CallbackFailedException; import org.skife.jdbi.v2.tweak.HandleCallback; /** * An interface for {@link DBI} instances for systems which like * to work with interfaces. */ public interface IDBI { /** * Obtain a Handle to the data source wrapped by this DBI instance * * @return an open Handle instance * * @see org.skife.jdbi.v2.DBI#open() */ Handle open(); /** * Define an attribute on every {@link StatementContext} for every statement created * from a handle obtained from this DBI instance. * * @param key The key for the attribute * @param value the value for the attribute */ void define(String key, Object value); /** * A convenience function which manages the lifecycle of a handle and yields it to a callback * for use by clients. * * @param callback A callback which will receive an open Handle * * @return the value returned by callback * * @throws CallbackFailedException Will be thrown if callback raises an exception. This exception will * wrap the exception thrown by the callback. */ <ReturnType> ReturnType withHandle(HandleCallback<ReturnType> callback) throws CallbackFailedException; /** * A convenience function which manages the lifecycle of a handle and yields it to a callback * for use by clients. The handle will be in a transaction when the callback is invoked, and * that transaction will be committed if the callback finishes normally, or rolled back if the * callback raises an exception. * * @param callback A callback which will receive an open Handle, in a transaction * * @return the value returned by callback * * @throws CallbackFailedException Will be thrown if callback raises an exception. This exception will * wrap the exception thrown by the callback. */ <ReturnType> ReturnType inTransaction(TransactionCallback<ReturnType> callback) throws CallbackFailedException; /** * A convenience function which manages the lifecycle of a handle and yields it to a callback * for use by clients. The handle will be in a transaction when the callback is invoked, and * that transaction will be committed if the callback finishes normally, or rolled back if the * callback raises an exception. * * @param isolation The transaction isolation level to set * @param callback A callback which will receive an open Handle, in a transaction * * @return the value returned by callback * * @throws CallbackFailedException Will be thrown if callback raises an exception. This exception will * wrap the exception thrown by the callback. */ <ReturnType> ReturnType inTransaction(TransactionIsolationLevel isolation, TransactionCallback<ReturnType> callback) throws CallbackFailedException; /** * Open a handle and attach a new sql object of the specified type to that handle. Be sure to close the * sql object (via a close() method, or calling {@link IDBI#close(Object)} * @param sqlObjectType an interface with annotations declaring desired behavior * @param <SqlObjectType> * @return a new sql object of the specified type, with a dedicated handle */ <SqlObjectType> SqlObjectType open(Class<SqlObjectType> sqlObjectType); /** * Create a new sql object which will obtain and release connections from this dbi instance, as it needs to, * and can, respectively. You should not explicitely close this sql object * * @param sqlObjectType an interface with annotations declaring desired behavior * @param <SqlObjectType> * @return a new sql object of the specified type, with a dedicated handle */ <SqlObjectType> SqlObjectType onDemand(Class<SqlObjectType> sqlObjectType); /** * Used to close a sql object which lacks a close() method. * @param sqlObject the sql object to close */ void close(Object sqlObject); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/SqlDateArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/SqlDateArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.Date; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * */ class SqlDateArgument implements Argument { private final Date value; SqlDateArgument(Date value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setDate(position, value); } else { statement.setNull(position, Types.DATE); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/DefaultMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/DefaultMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.ResultSetException; import org.skife.jdbi.v2.tweak.ResultSetMapper; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; public class DefaultMapper implements ResultSetMapper<Map<String, Object>> { @Override public Map<String, Object> map(int index, ResultSet r, StatementContext ctx) { Map<String, Object> row = new DefaultResultMap(); ResultSetMetaData m; try { m = r.getMetaData(); } catch (SQLException e) { throw new ResultSetException("Unable to obtain metadata from result set", e, ctx); } try { for (int i = 1; i <= m.getColumnCount(); i ++) { String key = m.getColumnName(i); String alias = m.getColumnLabel(i); Object value = r.getObject(i); row.put(alias != null ? alias : key, value); } } catch (SQLException e) { throw new ResultSetException("Unable to access specific metadata from " + "result set metadata", e, ctx); } return row; } private static class DefaultResultMap extends HashMap<String, Object> { public static final long serialVersionUID = 1L; @Override public Object get(Object o) { return super.get(((String)o).toLowerCase()); } @Override public Object put(String key, Object value) { return super.put(key.toLowerCase(), value); } @Override public boolean containsKey(Object key) { return super.containsKey(((String)key).toLowerCase()); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/MapArguments.java
jdbi/src/main/java/org/skife/jdbi/v2/MapArguments.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import org.skife.jdbi.v2.tweak.NamedArgumentFinder; import java.util.LinkedHashMap; import java.util.Map; /** * Binds all fields of a map as arguments. */ class MapArguments implements NamedArgumentFinder { private final Foreman foreman; private final StatementContext ctx; private final Map<String, ? extends Object> args; MapArguments(Foreman foreman, StatementContext ctx, Map<String, ? extends Object> args) { this.foreman = foreman; this.ctx = ctx; this.args = args; } @Override public Argument find(String name) { if (args.containsKey(name)) { final Object argument = args.get(name); final Class<? extends Object> argumentClass = argument == null ? Object.class : argument.getClass(); return foreman.waffle(argumentClass, argument, ctx); } else { return null; } } @Override public String toString() { return new LinkedHashMap<String, Object>(args).toString(); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ReflectionBeanMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/ReflectionBeanMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.ResultSetMapper; import java.lang.reflect.Field; import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; import java.util.Date; /** * A result set mapper which maps the fields in a statement into a JavaBean. This uses * the reflection to set the fields on the bean including its super class fields, it does not support nested properties. */ public class ReflectionBeanMapper<T> implements ResultSetMapper<T> { private final Class<T> type; private final Map<String, Field> properties = new HashMap<String, Field>(); public ReflectionBeanMapper(Class<T> type) { this.type = type; cacheAllFieldsIncludingSuperClass(type); } private void cacheAllFieldsIncludingSuperClass(Class<T> type) { Class aClass = type; while(aClass != null) { for (Field field : aClass.getDeclaredFields()) { properties.put(field.getName().toLowerCase(), field); } aClass = aClass.getSuperclass(); } } @Override @SuppressWarnings({"unchecked", "rawtypes"}) public T map(int row, ResultSet rs, StatementContext ctx) throws SQLException { T bean; try { bean = type.newInstance(); } catch (Exception e) { throw new IllegalArgumentException(String.format("A bean, %s, was mapped " + "which was not instantiable", type.getName()), e); } ResultSetMetaData metadata = rs.getMetaData(); for (int i = 1; i <= metadata.getColumnCount(); ++i) { String name = metadata.getColumnLabel(i).toLowerCase(); Field field = properties.get(name); if (field != null) { Class type = field.getType(); Object value; if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) { value = rs.getBoolean(i); } else if (type.isAssignableFrom(Byte.class) || type.isAssignableFrom(byte.class)) { value = rs.getByte(i); } else if (type.isAssignableFrom(Short.class) || type.isAssignableFrom(short.class)) { value = rs.getShort(i); } else if (type.isAssignableFrom(Integer.class) || type.isAssignableFrom(int.class)) { value = rs.getInt(i); } else if (type.isAssignableFrom(Long.class) || type.isAssignableFrom(long.class)) { value = rs.getLong(i); } else if (type.isAssignableFrom(Float.class) || type.isAssignableFrom(float.class)) { value = rs.getFloat(i); } else if (type.isAssignableFrom(Double.class) || type.isAssignableFrom(double.class)) { value = rs.getDouble(i); } else if (type.isAssignableFrom(BigDecimal.class)) { value = rs.getBigDecimal(i); } else if (type.isAssignableFrom(Timestamp.class)) { value = rs.getTimestamp(i); } else if (type.isAssignableFrom(Time.class)) { value = rs.getTime(i); } else if (type.isAssignableFrom(Date.class)) { value = rs.getDate(i); } else if (type.isAssignableFrom(String.class)) { value = rs.getString(i); } else if (type.isEnum()) { value = Enum.valueOf(type, rs.getString(i)); } else { value = rs.getObject(i); } if (rs.wasNull() && !type.isPrimitive()) { value = null; } try { field.setAccessible(true); field.set(bean, value); } catch (IllegalAccessException e) { throw new IllegalArgumentException(String.format("Unable to access " + "property, %s", name), e); } } } return bean; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/FoldController.java
jdbi/src/main/java/org/skife/jdbi/v2/FoldController.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.sql.ResultSet; public class FoldController { private boolean abort = false; private final ResultSet resultSet; public FoldController(ResultSet rs) { resultSet = rs; } public void abort() { this.abort = true; } boolean isAborted() { return abort; } public ResultSet getResultSet() { return resultSet; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/TimestampArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/TimestampArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Timestamp; import java.sql.Types; /** * */ class TimestampArgument implements Argument { private final Timestamp value; TimestampArgument(Timestamp value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setTimestamp(position, value); } else { statement.setNull(position, Types.TIMESTAMP); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/HashPrefixStatementRewriter.java
jdbi/src/main/java/org/skife/jdbi/v2/HashPrefixStatementRewriter.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.antlr.runtime.ANTLRStringStream; import org.antlr.runtime.Token; import org.skife.jdbi.rewriter.hash.HashStatementLexer; import org.skife.jdbi.v2.exceptions.UnableToCreateStatementException; import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; import org.skife.jdbi.v2.tweak.Argument; import org.skife.jdbi.v2.tweak.RewrittenStatement; import org.skife.jdbi.v2.tweak.StatementRewriter; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.WeakHashMap; import static org.skife.jdbi.rewriter.hash.HashStatementLexer.DOUBLE_QUOTED_TEXT; import static org.skife.jdbi.rewriter.hash.HashStatementLexer.ESCAPED_TEXT; import static org.skife.jdbi.rewriter.hash.HashStatementLexer.LITERAL; import static org.skife.jdbi.rewriter.hash.HashStatementLexer.NAMED_PARAM; import static org.skife.jdbi.rewriter.hash.HashStatementLexer.POSITIONAL_PARAM; import static org.skife.jdbi.rewriter.hash.HashStatementLexer.QUOTED_TEXT; /** * Statement rewriter which replaces named parameter tokens of the form #tokenName */ public class HashPrefixStatementRewriter implements StatementRewriter { private final Map<String, ParsedStatement> cache = Collections.synchronizedMap(new WeakHashMap<String, ParsedStatement>()); /** * Munge up the SQL as desired. Responsible for figuring out ow to bind any * arguments in to the resultant prepared statement. * * @param sql The SQL to rewrite * @param params contains the arguments which have been bound to this statement. * @param ctx The statement context for the statement being executed * * @return something which can provide the actual SQL to prepare a statement from * and which can bind the correct arguments to that prepared statement */ @Override public RewrittenStatement rewrite(String sql, Binding params, StatementContext ctx) { ParsedStatement stmt = cache.get(sql); if (stmt == null) { try { stmt = parseString(sql); cache.put(sql, stmt); } catch (IllegalArgumentException e) { throw new UnableToCreateStatementException("Exception parsing for named parameter replacement", e, ctx); } } return new MyRewrittenStatement(stmt, ctx); } ParsedStatement parseString(final String sql) throws IllegalArgumentException { ParsedStatement stmt = new ParsedStatement(); StringBuilder b = new StringBuilder(sql.length()); HashStatementLexer lexer = new HashStatementLexer(new ANTLRStringStream(sql)); Token t = lexer.nextToken(); while (t.getType() != HashStatementLexer.EOF) { switch (t.getType()) { case LITERAL: b.append(t.getText()); break; case NAMED_PARAM: stmt.addNamedParamAt(t.getText().substring(1, t.getText().length())); b.append("?"); break; case QUOTED_TEXT: b.append(t.getText()); break; case DOUBLE_QUOTED_TEXT: b.append(t.getText()); break; case POSITIONAL_PARAM: b.append("?"); stmt.addPositionalParamAt(); break; case ESCAPED_TEXT: b.append(t.getText().substring(1)); break; default: break; } t = lexer.nextToken(); } stmt.sql = b.toString(); return stmt; } private static class MyRewrittenStatement implements RewrittenStatement { private final ParsedStatement stmt; private final StatementContext context; MyRewrittenStatement(ParsedStatement stmt, StatementContext ctx) { this.context = ctx; this.stmt = stmt; } @Override public void bind(Binding params, PreparedStatement statement) throws SQLException { if (stmt.positionalOnly) { // no named params, is easy boolean finished = false; for (int i = 0; !finished; ++i) { final Argument a = params.forPosition(i); if (a != null) { try { a.apply(i + 1, statement, this.context); } catch (SQLException e) { throw new UnableToExecuteStatementException( String.format("Exception while binding positional param at (0 based) position %d", i), e, context); } } else { finished = true; } } } else { //List<String> named_params = stmt.params; int i = 0; for (String named_param : stmt.params) { if ("*".equals(named_param)) { continue; } Argument a = params.forName(named_param); if (a == null) { a = params.forPosition(i); } if (a == null) { String msg = String.format("Unable to execute, no named parameter matches " + "\"%s\" and no positional param for place %d (which is %d in " + "the JDBC 'start at 1' scheme) has been set.", named_param, i, i + 1); throw new UnableToExecuteStatementException(msg, context); } try { a.apply(i + 1, statement, this.context); } catch (SQLException e) { throw new UnableToCreateStatementException(String.format("Exception while binding '%s'", named_param), e, context); } i++; } } } @Override public String getSql() { return stmt.getParsedSql(); } } static class ParsedStatement { private String sql; private boolean positionalOnly = true; private List<String> params = new ArrayList<String>(); public void addNamedParamAt(String name) { positionalOnly = false; params.add(name); } public void addPositionalParamAt() { params.add("*"); } public String getParsedSql() { return sql; } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/CallableStatementMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/CallableStatementMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.sql.CallableStatement; import java.sql.SQLException; public interface CallableStatementMapper { Object map(int position, CallableStatement stmt) throws SQLException; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ConcreteStatementContext.java
jdbi/src/main/java/org/skife/jdbi/v2/ConcreteStatementContext.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.lang.reflect.Method; import java.sql.Connection; import java.sql.PreparedStatement; import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; public final class ConcreteStatementContext implements StatementContext { private final Collection<Cleanable> cleanables = new LinkedHashSet<>(); private final Map<String, Object> attributes = new HashMap<>(); private String rawSql; private String rewrittenSql; private String locatedSql; private PreparedStatement statement; private Connection connection; private Binding binding; private Class<?> sqlObjectType; private Method sqlObjectMethod; private boolean returningGeneratedKeys; ConcreteStatementContext(final Map<String, Object> globalAttributes) { attributes.putAll(globalAttributes); } /** * Specify an attribute on the statement context * * @param key name of the attribute * @param value value for the attribute * * @return previous value of this attribute */ @Override public Object setAttribute(final String key, final Object value) { return attributes.put(key, value); } /** * Obtain the value of an attribute * * @param key The name of the attribute * * @return the value of the attribute */ @Override public Object getAttribute(final String key) { return this.attributes.get(key); } /** * Obtain all the attributes associated with this context as a map. Changes to the map * or to the attributes on the context will be reflected across both * * @return a map f attributes */ @Override public Map<String, Object> getAttributes() { return new HashMap<>(attributes); } void setRawSql(final String rawSql) { this.rawSql = rawSql; } /** * Obtain the initial sql for the statement used to create the statement * * @return the initial sql */ @Override public String getRawSql() { return rawSql; } void setLocatedSql(final String locatedSql) { this.locatedSql = locatedSql; } void setRewrittenSql(final String rewrittenSql) { this.rewrittenSql = rewrittenSql; } /** * Obtain the located and rewritten sql * <p/> * Not available until statement execution time * * @return the sql as it will be executed against the database */ @Override public String getRewrittenSql() { return rewrittenSql; } /** * Obtain the located sql * <p/> * Not available until until statement execution time * * @return the sql which will be passed to the statement rewriter */ @Override public String getLocatedSql() { return locatedSql; } void setStatement(final PreparedStatement stmt) { statement = stmt; } /** * Obtain the actual prepared statement being used. * <p/> * Not available until execution time * * @return Obtain the actual prepared statement being used. */ @Override public PreparedStatement getStatement() { return statement; } void setConnection(final Connection connection) { this.connection = connection; } /** * Obtain the JDBC connection being used for this statement * * @return the JDBC connection */ @Override public Connection getConnection() { return connection; } public void setBinding(final Binding b) { this.binding = b; } @Override public Binding getBinding() { return binding; } public void setSqlObjectType(final Class<?> sqlObjectType) { this.sqlObjectType = sqlObjectType; } @Override public Class<?> getSqlObjectType() { return sqlObjectType; } public void setSqlObjectMethod(final Method sqlObjectMethod) { this.sqlObjectMethod = sqlObjectMethod; } @Override public Method getSqlObjectMethod() { return sqlObjectMethod; } public void setReturningGeneratedKeys(final boolean b) { this.returningGeneratedKeys = b; } @Override public boolean isReturningGeneratedKeys() { return returningGeneratedKeys; } @Override public void addCleanable(final Cleanable cleanable) { this.cleanables.add(cleanable); } @Override public Collection<Cleanable> getCleanables() { return cleanables; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ResultSetResultIterator.java
jdbi/src/main/java/org/skife/jdbi/v2/ResultSetResultIterator.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.ResultSetException; import org.skife.jdbi.v2.tweak.ResultSetMapper; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; class ResultSetResultIterator<Type> implements ResultIterator<Type> { private final ResultSetMapper<Type> mapper; private final SQLStatement jdbiStatement; private final ResultSet results; private final StatementContext context; private volatile boolean alreadyAdvanced = false; private volatile int count = 0; private volatile boolean hasNext = false; private volatile boolean closed = false; ResultSetResultIterator(ResultSetMapper<Type> mapper, SQLStatement jdbiStatement, Statement stmt, StatementContext context) throws SQLException { this.mapper = mapper; this.context = context; this.jdbiStatement = jdbiStatement; this.results = stmt.getResultSet(); this.jdbiStatement.addCleanable(Cleanables.forResultSet(results)); } @Override public void close() { if (closed) { return; } closed = true; jdbiStatement.cleanup(); } @Override public boolean hasNext() { if (closed) { return false; } if (alreadyAdvanced) { return hasNext; } hasNext = safeNext(); if (hasNext) { alreadyAdvanced = true; } else { close(); } return hasNext; } @Override public Type next() { if (closed) { throw new IllegalStateException("iterator is closed"); } if (!hasNext()) { close(); throw new IllegalStateException("No element to advance to"); } try { return mapper.map(count++, results, context); } catch (SQLException e) { throw new ResultSetException("Error thrown mapping result set into return type", e, context); } finally { alreadyAdvanced = safeNext(); if (!alreadyAdvanced) { close(); } } } @Override public void remove() { throw new UnsupportedOperationException("Deleting from a result set iterator is not yet supported"); } private boolean safeNext() { try { return results.next(); } catch (SQLException e) { throw new ResultSetException("Unable to advance result set", e, context); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Script.java
jdbi/src/main/java/org/skife/jdbi/v2/Script.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; import org.skife.jdbi.v2.tweak.StatementLocator; import java.util.Map; import java.util.regex.Pattern; /** * Represents a number of SQL statements which will be executed in a batch statement. */ public class Script { private static final Pattern WHITESPACE_ONLY = Pattern.compile("^\\s*$"); private Handle handle; private final StatementLocator locator; private final String name; private final Map<String, Object> globalStatementAttributes; Script(Handle h, StatementLocator locator, String name, Map<String, Object> globalStatementAttributes) { this.handle = h; this.locator = locator; this.name = name; this.globalStatementAttributes = globalStatementAttributes; } /** * Execute this script in a batch statement * * @return an array of ints which are the results of each statement in the script */ public int[] execute() { final String[] statements = getStatements(); Batch b = handle.createBatch(); for (String s : statements) { if ( ! WHITESPACE_ONLY.matcher(s).matches() ) { b.add(s); } } return b.execute(); } /** * Execute this script as a set of separate statements */ public void executeAsSeparateStatements() { for (String s : getStatements()) { if (!WHITESPACE_ONLY.matcher(s).matches()) { handle.execute(s); } } } private String[] getStatements() { final String script; final StatementContext ctx = new ConcreteStatementContext(globalStatementAttributes); try { script = locator.locate(name, ctx); } catch (Exception e) { throw new UnableToExecuteStatementException(String.format("Error while loading script [%s]", name), e, ctx); } return script.replaceAll("\n", " ").replaceAll("\r", "").split(";"); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Folder3.java
jdbi/src/main/java/org/skife/jdbi/v2/Folder3.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.sql.SQLException; public interface Folder3<AccumulatorType, MappedType> { /** * Invoked once per row in the result set from the query. * * @param accumulator The initial value passed to {@link org.skife.jdbi.v2.Query#fold(Object, Folder)} * for the first call, the return value from the previous call thereafter. * @param rs The mapped result set row to fold across * @param ctx The statement context for execution * @return A value which will be passed to the next invocation of this function. The final * invocation will be returned from the {@link org.skife.jdbi.v2.Query#fold(Object, Folder)} call. * @throws java.sql.SQLException will be wrapped and rethrown as a {@link org.skife.jdbi.v2.exceptions.CallbackFailedException} */ AccumulatorType fold(AccumulatorType accumulator, MappedType rs, FoldController control, StatementContext ctx) throws SQLException; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ByteArrayArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/ByteArrayArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; import java.util.Arrays; /** * */ class ByteArrayArgument implements Argument { private final byte[] value; ByteArrayArgument(byte[] value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setBytes(position, value); } else { statement.setNull(position, Types.VARBINARY); } } @Override public String toString() { return Arrays.toString(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/StringArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/StringArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * */ class StringArgument implements Argument { private final String value; StringArgument(String value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setString(position, value); } else { statement.setNull(position, Types.VARCHAR); } } @Override public String toString() { return "'" + value + "'"; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/DoubleArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/DoubleArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * */ class DoubleArgument implements Argument { private final Double value; DoubleArgument(Double value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setDouble(position, value); } else { statement.setNull(position, Types.DOUBLE); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Query.java
jdbi/src/main/java/org/skife/jdbi/v2/Query.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.ResultSetMapper; import org.skife.jdbi.v2.tweak.SQLLog; import org.skife.jdbi.v2.tweak.StatementBuilder; import org.skife.jdbi.v2.tweak.StatementCustomizer; import org.skife.jdbi.v2.tweak.StatementLocator; import org.skife.jdbi.v2.tweak.StatementRewriter; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.atomic.AtomicReference; /** * Statement providing convenience result handling for SQL queries. */ public class Query<ResultType> extends SQLStatement<Query<ResultType>> implements ResultBearing<ResultType> { private final ResultSetMapper<ResultType> mapper; private final MappingRegistry mappingRegistry; Query(Binding params, ResultSetMapper<ResultType> mapper, StatementLocator locator, StatementRewriter statementRewriter, Handle handle, StatementBuilder cache, String sql, ConcreteStatementContext ctx, SQLLog log, TimingCollector timingCollector, Collection<StatementCustomizer> customizers, MappingRegistry mappingRegistry, Foreman foreman, ContainerFactoryRegistry containerFactoryRegistry) { super(params, locator, statementRewriter, handle, cache, sql, ctx, log, timingCollector, customizers, foreman, containerFactoryRegistry); this.mapper = mapper; this.mappingRegistry = mappingRegistry.createChild(); } /** * Executes the select * <p/> * Will eagerly load all results * * @throws org.skife.jdbi.v2.exceptions.UnableToCreateStatementException * if there is an error creating the statement * @throws org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException * if there is an error executing the statement * @throws org.skife.jdbi.v2.exceptions.ResultSetException if there is an error dealing with the result set */ @Override public List<ResultType> list() { return list(List.class); } @Override public <ContainerType> ContainerType list(Class<ContainerType> containerType) { ContainerBuilder<ContainerType> builder = getContainerMapperRegistry().createBuilderFor(containerType); return fold(builder, new Folder3<ContainerBuilder<ContainerType>, ResultType>() { @Override public ContainerBuilder<ContainerType> fold(ContainerBuilder<ContainerType> accumulator, ResultType rs, FoldController ctl, StatementContext ctx) throws SQLException { accumulator.add(rs); return accumulator; } }).build(); } /** * Executes the select * <p/> * Will eagerly load all results up to a maximum of <code>maxRows</code> * * @param maxRows The maximum number of results to include in the result, any * rows in the result set beyond this number will be ignored. * * @throws org.skife.jdbi.v2.exceptions.UnableToCreateStatementException * if there is an error creating the statement * @throws org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException * if there is an error executing the statement * @throws org.skife.jdbi.v2.exceptions.ResultSetException if there is an error dealing with the result set */ @Override public List<ResultType> list(final int maxRows) { try { return this.internalExecute(new QueryResultSetMunger<List<ResultType>>(this) { @Override public List<ResultType> munge(ResultSet rs) throws SQLException { List<ResultType> result_list = new ArrayList<ResultType>(); int index = 0; while (rs.next() && index < maxRows) { result_list.add(mapper.map(index++, rs, getContext())); } return result_list; } }, null); } finally { cleanup(); } } /** * Used to execute the query and traverse the result set with a accumulator. * <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Folding</a> over the * result involves invoking a callback for each row, passing into the callback the return value * from the previous function invocation. * * @param accumulator The initial accumulator value * @param folder Defines the function which will fold over the result set. * * @return The return value from the last invocation of {@link Folder#fold(Object, java.sql.ResultSet)} * * @see org.skife.jdbi.v2.Folder */ public <AccumulatorType> AccumulatorType fold(AccumulatorType accumulator, final Folder2<AccumulatorType> folder) { final AtomicReference<AccumulatorType> acc = new AtomicReference<AccumulatorType>(accumulator); try { this.internalExecute(new QueryResultSetMunger<Void>(this) { @Override public Void munge(ResultSet rs) throws SQLException { while (rs.next()) { acc.set(folder.fold(acc.get(), rs, getContext())); } return null; } }, null); return acc.get(); } finally { cleanup(); } } public <AccumulatorType> AccumulatorType fold(final AccumulatorType accumulator, final Folder3<AccumulatorType, ResultType> folder) { try { return this.internalExecute(new QueryResultSetMunger<AccumulatorType>(this) { private int idx = 0; private AccumulatorType ac = accumulator; @Override protected AccumulatorType munge(ResultSet rs) throws SQLException { final FoldController ctl = new FoldController(rs); while (!ctl.isAborted() && rs.next()) { ResultType row_value = mapper.map(idx++, rs, getContext()); this.ac = folder.fold(ac, row_value, ctl, getContext()); } return ac; } }, null); } finally { cleanup(); } } /** * Used to execute the query and traverse the result set with a accumulator. * <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Folding</a> over the * result involves invoking a callback for each row, passing into the callback the return value * from the previous function invocation. * * @param accumulator The initial accumulator value * @param folder Defines the function which will fold over the result set. * * @return The return value from the last invocation of {@link Folder#fold(Object, java.sql.ResultSet)} * * @see org.skife.jdbi.v2.Folder * @deprecated Use {@link Query#fold(Object, Folder2)} */ public <AccumulatorType> AccumulatorType fold(AccumulatorType accumulator, final Folder<AccumulatorType> folder) { final AtomicReference<AccumulatorType> acc = new AtomicReference<AccumulatorType>(accumulator); try { this.internalExecute(new QueryResultSetMunger<Void>(this) { @Override public Void munge(ResultSet rs) throws SQLException { while (rs.next()) { acc.set(folder.fold(acc.get(), rs)); } return null; } }, null); return acc.get(); } finally { cleanup(); } } /** * Obtain a forward-only result set iterator. Note that you must explicitely close * the iterator to close the underlying resources. */ @Override public ResultIterator<ResultType> iterator() { return this.internalExecute(new QueryResultMunger<ResultIterator<ResultType>>() { @Override public ResultIterator<ResultType> munge(Statement stmt) throws SQLException { return new ResultSetResultIterator<ResultType>(mapper, Query.this, stmt, getContext()); } }, null); } /** * Executes the select. * <p/> * Specifies a maximum of one result on the JDBC statement, and map that one result * as the return value, or return null if there is nothing in the results * * @return first result, mapped, or null if there is no first result */ @Override public ResultType first() { return (ResultType) first(UnwrappedSingleValue.class); } @Override public <T> T first(Class<T> containerType) { // Kill Bill specific: assume our queries will always either use LIMIT 1 or will return exactly one row (see ResultReturnThing) // This saves a roundtrip (set @@SQL_SELECT_LIMIT=1) //addStatementCustomizer(StatementCustomizers.MAX_ROW_ONE); ContainerBuilder builder = getContainerMapperRegistry().createBuilderFor(containerType); return (T) this.fold(builder, new Folder3<ContainerBuilder, ResultType>() { @Override public ContainerBuilder fold(ContainerBuilder accumulator, ResultType rs, FoldController control, StatementContext ctx) throws SQLException { accumulator.add(rs); control.abort(); return accumulator; } }).build(); } /** * Provide basic JavaBean mapping capabilities. Will instantiate an instance of resultType * for each row and set the JavaBean properties which match fields in the result set. * * @param resultType JavaBean class to map result set fields into the properties of, by name * * @return a Query which provides the bean property mapping */ public <Type> Query<Type> map(Class<Type> resultType) { return this.map(new BeanMapper<Type>(resultType)); } /** * Makes use of registered mappers to map the result set to the desired type. * * @param resultType the type to map the query results to * * @return a new query instance which will map to the desired type * * @see DBI#registerMapper(org.skife.jdbi.v2.tweak.ResultSetMapper) * @see DBI#registerMapper(ResultSetMapperFactory) * @see Handle#registerMapper(ResultSetMapperFactory) * @see Handle#registerMapper(org.skife.jdbi.v2.tweak.ResultSetMapper) */ public <T> Query<T> mapTo(Class<T> resultType) { return this.map(new RegisteredMapper(resultType, mappingRegistry)); } public <T> Query<T> map(ResultSetMapper<T> mapper) { return new Query<T>(getParameters(), mapper, getStatementLocator(), getRewriter(), getHandle(), getStatementBuilder(), getSql(), getConcreteContext(), getLog(), getTimingCollector(), getStatementCustomizers(), mappingRegistry.createChild(), getForeman().createChild(), getContainerMapperRegistry().createChild()); } /** * Specify the fetch size for the query. This should cause the results to be * fetched from the underlying RDBMS in groups of rows equal to the number passed. * This is useful for doing chunked streaming of results when exhausting memory * could be a problem. * * @param fetchSize the number of rows to fetch in a bunch * * @return the modified query */ public Query<ResultType> setFetchSize(final int fetchSize) { this.addStatementCustomizer(new StatementCustomizers.FetchSizeCustomizer(fetchSize)); return this; } /** * Specify the maimum number of rows the query is to return. This uses the underlying JDBC * {@link Statement#setMaxRows(int)}}. * * @param maxRows maximum number of rows to return * * @return modified query */ public Query<ResultType> setMaxRows(final int maxRows) { this.addStatementCustomizer(new StatementCustomizers.MaxRowsCustomizer(maxRows)); return this; } /** * Specify the maimum field size in the result set. This uses the underlying JDBC * {@link Statement#setMaxFieldSize(int)} * * @param maxFields maximum field size * * @return modified query */ public Query<ResultType> setMaxFieldSize(final int maxFields) { this.addStatementCustomizer(new StatementCustomizers.MaxFieldSizeCustomizer(maxFields)); return this; } /** * Specify that the fetch order should be reversed, uses the underlying * {@link Statement#setFetchDirection(int)} * * @return the modified query */ public Query<ResultType> fetchReverse() { setFetchDirection(ResultSet.FETCH_REVERSE); return this; } /** * Specify that the fetch order should be forward, uses the underlying * {@link Statement#setFetchDirection(int)} * * @return the modified query */ public Query<ResultType> fetchForward() { setFetchDirection(ResultSet.FETCH_FORWARD); return this; } public void registerMapper(ResultSetMapper m) { //this.mappingRegistry.add(new InferredMapperFactory(m)); throw new UnsupportedOperationException("[OPTIMIZATION] Registering a custom ResultSetMapper on a Query is disabled"); } public void registerMapper(ResultSetMapperFactory m) { //this.mappingRegistry.add(m); throw new UnsupportedOperationException("[OPTIMIZATION] Registering a custom ResultSetMapperFactory on a Query is disabled"); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/BeanMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/BeanMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.killbill.commons.utils.annotation.VisibleForTesting; import org.skife.jdbi.v2.tweak.ResultSetMapper; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; import java.util.Date; import java.util.HashMap; import java.util.Map; /** * A result set mapper which maps the fields in a statement into a JavaBean. This uses * the JDK's built-in bean mapping facilities, so it does not support nested properties. */ public class BeanMapper<T> implements ResultSetMapper<T> { private final Class<T> type; private final Map<String, PropertyDescriptor> properties = new HashMap<>(); public BeanMapper(final Class<T> type) { this.type = type; try { final BeanInfo info = Introspector.getBeanInfo(type); for (final PropertyDescriptor descriptor : info.getPropertyDescriptors()) { properties.put(descriptor.getName().toLowerCase(), descriptor); } } catch (final IntrospectionException e) { throw new IllegalArgumentException(e); } } @Override @SuppressWarnings({"rawtypes"}) public T map(final int row, final ResultSet rs, final StatementContext ctx) throws SQLException { final T bean; try { bean = type.getDeclaredConstructor().newInstance(); } catch (final Exception e) { throw new IllegalArgumentException(String.format("A bean, %s, was mapped which was not instantiable", type.getName()), e); } final ResultSetMetaData metadata = rs.getMetaData(); for (int i = 1; i <= metadata.getColumnCount(); ++i) { final String name = metadata.getColumnLabel(i).toLowerCase(); final PropertyDescriptor descriptor = properties.get(name); if (descriptor != null) { final Class type = descriptor.getPropertyType(); final Object value = getValueFromResultSet(rs, type, i); final Method method = descriptor.getWriteMethod(); if (method == null) { throw new IllegalArgumentException(String.format("No appropriate method to write property %s", name)); } try { descriptor.getWriteMethod().invoke(bean, value); } catch (final IllegalAccessException e) { throw new IllegalArgumentException(String.format("Unable to access setter for property, %s", name), e); } catch (final InvocationTargetException e) { throw new IllegalArgumentException(String.format("Invocation target exception trying to invoker setter for the %s property", name), e); } } } return bean; } @SuppressWarnings({"unchecked", "rawtypes"}) @VisibleForTesting Object getValueFromResultSet(final ResultSet rs, final Class type, final int index) throws SQLException { final Object result; if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) { result = rs.getBoolean(index); } else if (type.isAssignableFrom(Byte.class) || type.isAssignableFrom(byte.class)) { result = rs.getByte(index); } else if (type.isAssignableFrom(Short.class) || type.isAssignableFrom(short.class)) { result = rs.getShort(index); } else if (type.isAssignableFrom(Integer.class) || type.isAssignableFrom(int.class)) { result = rs.getInt(index); } else if (type.isAssignableFrom(Long.class) || type.isAssignableFrom(long.class)) { result = rs.getLong(index); } else if (type.isAssignableFrom(Float.class) || type.isAssignableFrom(float.class)) { result = rs.getFloat(index); } else if (type.isAssignableFrom(Double.class) || type.isAssignableFrom(double.class)) { result = rs.getDouble(index); } else if (type.isAssignableFrom(BigDecimal.class)) { result = rs.getBigDecimal(index); } else if (type.isAssignableFrom(Timestamp.class)) { result = rs.getTimestamp(index); } else if (type.isAssignableFrom(Time.class)) { result = rs.getTime(index); } else if (type.isAssignableFrom(Date.class)) { result = rs.getDate(index); } else if (type.isAssignableFrom(String.class)) { result = rs.getString(index); } else if (type.isEnum()) { final String str = rs.getString(index); result = str != null ? Enum.valueOf(type, str) : null; } else { result = rs.getObject(index); } return (rs.wasNull() && !type.isPrimitive()) ? null : result; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Update.java
jdbi/src/main/java/org/skife/jdbi/v2/Update.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.ResultSetMapper; import org.skife.jdbi.v2.tweak.SQLLog; import org.skife.jdbi.v2.tweak.StatementBuilder; import org.skife.jdbi.v2.tweak.StatementCustomizer; import org.skife.jdbi.v2.tweak.StatementLocator; import org.skife.jdbi.v2.tweak.StatementRewriter; import java.sql.SQLException; import java.sql.Statement; import java.util.Collections; import java.util.Map; /** * Used for INSERT, UPDATE, and DELETE statements */ public class Update extends SQLStatement<Update> { Update(Handle handle, StatementLocator locator, StatementRewriter statementRewriter, StatementBuilder statementBuilder, String sql, ConcreteStatementContext ctx, SQLLog log, TimingCollector timingCollector, Foreman foreman, ContainerFactoryRegistry containerFactoryRegistry) { super(new Binding(), locator, statementRewriter, handle, statementBuilder, sql, ctx, log, timingCollector, Collections.<StatementCustomizer>emptyList(), foreman, containerFactoryRegistry); } /** * Execute the statement * @return the number of rows modified */ public int execute() { try { return this.internalExecute(new QueryResultMunger<Integer>() { @Override public Integer munge(Statement results) throws SQLException { return results.getUpdateCount(); } }, null); } finally { cleanup(); } } /** * Execute the statement and returns any auto-generated keys. This requires the JDBC driver to support * the {@link Statement#getGeneratedKeys()} method. * @param mapper the mapper to generate the resulting key object * @return the generated key or null if none was returned */ public <GeneratedKeyType> GeneratedKeys<GeneratedKeyType> executeAndReturnGeneratedKeys(final ResultSetMapper<GeneratedKeyType> mapper, final String... columnNames) { getConcreteContext().setReturningGeneratedKeys(true); return this.internalExecute(new QueryResultMunger<GeneratedKeys<GeneratedKeyType>>() { @Override public GeneratedKeys<GeneratedKeyType> munge(Statement results) throws SQLException { return new GeneratedKeys<GeneratedKeyType>(mapper, Update.this, results, getContext(), getContainerMapperRegistry()); } }, columnNames); } public GeneratedKeys<Map<String, Object>> executeAndReturnGeneratedKeys() { return executeAndReturnGeneratedKeys(new DefaultMapper()); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/TimeArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/TimeArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Time; import java.sql.Types; /** * */ class TimeArgument implements Argument { private final Time value; TimeArgument(Time value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setTime(position, value); } else { statement.setNull(position, Types.TIME); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ContainerFactoryRegistry.java
jdbi/src/main/java/org/skife/jdbi/v2/ContainerFactoryRegistry.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.ContainerFactory; import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; class ContainerFactoryRegistry { private final Map<Class<?>, ContainerFactory<?>> cache = new ConcurrentHashMap<Class<?>, ContainerFactory<?>>(); private final List<ContainerFactory> factories = new CopyOnWriteArrayList<ContainerFactory>(); ContainerFactoryRegistry() { factories.add(new ListContainerFactory()); factories.add(new SetContainerFactory()); factories.add(new SortedSetContainerFactory()); factories.add(new UnwrappedSingleValueFactory()); } ContainerFactoryRegistry(ContainerFactoryRegistry parent) { cache.putAll(parent.cache); factories.addAll(parent.factories); } void register(ContainerFactory<?> factory) { // [OPTIMIZATION] Disable feature to avoid creating lots of ContainerFactoryRegistry objects //factories.add(factory); //cache.clear(); throw new UnsupportedOperationException("[OPTIMIZATION] Registering a custom ContainerFactory is disabled"); } public ContainerFactoryRegistry createChild() { // [OPTIMIZATION] See above //return new ContainerFactoryRegistry(this); return this; } public ContainerBuilder createBuilderFor(Class<?> type) { if (cache.containsKey(type)) { return cache.get(type).newContainerBuilderFor(type); } for (int i = factories.size(); i > 0; i--) { ContainerFactory factory = factories.get(i - 1); if (factory.accepts(type)) { cache.put(type, factory); return factory.newContainerBuilderFor(type); } } throw new IllegalStateException("No container builder available for " + type.getName()); } static class SortedSetContainerFactory implements ContainerFactory<SortedSet<?>> { @Override public boolean accepts(Class<?> type) { return type.equals(SortedSet.class); } @Override public ContainerBuilder<SortedSet<?>> newContainerBuilderFor(Class<?> type) { return new ContainerBuilder<SortedSet<?>>() { private SortedSet<Object> s = new TreeSet<Object>(); @Override public ContainerBuilder<SortedSet<?>> add(Object it) { s.add(it); return this; } @Override public SortedSet<?> build() { return s; } }; } } static class SetContainerFactory implements ContainerFactory<Set<?>> { @Override public boolean accepts(Class<?> type) { return Set.class.equals(type) || LinkedHashSet.class.equals(type); } @Override public ContainerBuilder<Set<?>> newContainerBuilderFor(Class<?> type) { return new ContainerBuilder<Set<?>>() { private Set<Object> s = new LinkedHashSet<Object>(); @Override public ContainerBuilder<Set<?>> add(Object it) { s.add(it); return this; } @Override public Set<?> build() { return s; } }; } } static class ListContainerFactory implements ContainerFactory<List<?>> { @Override public boolean accepts(Class<?> type) { return type.equals(List.class) || type.equals(Collection.class) || type.equals(Iterable.class); } @Override public ContainerBuilder<List<?>> newContainerBuilderFor(Class<?> type) { return new ListContainerBuilder(); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/TimingCollector.java
jdbi/src/main/java/org/skife/jdbi/v2/TimingCollector.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; /** * This class collects timing information for every database operation. */ public interface TimingCollector { /** * This method is executed every time there is information to collect. Grouping of the * timing information is up to the implementation of this interface. * * @param ctx The Statement Context, which contains additional information about the * statement that just ran. * @param elapsedTime The elapsed time in nanoseconds. */ void collect(long elapsedTime, StatementContext ctx); /** * A No Operation Timing Collector. It can be used to "plug" into DBI if more sophisticated * collection is not needed. */ TimingCollector NOP_TIMING_COLLECTOR = new NopTimingCollector(); public static final class NopTimingCollector implements TimingCollector { @Override public void collect(final long elapsedTime, final StatementContext ctx) { // GNDN } }; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ResultBearing.java
jdbi/src/main/java/org/skife/jdbi/v2/ResultBearing.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.util.List; public interface ResultBearing<ResultType> extends Iterable<ResultType> { <ContainerType> ContainerType list(Class<ContainerType> containerType); List<ResultType> list(final int maxRows); List<ResultType> list(); @Override ResultIterator<ResultType> iterator(); ResultType first(); <T> T first(Class<T> containerType); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Handle.java
jdbi/src/main/java/org/skife/jdbi/v2/Handle.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.TransactionFailedException; import org.skife.jdbi.v2.tweak.ArgumentFactory; import org.skife.jdbi.v2.tweak.ContainerFactory; import org.skife.jdbi.v2.tweak.ResultSetMapper; import org.skife.jdbi.v2.tweak.SQLLog; import org.skife.jdbi.v2.tweak.StatementBuilder; import org.skife.jdbi.v2.tweak.StatementLocator; import org.skife.jdbi.v2.tweak.StatementRewriter; import java.io.Closeable; import java.sql.Connection; import java.util.List; import java.util.Map; /** * This represents a connection to the database system. It ususally is a wrapper around * a JDBC Connection object. */ public interface Handle extends Closeable { /** * Get the JDBC Connection this Handle uses * @return the JDBC Connection this Handle uses */ Connection getConnection(); @Override /** * @throws org.skife.jdbi.v2.exceptions.UnableToCloseResourceException if any * resources throw exception while closing */ void close(); /** * Define a statement attribute which will be applied to all {@link StatementContext} * instances for statements created from this handle * * @param key Attribute name * @param value Attribute value */ void define(String key, Object value); /** * Start a transaction */ Handle begin(); /** * Commit a transaction */ Handle commit(); /** * Rollback a transaction */ Handle rollback(); /** * Rollback a transaction to a named checkpoint * @param checkpointName the name of the checkpoint, previously declared with {@link Handle#checkpoint} */ Handle rollback(String checkpointName); /** * Is the handle in a transaction? It defers to the underlying {@link org.skife.jdbi.v2.tweak.TransactionHandler} */ boolean isInTransaction(); /** * Return a default Query instance which can be executed later, as long as this handle remains open. * @param sql the select sql */ Query<Map<String, Object>> createQuery(String sql); /** * Create an Insert or Update statement which returns the number of rows modified. * @param sql The statement sql */ Update createStatement(String sql); /** * Create a call to a stored procedure * * @param callableSql * @return the Call */ Call createCall(String callableSql); /** * Execute a simple insert statement * @param sql the insert SQL * @return the number of rows inserted */ int insert(String sql, Object... args); /** * Execute a simple update statement * @param sql the update SQL * @param args positional arguments * @return the number of updated inserted */ int update(String sql, Object... args); /** * Prepare a batch to execute. This is for efficiently executing more than one * of the same statements with different parameters bound * @param sql the batch SQL * @return a batch which can have "statements" added */ PreparedBatch prepareBatch(String sql); /** * Create a non-prepared (no bound parameters, but different SQL, batch statement * @return empty batch * @see Handle#prepareBatch(String) */ Batch createBatch(); /** * Executes <code>callback</code> in a transaction. If the transaction succeeds, the * result of the callback will be returned. If it fails a {@link TransactionFailedException} * will be thrown. * * @return value returned from the callback * @throws TransactionFailedException if the transaction failed in the callback */ <ReturnType> ReturnType inTransaction(TransactionCallback<ReturnType> callback) throws TransactionFailedException; /** * Executes <code>callback</code> in a transaction. If the transaction succeeds, the * result of the callback will be returned. If it fails a {@link TransactionFailedException} * will be thrown. * <p> * This form accepts a transaction isolation level which will be applied to the connection * for the scope of this transaction, after which the original isolation level will be restored. * </p> * @return value returned from the callback * @throws TransactionFailedException if the transaction failed in the callback */ <ReturnType> ReturnType inTransaction(TransactionIsolationLevel level, TransactionCallback<ReturnType> callback) throws TransactionFailedException; /** * Convenience method which executes a select with purely positional arguments * @param sql SQL or named statement * @param args arguments to bind positionally * @return results of the query */ List<Map<String, Object>> select(String sql, Object... args); /** * Allows for overiding the default statement locator. The default searches the * classpath for named statements */ void setStatementLocator(StatementLocator locator); /** * Allows for overiding the default statement rewriter. The default handles * named parameter interpolation. */ void setStatementRewriter(StatementRewriter rewriter); /** * Creates an SQL script, looking for the source of the script using the * current statement locator (which defaults to searching the classpath) */ Script createScript(String name); /** * Execute some SQL with no return value * @param sql the sql to execute * @param args arguments to bind to the sql */ void execute(String sql, Object... args); /** * Create a transaction checkpoint (savepoint in JDBC terminology) with the name provided. * @param name The name of the checkpoint * @return The same handle */ Handle checkpoint(String name); /** * Release a previously created checkpoint * * @param checkpointName the name of the checkpoint to release */ Handle release(String checkpointName); /** * Specify the statement builder to use for this handle * @param builder StatementBuilder to be used */ void setStatementBuilder(StatementBuilder builder); /** * Specify the class used to log sql statements. The default is inherited from the DBI used * to create this Handle. */ void setSQLLog(SQLLog log); /** * Specify the class used to collect timing information. The default is inherited from the DBI used * to create this Handle. */ void setTimingCollector(TimingCollector timingCollector); /** * Register a result set mapper which will have its parameterized type inspected to determine what it maps to * * Will be used with {@link Query#mapTo(Class)} for registered mappings. */ void registerMapper(ResultSetMapper mapper); /** * Register a result set mapper factory. * * Will be used with {@link Query#mapTo(Class)} for registerd mappings. */ void registerMapper(ResultSetMapperFactory factory); /** * Create a a sql object of the specified type bound to this handle. Any state changes to the handle, or the * sql object, such as transaction status, closing it, etc, will apply to both the object and the handle. * * @param sqlObjectType * @param <SqlObjectType> * @return the new sql object bound to this handle */ <SqlObjectType> SqlObjectType attach(Class<SqlObjectType> sqlObjectType); /** * Set the transaction isolation level on the underlying connection * * @param level the isolation level to use */ void setTransactionIsolation(TransactionIsolationLevel level); /** * Set the transaction isolation level on the underlying connection * * @param level the isolation level to use */ void setTransactionIsolation(int level); /** * Obtain the current transaction isolation level * * @return the current isolation level on the underlying connection */ TransactionIsolationLevel getTransactionIsolationLevel(); void registerArgumentFactory(ArgumentFactory argumentFactory); void registerContainerFactory(ContainerFactory<?> factory); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Cleanable.java
jdbi/src/main/java/org/skife/jdbi/v2/Cleanable.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.sql.SQLException; public interface Cleanable { void cleanup() throws SQLException; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/GeneratedKeys.java
jdbi/src/main/java/org/skife/jdbi/v2/GeneratedKeys.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.ResultSetException; import org.skife.jdbi.v2.tweak.ResultSetMapper; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; /** * Wrapper object for generated keys as returned by the {@link Statement#getGeneratedKeys()} * * @param <Type> the key type returned */ public class GeneratedKeys<Type> implements ResultBearing<Type> { private final ResultSetMapper<Type> mapper; private final SQLStatement<?> jdbiStatement; private final Statement stmt; private final ResultSet results; private final StatementContext context; private final ContainerFactoryRegistry containerFactoryRegistry; /** * Creates a new wrapper object for generated keys as returned by the {@link Statement#getGeneratedKeys()} * method for update and insert statement for drivers that support this function. * * @param mapper Maps the generated keys result set to an object * @param jdbiStatement The original jDBI statement * @param stmt The corresponding sql statement * @param context The statement context */ GeneratedKeys(ResultSetMapper<Type> mapper, SQLStatement<?> jdbiStatement, Statement stmt, StatementContext context, ContainerFactoryRegistry containerFactoryRegistry) throws SQLException { this.mapper = mapper; this.jdbiStatement = jdbiStatement; this.stmt = stmt; this.results = stmt.getGeneratedKeys(); this.context = context; this.containerFactoryRegistry = containerFactoryRegistry.createChild(); this.jdbiStatement.addCleanable(Cleanables.forResultSet(results)); } /** * Returns the first generated key. * * @return The key or null if no keys were returned */ @Override public Type first() { try { if (results != null && results.next()) { return mapper.map(0, results, context); } else { // no result matches return null; } } catch (SQLException e) { throw new ResultSetException("Exception thrown while attempting to traverse the result set", e, context); } finally { jdbiStatement.cleanup(); } } @Override public <T> T first(Class<T> containerType) { // return containerFactoryRegistry.lookup(containerType).create(Arrays.asList(first())); throw new UnsupportedOperationException("Not Yet Implemented!"); } @Override public <ContainerType> ContainerType list(Class<ContainerType> containerType) { // return containerFactoryRegistry.lookup(containerType).create(Arrays.asList(list())); if (containerType.isAssignableFrom(List.class)) { return (ContainerType) list(); } else { throw new UnsupportedOperationException("Not Yet Implemented!"); } } @Override public List<Type> list(int maxRows) { try { int idx = 0; List<Type> resultList = new ArrayList<Type>(); if (results != null && ++idx <= maxRows && !results.isClosed()) { int index = 0; while (results.next()) { resultList.add(mapper.map(index++, results, context)); } } return resultList; } catch (SQLException e) { throw new ResultSetException("Exception thrown while attempting to traverse the result set", e, context); } finally { jdbiStatement.cleanup(); } } /** * Returns a list of all generated keys. * * @return The list of keys or an empty list if no keys were returned */ @Override public List<Type> list() { return list(Integer.MAX_VALUE); } /** * Returns a iterator over all generated keys. * * @return The key iterator */ @Override public ResultIterator<Type> iterator() { try { return new ResultSetResultIterator<Type>(mapper, jdbiStatement, stmt, context); } catch (SQLException e) { throw new ResultSetException("Exception thrown while attempting to traverse the result set", e, context); } } /** * Used to execute the query and traverse the generated keys with a accumulator. * <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">Folding</a> over the * keys involves invoking a callback for each row, passing into the callback the return value * from the previous function invocation. * * @param accumulator The initial accumulator value * @param folder Defines the function which will fold over the result set. * * @return The return value from the last invocation of {@link Folder#fold(Object, java.sql.ResultSet)} * * @see org.skife.jdbi.v2.Folder */ public <AccumulatorType> AccumulatorType fold(AccumulatorType accumulator, final Folder2<AccumulatorType> folder) { try { AccumulatorType value = accumulator; if (results != null && !results.isClosed()) { while (results.next()) { value = folder.fold(value, results, context); } } return value; } catch (SQLException e) { throw new ResultSetException("Exception thrown while attempting to traverse the result set", e, context); } finally { jdbiStatement.cleanup(); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ListContainerBuilder.java
jdbi/src/main/java/org/skife/jdbi/v2/ListContainerBuilder.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.util.ArrayList; import java.util.List; class ListContainerBuilder implements ContainerBuilder<List<?>> { private final ArrayList<Object> list; ListContainerBuilder() { this.list = new ArrayList<Object>(); } @Override public ListContainerBuilder add(Object it) { list.add(it); return this; } @Override public List<?> build() { return list; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/TransactionIsolationLevel.java
jdbi/src/main/java/org/skife/jdbi/v2/TransactionIsolationLevel.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.sql.Connection; public enum TransactionIsolationLevel { READ_UNCOMMITTED(Connection.TRANSACTION_READ_UNCOMMITTED), READ_COMMITTED(Connection.TRANSACTION_READ_COMMITTED), REPEATABLE_READ(Connection.TRANSACTION_REPEATABLE_READ), NONE(Connection.TRANSACTION_NONE), SERIALIZABLE(Connection.TRANSACTION_SERIALIZABLE), INVALID_LEVEL(Integer.MIN_VALUE); private final int value; TransactionIsolationLevel(int value) { this.value = value; } public int intValue() { return this.value; } public static TransactionIsolationLevel valueOf(int val) { switch (val) { case Connection.TRANSACTION_READ_UNCOMMITTED: return READ_UNCOMMITTED; case Connection.TRANSACTION_READ_COMMITTED: return READ_COMMITTED; case Connection.TRANSACTION_NONE: return NONE; case Connection.TRANSACTION_REPEATABLE_READ: return REPEATABLE_READ; case Connection.TRANSACTION_SERIALIZABLE: return SERIALIZABLE; default: return INVALID_LEVEL; } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Pair.java
jdbi/src/main/java/org/skife/jdbi/v2/Pair.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; final class Pair<FirstType, SecondType> { private final FirstType first; private final SecondType second; Pair(final FirstType first, final SecondType second) { this.first = first; this.second = second; } FirstType getFirst() { return first; } SecondType getSecond() { return second; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/SqlTypeArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/SqlTypeArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; /** * */ class SqlTypeArgument implements Argument { private final Object value; private final int sqlType; public SqlTypeArgument(Object value, int sqlType) { this.value = value; this.sqlType = sqlType; } @Override public void apply(final int position, PreparedStatement statement, StatementContext ctx) throws SQLException { statement.setObject(position, value, sqlType); } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/NoOpStatementRewriter.java
jdbi/src/main/java/org/skife/jdbi/v2/NoOpStatementRewriter.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import org.skife.jdbi.v2.tweak.RewrittenStatement; import org.skife.jdbi.v2.tweak.StatementRewriter; import java.sql.PreparedStatement; import java.sql.SQLException; /** * A statement rewriter which does not, in fact, rewrite anything. This is useful * if you use something like Oracle which supports :foo based parameter indicators * natively. It does not do any name based binding, however. */ public class NoOpStatementRewriter implements StatementRewriter { @Override public RewrittenStatement rewrite(String sql, Binding params, StatementContext ctx) { return new NoOpRewrittenStatement(sql, ctx); } private static class NoOpRewrittenStatement implements RewrittenStatement { private final String sql; private final StatementContext context; public NoOpRewrittenStatement(String sql, StatementContext ctx) { this.context = ctx; this.sql = sql; } @Override public void bind(Binding params, PreparedStatement statement) throws SQLException { for (int i = 0; ; i++) { final Argument s = params.forPosition(i); if (s == null) { break; } s.apply(i + 1, statement, this.context); } } @Override public String getSql() { return sql; } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ColonPrefixNamedParamStatementRewriter.java
jdbi/src/main/java/org/skife/jdbi/v2/ColonPrefixNamedParamStatementRewriter.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.antlr.runtime.ANTLRStringStream; import org.antlr.runtime.Token; import org.skife.jdbi.rewriter.colon.ColonStatementLexer; import org.skife.jdbi.v2.exceptions.UnableToCreateStatementException; import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; import org.skife.jdbi.v2.tweak.Argument; import org.skife.jdbi.v2.tweak.RewrittenStatement; import org.skife.jdbi.v2.tweak.StatementRewriter; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.WeakHashMap; import static org.skife.jdbi.rewriter.colon.ColonStatementLexer.DOUBLE_QUOTED_TEXT; import static org.skife.jdbi.rewriter.colon.ColonStatementLexer.ESCAPED_TEXT; import static org.skife.jdbi.rewriter.colon.ColonStatementLexer.LITERAL; import static org.skife.jdbi.rewriter.colon.ColonStatementLexer.NAMED_PARAM; import static org.skife.jdbi.rewriter.colon.ColonStatementLexer.POSITIONAL_PARAM; import static org.skife.jdbi.rewriter.colon.ColonStatementLexer.QUOTED_TEXT; /** * Statement rewriter which replaces named parameter tokens of the form :tokenName * <p/> * This is the default statement rewriter */ public class ColonPrefixNamedParamStatementRewriter implements StatementRewriter { private final Map<String, ParsedStatement> cache = Collections.synchronizedMap(new WeakHashMap<String, ParsedStatement>()); /** * Munge up the SQL as desired. Responsible for figuring out ow to bind any * arguments in to the resultant prepared statement. * * @param sql The SQL to rewrite * @param params contains the arguments which have been bound to this statement. * @param ctx The statement context for the statement being executed * @return something which can provide the actual SQL to prepare a statement from * and which can bind the correct arguments to that prepared statement */ @Override public RewrittenStatement rewrite(String sql, Binding params, StatementContext ctx) { ParsedStatement stmt = cache.get(sql); if (stmt == null) { try { stmt = parseString(sql); cache.put(sql, stmt); } catch (IllegalArgumentException e) { throw new UnableToCreateStatementException("Exception parsing for named parameter replacement", e, ctx); } } return new MyRewrittenStatement(stmt, ctx); } protected ParsedStatement parseString(final String sql) throws IllegalArgumentException { ParsedStatement stmt = new ParsedStatement(); StringBuilder b = new StringBuilder(sql.length()); ColonStatementLexer lexer = new ColonStatementLexer(new ANTLRStringStream(sql)); Token t = lexer.nextToken(); while (t.getType() != ColonStatementLexer.EOF) { switch (t.getType()) { case LITERAL: b.append(t.getText()); break; case NAMED_PARAM: stmt.addNamedParamAt(t.getText().substring(1, t.getText().length())); b.append("?"); break; case QUOTED_TEXT: b.append(t.getText()); break; case DOUBLE_QUOTED_TEXT: b.append(t.getText()); break; case POSITIONAL_PARAM: b.append("?"); stmt.addPositionalParamAt(); break; case ESCAPED_TEXT: b.append(t.getText().substring(1)); break; default: break; } t = lexer.nextToken(); } stmt.sql = b.toString(); return stmt; } private static class MyRewrittenStatement implements RewrittenStatement { private final ParsedStatement stmt; private final StatementContext context; MyRewrittenStatement(ParsedStatement stmt, StatementContext ctx) { this.context = ctx; this.stmt = stmt; } @Override public void bind(Binding params, PreparedStatement statement) throws SQLException { if (stmt.positionalOnly) { // no named params, is easy boolean finished = false; for (int i = 0; !finished; ++i) { final Argument a = params.forPosition(i); if (a != null) { try { a.apply(i + 1, statement, this.context); } catch (SQLException e) { throw new UnableToExecuteStatementException( String.format("Exception while binding positional param at (0 based) position %d", i), e, context); } } else { finished = true; } } } else { //List<String> named_params = stmt.params; int i = 0; for (String named_param : stmt.params) { if ("*".equals(named_param)) { continue; } Argument a = params.forName(named_param); if (a == null) { a = params.forPosition(i); } if (a == null) { String msg = String.format("Unable to execute, no named parameter matches " + "\"%s\" and no positional param for place %d (which is %d in " + "the JDBC 'start at 1' scheme) has been set.", named_param, i, i + 1); throw new UnableToExecuteStatementException(msg, context); } try { a.apply(i + 1, statement, this.context); } catch (SQLException e) { throw new UnableToCreateStatementException(String.format("Exception while binding '%s'", named_param), e, context); } i++; } } } @Override public String getSql() { return stmt.getParsedSql(); } } protected static class ParsedStatement { private String sql; private boolean positionalOnly = true; private List<String> params = new ArrayList<String>(); public void addNamedParamAt(String name) { positionalOnly = false; params.add(name); } public void addPositionalParamAt() { params.add("*"); } public String getParsedSql() { return sql; } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/StatementContext.java
jdbi/src/main/java/org/skife/jdbi/v2/StatementContext.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.lang.reflect.Method; import java.sql.Connection; import java.sql.PreparedStatement; import java.util.Collection; import java.util.Map; /** * The statement context provides a means for passing client specific information through the * evaluation of a statement. The context is not used by jDBI internally, but will be passed * to all statement customizers. This makes it possible to parameterize the processing of * the tweakable parts of the statement processing cycle. */ public interface StatementContext { /** * Specify an attribute on the statement context * * @param key name of the attribute * @param value value for the attribute * * @return previous value of this attribute */ Object setAttribute(String key, Object value); /** * Obtain the value of an attribute * * @param key The name of the attribute * * @return the value of the attribute */ Object getAttribute(String key); /** * Obtain all the attributes associated with this context as a map. Changes to the map * or to the attributes on the context will be reflected across both * * @return a map f attributes */ Map<String, Object> getAttributes(); /** * Obtain the initial sql for the statement used to create the statement * * @return the initial sql */ String getRawSql(); /** * Obtain the located and rewritten sql * <p/> * Not available until until statement execution time * * @return the sql as it will be executed against the database */ String getRewrittenSql(); /** * Obtain the located sql * <p/> * Not available until until statement execution time * * @return the sql which will be passed to the statement rewriter */ String getLocatedSql(); /** * Obtain the actual prepared statement being used. * <p/> * Not available until execution time * * @return Obtain the actual prepared statement being used. */ PreparedStatement getStatement(); /** * Obtain the JDBC connection being used for this statement * * @return the JDBC connection */ Connection getConnection(); Binding getBinding(); Class<?> getSqlObjectType(); Method getSqlObjectMethod(); /** * Is the statement being generated expected to return the generated keys? */ boolean isReturningGeneratedKeys(); void addCleanable(Cleanable cleanable); Collection<Cleanable> getCleanables(); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/BuiltInArgumentFactory.java
jdbi/src/main/java/org/skife/jdbi/v2/BuiltInArgumentFactory.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import org.skife.jdbi.v2.tweak.ArgumentFactory; import java.lang.reflect.Constructor; import java.math.BigDecimal; import java.net.URL; import java.sql.Blob; import java.sql.Clob; import java.sql.Time; import java.sql.Timestamp; import java.util.IdentityHashMap; import java.util.Map; public final class BuiltInArgumentFactory implements ArgumentFactory { private static final Map<Class, P> b = new IdentityHashMap<Class, P>(); static { b.put(BigDecimal.class, new P(BigDecimalArgument.class)); b.put(Blob.class, new P(BlobArgument.class)); b.put(Boolean.class, new P(BooleanArgument.class)); b.put(boolean.class, new P(BooleanArgument.class)); b.put(Byte.class, new P(ByteArgument.class)); b.put(byte.class, new P(ByteArgument.class)); b.put(byte[].class, new P(ByteArrayArgument.class)); b.put(Character.class, new P(CharacterArgument.class)); b.put(char.class, new P(CharacterArgument.class)); b.put(Clob.class, new P(ClobArgument.class)); b.put(Double.class, new P(DoubleArgument.class)); b.put(double.class, new P(DoubleArgument.class)); b.put(Enum.class, new P(EnumArgument.class)); b.put(Float.class, new P(FloatArgument.class)); b.put(float.class, new P(FloatArgument.class)); b.put(Integer.class, new P(IntegerArgument.class)); b.put(int.class, new P(IntegerArgument.class)); b.put(java.util.Date.class, new P(JavaDateArgument.class)); b.put(Long.class, new P(LongArgument.class)); b.put(long.class, new P(LongArgument.class)); b.put(Object.class, new P(ObjectArgument.class)); b.put(Short.class, new P(ShortArgument.class)); b.put(short.class, new P(ShortArgument.class)); b.put(java.sql.Date.class, new P(SqlDateArgument.class)); b.put(String.class, new P(StringArgument.class)); b.put(Time.class, new P(TimeArgument.class)); b.put(Timestamp.class, new P(TimestampArgument.class)); b.put(URL.class, new P(URLArgument.class)); } public static boolean canAccept(Class expectedType) { return b.containsKey(expectedType) || expectedType.isEnum(); } BuiltInArgumentFactory(){} @Override public boolean accepts(Class expectedType, Object value, StatementContext ctx) { return canAccept(expectedType); } @Override public Argument build(Class expectedType, Object value, StatementContext ctx) { P p; if (expectedType.isEnum()) { p = b.get(Enum.class); } else { p = b.get(expectedType); } if (value != null && expectedType == Object.class) { P v = b.get(value.getClass()); if (v != null) { return v.build(value); } } return p.build(value); } private static class P { private final Constructor<?> ctor; public P(Class<? extends Argument> argType) { this.ctor = argType.getDeclaredConstructors()[0]; } public Argument build(Object value) { try { return (Argument) ctor.newInstance(value); } catch (Exception e) { throw new IllegalStateException(e); } } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/OutParameters.java
jdbi/src/main/java/org/skife/jdbi/v2/OutParameters.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.sql.Date; import java.sql.Timestamp; import java.util.HashMap; import java.util.Map; /** * Represents output from a Call (CallableStatement) * @see org.skife.jdbi.v2.Call */ public class OutParameters { private final Map<Object, Object> map = new HashMap<Object, Object>(); /** * Type-casting convenience method which obtains an object from the map, the * object obtained should have been created with {@link org.skife.jdbi.v2.CallableStatementMapper} * * @param name The out parameter name * @param type The java type to obtain * @return the output of name as type T */ public <T> T getObject(String name, Class<T> type) { return type.cast(getObject(name)); } /** * Obtains an object from the map, the * object obtained should have been created with {@link org.skife.jdbi.v2.CallableStatementMapper} * * @param name The out parameter name * @return the output of name as type T */ public Object getObject(String name) { return map.get(name); } /** * Type-casting convenience method which obtains an object from the the results positionally * object obtained should have been created with {@link org.skife.jdbi.v2.CallableStatementMapper} * * @param position The out parameter name * @return the output of name as type T */ public Object getObject(int position) { return map.get(position); } /** * Type-casting convenience method which obtains an object from the map positionally * object obtained should have been created with {@link org.skife.jdbi.v2.CallableStatementMapper} * * @param pos The out parameter position * @param type The java type to obtain * @return the output of name as type T */ public <T> T getObject(int pos, Class<T> type) { return type.cast(getObject(pos)); } public String getString(String name) { Object obj = map.get(name); if (obj == null) { if (!map.containsKey(name)) { throw new IllegalArgumentException(String.format("Parameter %s does not exist", name)); } return null; } return obj.toString(); } public String getString(int pos) { Object obj = map.get(pos); if (obj == null) { if (!map.containsKey(pos)) { throw new IllegalArgumentException(String.format("Parameter at %d does not exist", pos)); } return null; } return obj.toString(); } public byte[] getBytes(String name) { Object obj = map.get(name); if (obj == null) { if (!map.containsKey(name)) { throw new IllegalArgumentException(String.format("Parameter %s does not exist", name)); } return null; } if (obj instanceof byte[]) { return (byte[]) obj; } else { throw new IllegalArgumentException(String.format("Parameter %s is not byte[] but %s", name, obj.getClass())); } } public byte[] getBytes(int pos) { Object obj = map.get(pos); if (obj == null) { if (!map.containsKey(pos)) { throw new IllegalArgumentException(String.format("Parameter at %d does not exist", pos)); } return null; } if (obj instanceof byte[]) { return (byte[]) obj; } else { throw new IllegalArgumentException(String.format("Parameter at %d is not byte[] but %s", pos, obj.getClass())); } } public Integer getInt(String name) { return getNumber(name).intValue(); } public Integer getInt(int pos) { return getNumber(pos).intValue(); } public Long getLong(String name) { return getNumber(name).longValue(); } public Long getLong(int pos) { return getNumber(pos).longValue(); } public Short getShort(String name) { return getNumber(name).shortValue(); } public Short getShort(int pos) { return getNumber(pos).shortValue(); } public Date getDate(String name) { Long epoch = getEpoch(name); if (epoch == null) { return null; } return new Date(epoch); } public Date getDate(int pos) { Long epoch = getEpoch(pos); if (epoch == null) { return null; } return new Date(epoch); } public Timestamp getTimestamp(String name) { Long epoch = getEpoch(name); if (epoch == null) { return null; } return new Timestamp(epoch); } public Timestamp getTimestamp(int pos) { Long epoch = getEpoch(pos); if (epoch == null) { return null; } return new Timestamp(epoch); } public Double getDouble(String name) { return getNumber(name).doubleValue(); } public Double getDouble(int pos) { return getNumber(pos).doubleValue(); } public Float getFloat(String name) { return getNumber(name).floatValue(); } public Float getFloat(int pos) { return getNumber(pos).floatValue(); } private Number getNumber(String name) { Object obj = map.get(name); if (obj == null) { if (!map.containsKey(name)) { throw new IllegalArgumentException(String.format("Parameter %s does not exist", name)); } return null; } if (obj instanceof Number) { return (Number) obj; } else { throw new IllegalArgumentException(String.format("Parameter %s is not a number but %s", name, obj.getClass())); } } private Number getNumber(int pos) { Object obj = map.get(pos); if (obj == null) { if (!map.containsKey(pos)) { throw new IllegalArgumentException(String.format("Parameter at %d does not exist", pos)); } return null; } if (obj instanceof Number) { return (Number) obj; } else { throw new IllegalArgumentException(String.format("Parameter at %d is not a number but %s", pos, obj.getClass())); } } private Long getEpoch(String name) { Object obj = map.get(name); if (obj == null) { if (!map.containsKey(name)) { throw new IllegalArgumentException(String.format("Parameter %s does not exist", name)); } return null; } if (obj instanceof java.util.Date) { return ((java.util.Date) obj).getTime(); } else { throw new IllegalArgumentException(String.format("Parameter %s is not Date but %s", name, obj.getClass())); } } private Long getEpoch(int pos) { Object obj = map.get(pos); if (obj == null) { if (!map.containsKey(pos)) { throw new IllegalArgumentException(String.format("Parameter at %d does not exist", pos)); } return null; } if (obj instanceof java.util.Date) { return ((java.util.Date) obj).getTime(); } else { throw new IllegalArgumentException(String.format("Parameter at %d is not Date but %s", pos, obj.getClass())); } } Map<Object, Object> getMap() { return map; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/DataSourceConnectionFactory.java
jdbi/src/main/java/org/skife/jdbi/v2/DataSourceConnectionFactory.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.ConnectionFactory; import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; class DataSourceConnectionFactory implements ConnectionFactory { private DataSource dataSource; public DataSourceConnectionFactory(DataSource dataSource) { this.dataSource = dataSource; } @Override public Connection openConnection() throws SQLException { return dataSource.getConnection(); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ClobArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/ClobArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.Clob; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * */ class ClobArgument implements Argument { private final Clob value; ClobArgument(Clob value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setClob(position, value); } else { statement.setNull(position, Types.CLOB); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Folder2.java
jdbi/src/main/java/org/skife/jdbi/v2/Folder2.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.sql.ResultSet; import java.sql.SQLException; /** * */ public interface Folder2<AccumulatorType> { /** * Invoked once per row in the result set from the query. * * @param accumulator The initial value passed to {@link org.skife.jdbi.v2.Query#fold(Object, Folder)} * for the first call, the return value from the previous call thereafter. * @param rs The actual result set from the query. It will already have been advanced to the * correct row. Callbacks should not call {@link java.sql.ResultSet#next()} * @param ctx The statement context for execution * @return A value which will be passed to the next invocation of this function. The final * invocation will be returned from the {@link org.skife.jdbi.v2.Query#fold(Object, Folder)} call. * @throws java.sql.SQLException will be wrapped and rethrown as a {@link org.skife.jdbi.v2.exceptions.CallbackFailedException} */ AccumulatorType fold(AccumulatorType accumulator, ResultSet rs, StatementContext ctx) throws SQLException; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/CharacterArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/CharacterArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; class CharacterArgument implements Argument { private final Character value; CharacterArgument(Character value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setString(position, String.valueOf(value)); } else { statement.setNull(position, Types.CHAR); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/DBI.java
jdbi/src/main/java/org/skife/jdbi/v2/DBI.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.killbill.commons.profiling.Profiling; import org.killbill.commons.profiling.Profiling.WithProfilingCallback; import org.killbill.commons.profiling.ProfilingFeature.ProfilingFeatureType; import org.skife.jdbi.v2.exceptions.CallbackFailedException; import org.skife.jdbi.v2.exceptions.UnableToObtainConnectionException; import org.skife.jdbi.v2.logging.NoOpLog; import org.skife.jdbi.v2.sqlobject.SqlObjectBuilder; import org.skife.jdbi.v2.tweak.ArgumentFactory; import org.skife.jdbi.v2.tweak.ConnectionFactory; import org.skife.jdbi.v2.tweak.ContainerFactory; import org.skife.jdbi.v2.tweak.HandleCallback; import org.skife.jdbi.v2.tweak.ResultSetMapper; import org.skife.jdbi.v2.tweak.SQLLog; import org.skife.jdbi.v2.tweak.StatementBuilder; import org.skife.jdbi.v2.tweak.StatementBuilderFactory; import org.skife.jdbi.v2.tweak.StatementLocator; import org.skife.jdbi.v2.tweak.StatementRewriter; import org.skife.jdbi.v2.tweak.TransactionHandler; import org.skife.jdbi.v2.tweak.transactions.LocalTransactionHandler; import javax.sql.DataSource; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicReference; /** * This class provides the access point for jDBI. Use it to obtain Handle instances * and provide "global" configuration for all handles obtained from it. */ public class DBI implements IDBI { private final Map<String, Object> globalStatementAttributes = new ConcurrentHashMap<String, Object>(); private final MappingRegistry mappingRegistry = new MappingRegistry(); private final ContainerFactoryRegistry containerFactoryRegistry = new ContainerFactoryRegistry(); private final Foreman foreman = new Foreman(); private final ConnectionFactory connectionFactory; private AtomicReference<StatementRewriter> statementRewriter = new AtomicReference<StatementRewriter>(new ColonPrefixNamedParamStatementRewriter()); private AtomicReference<StatementLocator> statementLocator = new AtomicReference<StatementLocator>(new ClasspathStatementLocator()); private AtomicReference<TransactionHandler> transactionhandler = new AtomicReference<TransactionHandler>(new LocalTransactionHandler()); private AtomicReference<StatementBuilderFactory> statementBuilderFactory = new AtomicReference<StatementBuilderFactory>(new DefaultStatementBuilderFactory()); private AtomicReference<SQLLog> log = new AtomicReference<SQLLog>(new NoOpLog()); private AtomicReference<TimingCollector> timingCollector = new AtomicReference<TimingCollector>(TimingCollector.NOP_TIMING_COLLECTOR); private final Profiling<Connection, SQLException> prof; /** * Constructor for use with a DataSource which will provide * * @param dataSource */ public DBI(DataSource dataSource) { this(new DataSourceConnectionFactory(dataSource)); assert dataSource != null; } /** * Constructor used to allow for obtaining a Connection in a customized manner. * <p/> * The {@link org.skife.jdbi.v2.tweak.ConnectionFactory#openConnection()} method will * be invoked to obtain a connection instance whenever a Handle is opened. * * @param connectionFactory PrvidesJDBC connections to Handle instances */ public DBI(ConnectionFactory connectionFactory) { assert connectionFactory != null; this.connectionFactory = connectionFactory; this.prof = new Profiling<Connection, SQLException>(); } /** * Create a DBI which directly uses the DriverManager * * @param url JDBC URL for connections */ public DBI(final String url) { this(new ConnectionFactory() { @Override public Connection openConnection() throws SQLException { return DriverManager.getConnection(url); } }); } /** * Create a DBI which directly uses the DriverManager * * @param url JDBC URL for connections * @param props Properties to pass to DriverManager.getConnection(url, props) for each new handle */ public DBI(final String url, final Properties props) { this(new ConnectionFactory() { @Override public Connection openConnection() throws SQLException { return DriverManager.getConnection(url, props); } }); } /** * Create a DBI which directly uses the DriverManager * * @param url JDBC URL for connections * @param username User name for connection authentication * @param password Password for connection authentication */ public DBI(final String url, final String username, final String password) { this(new ConnectionFactory() { @Override public Connection openConnection() throws SQLException { return DriverManager.getConnection(url, username, password); } }); } /** * Use a non-standard StatementLocator to look up named statements for all * handles created from this DBi instance. * * @param locator StatementLocator which will be used by all Handle instances * created from this DBI */ public void setStatementLocator(StatementLocator locator) { assert locator != null; this.statementLocator.set(locator); } public StatementLocator getStatementLocator() { return this.statementLocator.get(); } /** * Use a non-standard StatementRewriter to transform SQL for all Handle instances * created by this DBI. * * @param rewriter StatementRewriter to use on all Handle instances */ public void setStatementRewriter(StatementRewriter rewriter) { assert rewriter != null; this.statementRewriter.set(rewriter); } public StatementRewriter getStatementRewriter() { return this.statementRewriter.get(); } /** * Specify the TransactionHandler instance to use. This allows overriding * transaction semantics, or mapping into different transaction * management systems. * <p/> * The default version uses local transactions on the database Connection * instances obtained. * * @param handler The TransactionHandler to use for all Handle instances obtained * from this DBI */ public void setTransactionHandler(TransactionHandler handler) { assert handler != null; this.transactionhandler.set(handler); } public TransactionHandler getTransactionHandler() { return this.transactionhandler.get(); } /** * Obtain a Handle to the data source wrapped by this DBI instance * * @return an open Handle instance */ @Override public Handle open() { return open(connectionFactory); } public Handle open(final ConnectionFactory connectionFactory) { try { final long start = System.nanoTime(); Connection conn = prof.executeWithProfiling(ProfilingFeatureType.DAO_CONNECTION, "get", new WithProfilingCallback<Connection, SQLException>() { @Override public Connection execute() throws SQLException { return connectionFactory.openConnection(); } }); final long stop = System.nanoTime(); StatementBuilder cache = statementBuilderFactory.get().createStatementBuilder(conn); Handle h = new BasicHandle(transactionhandler.get(), statementLocator.get(), cache, statementRewriter.get(), conn, globalStatementAttributes, log.get(), timingCollector.get(), mappingRegistry.createChild(), foreman.createChild(), containerFactoryRegistry.createChild()); log.get().logObtainHandle((stop - start) / 1000000L, h); return h; } catch (SQLException e) { throw new UnableToObtainConnectionException(e); } } /** * Register a result set mapper which will have its parameterized type inspected to determine what it maps to * * Will be used with {@link Query#mapTo(Class)} for registered mappings. */ public void registerMapper(ResultSetMapper mapper) { mappingRegistry.add(mapper); } /** * Register a result set mapper factory. * * Will be used with {@link Query#mapTo(Class)} for registerd mappings. */ public void registerMapper(ResultSetMapperFactory factory) { mappingRegistry.add(factory); } /** * Define an attribute on every {@link StatementContext} for every statement created * from a handle obtained from this DBI instance. * * @param key The key for the attribute * @param value the value for the attribute */ @Override public void define(String key, Object value) { this.globalStatementAttributes.put(key, value); } /** * A convenience function which manages the lifecycle of a handle and yields it to a callback * for use by clients. * * @param callback A callback which will receive an open Handle * * @return the value returned by callback * * @throws CallbackFailedException Will be thrown if callback raises an exception. This exception will * wrap the exception thrown by the callback. */ @Override public <ReturnType> ReturnType withHandle(HandleCallback<ReturnType> callback) throws CallbackFailedException { final Handle h = this.open(); try { return callback.withHandle(h); } catch (Exception e) { throw new CallbackFailedException(e); } finally { h.close(); } } /** * A convenience function which manages the lifecycle of a handle and yields it to a callback * for use by clients. The handle will be in a transaction when the callback is invoked, and * that transaction will be committed if the callback finishes normally, or rolled back if the * callback raises an exception. * * @param callback A callback which will receive an open Handle, in a transaction * * @return the value returned by callback * * @throws CallbackFailedException Will be thrown if callback raises an exception. This exception will * wrap the exception thrown by the callback. */ @Override public <ReturnType> ReturnType inTransaction(final TransactionCallback<ReturnType> callback) throws CallbackFailedException { return withHandle(new HandleCallback<ReturnType>() { @Override public ReturnType withHandle(Handle handle) throws Exception { return handle.inTransaction(callback); } }); } @Override public <ReturnType> ReturnType inTransaction(final TransactionIsolationLevel isolation, final TransactionCallback<ReturnType> callback) throws CallbackFailedException { return withHandle(new HandleCallback<ReturnType>() { @Override public ReturnType withHandle(Handle handle) throws Exception { return handle.inTransaction(isolation, callback); } }); } /** * Open a handle and attach a new sql object of the specified type to that handle. Be sure to close the * sql object (via a close() method, or calling {@link IDBI#close(Object)} * @param sqlObjectType an interface with annotations declaring desired behavior * @param <SqlObjectType> * @return a new sql object of the specified type, with a dedicated handle */ @Override public <SqlObjectType> SqlObjectType open(Class<SqlObjectType> sqlObjectType) { return SqlObjectBuilder.open(this, sqlObjectType); } /** * Create a new sql object which will obtain and release connections from this dbi instance, as it needs to, * and can, respectively. You should not explicitely close this sql object * * @param sqlObjectType an interface with annotations declaring desired behavior * @param <SqlObjectType> * @return a new sql object of the specified type, with a dedicated handle */ @Override public <SqlObjectType> SqlObjectType onDemand(Class<SqlObjectType> sqlObjectType) { return SqlObjectBuilder.onDemand(this, sqlObjectType); } /** * Used to close a sql object which lacks a close() method. * @param sqlObject the sql object to close */ @Override public void close(Object sqlObject) { if (sqlObject instanceof Handle) { // just because someone is *sure* to do it Handle h = (Handle) sqlObject; h.close(); } else { SqlObjectBuilder.close(sqlObject); } } /** * Convenience methd used to obtain a handle from a specific data source * * @param dataSource * * @return Handle using a Connection obtained from the provided DataSource */ public static Handle open(DataSource dataSource) { assert dataSource != null; return new DBI(dataSource).open(); } /** * Create a Handle wrapping a particular JDBC Connection * * @param connection * * @return Handle bound to connection */ public static Handle open(final Connection connection) { assert connection != null; return new DBI(new ConnectionFactory() { @Override public Connection openConnection() { return connection; } }).open(); } /** * Obtain a handle with just a JDBC URL * * @param url JDBC Url * * @return newly opened Handle */ public static Handle open(final String url) { assert url != null; return new DBI(url).open(); } /** * Obtain a handle with just a JDBC URL * * @param url JDBC Url * @param username JDBC username for authentication * @param password JDBC password for authentication * * @return newly opened Handle */ public static Handle open(final String url, final String username, final String password) { assert url != null; return new DBI(url, username, password).open(); } /** * Obtain a handle with just a JDBC URL * * @param url JDBC Url * @param props JDBC properties * * @return newly opened Handle */ public static Handle open(final String url, final Properties props) { assert url != null; return new DBI(url, props).open(); } /** * Allows customization of how prepared statements are created. When a Handle is created * against this DBI instance the factory will be used to create a StatementBuilder for * that specific handle. When the handle is closed, the StatementBuilder's close method * will be invoked. */ public void setStatementBuilderFactory(StatementBuilderFactory factory) { this.statementBuilderFactory.set(factory); } public StatementBuilderFactory getStatementBuilderFactory() { return this.statementBuilderFactory.get(); } /** * Specify the class used to log sql statements. Will be passed to all handles created from * this instance */ public void setSQLLog(SQLLog log) { this.log.set(log); } public SQLLog getSQLLog() { return this.log.get(); } /** * Add a callback to accumulate timing information about the queries running from this * data source. */ public void setTimingCollector(final TimingCollector timingCollector) { if (timingCollector == null) { this.timingCollector.set(TimingCollector.NOP_TIMING_COLLECTOR); } else { this.timingCollector.set(timingCollector); } } public TimingCollector getTimingCollector() { return this.timingCollector.get(); } public void registerArgumentFactory(ArgumentFactory<?> argumentFactory) { foreman.register(argumentFactory); } public void registerContainerFactory(ContainerFactory<?> factory) { this.containerFactoryRegistry.register(factory); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ParsedStatement.java
jdbi/src/main/java/org/skife/jdbi/v2/ParsedStatement.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; class ParsedStatement { private static final Pattern TOKEN_PATTERN = Pattern.compile(":(\\w+)"); private static final Pattern QUOTE_PATTERN = Pattern.compile("'.*'"); // private static final Pattern IN_PARAM_PATTERN = Pattern.compile("\\sin\\s*\\(\\?\\)"); private static final String[] EMPTY = new String[]{}; private final String[] tokens; private final String replaced; private boolean positionalOnly; public String[] getNamedParams() { return tokens; } public String getSubstitutedSql() { return replaced; } ParsedStatement(final String sql) { // attempt to short circuit if (sql.indexOf(":") == -1) { positionalOnly = true; // no named params, short circuit this.tokens = EMPTY; this.replaced = sql; return; } final Matcher token_matcher = TOKEN_PATTERN.matcher(sql); final Matcher quote_matcher = QUOTE_PATTERN.matcher(sql); boolean last_quote; boolean last_token; if (!(last_quote = quote_matcher.find())) { // we have no quotes, just replace tokens if there are any and exit this.replaced = token_matcher.replaceAll("?"); token_matcher.reset(); final List<String> tokens = new ArrayList<String>(); while (token_matcher.find()) { tokens.add(token_matcher.group().substring(token_matcher.group().indexOf(":") + 1)); } this.tokens = tokens.toArray(new String[tokens.size()]); } else if (last_token = token_matcher.find()) { // we have quotes and tokens, juggling time final List<String> tokens = new ArrayList<String>(); final StringBuffer replaced = new StringBuffer(); // copy everything up to beginning of first match into buffer final int end = quote_matcher.start() > token_matcher.start() ? token_matcher.start() : quote_matcher.start(); replaced.append(sql.substring(0, end)); do { if (last_token && last_quote) { // token and quote, crappo if (token_matcher.end() < quote_matcher.start()) { // token is before the quote // append ? and stuff to start of quote replaced.append("?"); tokens.add(token_matcher.group().substring(1, token_matcher.group().length())); replaced.append(sql.substring(token_matcher.end(), quote_matcher.start())); last_token = token_matcher.find(); } else if (token_matcher.start() > quote_matcher.end()) { // token is after quote replaced.append(sql.substring(quote_matcher.start(), token_matcher.start())); last_quote = quote_matcher.find(); } else { // token is inside quote replaced.append(sql.substring(quote_matcher.start(), quote_matcher.end())); // iterate through tokens until we escape the quote while (last_token = token_matcher.find()) { if (token_matcher.start() > quote_matcher.end()) { // found a token after the quote break; } } // or iterated through string and no more tokens last_quote = quote_matcher.find(); } } else if (last_token) { // found a token, but no more quotes replaced.append("?"); tokens.add(token_matcher.group().substring(1, token_matcher.group().length())); int index = token_matcher.end(); last_token = token_matcher.find(); replaced.append(sql.substring(index, last_token ? token_matcher.start() : sql.length())); } else // if (last_quote) { // quote, but no more tokens replaced.append(sql.substring(quote_matcher.start(), sql.length())); last_quote = false; } } while (last_token || last_quote); this.replaced = replaced.toString(); this.tokens = tokens.toArray(new String[tokens.size()]); } else { // no quotes, no tokens, piece of cake tokens = EMPTY; replaced = sql; } } public boolean isPositionalOnly() { return positionalOnly; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/InferredMapperFactory.java
jdbi/src/main/java/org/skife/jdbi/v2/InferredMapperFactory.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import com.fasterxml.classmate.ResolvedType; import com.fasterxml.classmate.TypeResolver; import org.skife.jdbi.v2.tweak.ResultSetMapper; import java.util.List; class InferredMapperFactory implements ResultSetMapperFactory { private static final TypeResolver tr = new TypeResolver(); private final Class maps; private final ResultSetMapper mapper; public InferredMapperFactory(ResultSetMapper mapper) { this.mapper = mapper; ResolvedType rt = tr.resolve(mapper.getClass()); List<ResolvedType> rs = rt.typeParametersFor(ResultSetMapper.class); if (rs.isEmpty() || rs.get(0).getErasedType().equals(Object.class)) { throw new UnsupportedOperationException("Must use a concretely typed ResultSetMapper here"); } maps = rs.get(0).getErasedType(); } @Override public boolean accepts(Class type, StatementContext ctx) { return maps.equals(type); } @Override public ResultSetMapper mapperFor(Class type, StatementContext ctx) { return mapper; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/CharacterStreamArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/CharacterStreamArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.io.Reader; import java.sql.PreparedStatement; import java.sql.SQLException; /** * */ class CharacterStreamArgument implements Argument { private final Reader value; private final int length; CharacterStreamArgument(Reader value, int length) { this.value = value; this.length = length; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { statement.setCharacterStream(position, value, length); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/BooleanIntegerArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/BooleanIntegerArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; /** * Takes a boolean and converts it into integer 0/1 column values. This is useful if your database does * not support boolean column types. */ class BooleanIntegerArgument implements Argument { private final boolean value; BooleanIntegerArgument(final boolean value) { this.value = value; } @Override public void apply(final int position, final PreparedStatement statement, final StatementContext ctx) throws SQLException { statement.setInt(position, value ? 1 : 0); } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/MappingRegistry.java
jdbi/src/main/java/org/skife/jdbi/v2/MappingRegistry.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.DBIException; import org.skife.jdbi.v2.tweak.ResultSetMapper; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; class MappingRegistry { private static final PrimitivesMapperFactory BUILT_IN_MAPPERS = new PrimitivesMapperFactory(); private final List<ResultSetMapperFactory> factories = new CopyOnWriteArrayList<ResultSetMapperFactory>(); private final ConcurrentHashMap<Class, ResultSetMapper> cache = new ConcurrentHashMap<Class, ResultSetMapper>(); /** * Copy Constructor */ MappingRegistry(MappingRegistry parent) { factories.addAll(parent.factories); cache.putAll(parent.cache); } public MappingRegistry() { } public void add(ResultSetMapper mapper) { this.add(new InferredMapperFactory(mapper)); } public void add(ResultSetMapperFactory factory) { factories.add(factory); cache.clear(); } public ResultSetMapper mapperFor(Class type, StatementContext ctx) { // check if cache must be bypassed Boolean bypassCache = Boolean.valueOf(String.valueOf(ctx.getAttribute("bypassMappingRegistryCache"))); if (cache.containsKey(type)) { ResultSetMapper mapper = cache.get(type); if (mapper != null) { return mapper; } } for (ResultSetMapperFactory factory : factories) { if (factory.accepts(type, ctx)) { ResultSetMapper mapper = factory.mapperFor(type, ctx); // bypass the cache if (!bypassCache.booleanValue()) { cache.put(type, mapper); } return mapper; } } if (BUILT_IN_MAPPERS.accepts(type, ctx)) { ResultSetMapper mapper = BUILT_IN_MAPPERS.mapperFor(type, ctx); cache.put(type, mapper); return mapper; } throw new DBIException("No mapper registered for " + type.getName()) {}; } public MappingRegistry createChild() { // [OPTIMIZATION] See above //return new MappingRegistry(this); return this; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/DelegatingConnection.java
jdbi/src/main/java/org/skife/jdbi/v2/DelegatingConnection.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.sql.Array; import java.sql.Blob; import java.sql.CallableStatement; import java.sql.Clob; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.NClob; import java.sql.PreparedStatement; import java.sql.SQLClientInfoException; import java.sql.SQLException; import java.sql.SQLWarning; import java.sql.SQLXML; import java.sql.Savepoint; import java.sql.Statement; import java.sql.Struct; import java.util.Map; import java.util.Properties; import java.util.concurrent.Executor; /** * Convenience class for intercepting Connection behavior. */ public class DelegatingConnection implements Connection { private final Connection connection; public DelegatingConnection(Connection delegate) { this.connection = delegate; } @Override public Statement createStatement() throws SQLException { return connection.createStatement(); } @Override public PreparedStatement prepareStatement(String s) throws SQLException { return connection.prepareStatement(s); } @Override public CallableStatement prepareCall(String s) throws SQLException { return connection.prepareCall(s); } @Override public String nativeSQL(String s) throws SQLException { return connection.nativeSQL(s); } @Override public boolean getAutoCommit() throws SQLException { return connection.getAutoCommit(); } @Override public void setAutoCommit(boolean b) throws SQLException { connection.setAutoCommit(b); } @Override public void commit() throws SQLException { connection.commit(); } @Override public void rollback() throws SQLException { connection.rollback(); } @Override public void close() throws SQLException { connection.close(); } @Override public boolean isClosed() throws SQLException { return connection.isClosed(); } @Override public DatabaseMetaData getMetaData() throws SQLException { return connection.getMetaData(); } @Override public boolean isReadOnly() throws SQLException { return connection.isReadOnly(); } @Override public void setReadOnly(boolean b) throws SQLException { connection.setReadOnly(b); } @Override public String getCatalog() throws SQLException { return connection.getCatalog(); } @Override public void setCatalog(String s) throws SQLException { connection.setCatalog(s); } @Override public int getTransactionIsolation() throws SQLException { return connection.getTransactionIsolation(); } @Override public void setTransactionIsolation(int i) throws SQLException { connection.setTransactionIsolation(i); } @Override public SQLWarning getWarnings() throws SQLException { return connection.getWarnings(); } @Override public void clearWarnings() throws SQLException { connection.clearWarnings(); } @Override public Statement createStatement(int i, int i1) throws SQLException { return connection.createStatement(i, i1); } @Override public PreparedStatement prepareStatement(String s, int i, int i1) throws SQLException { return connection.prepareStatement(s, i, i1); } @Override public CallableStatement prepareCall(String s, int i, int i1) throws SQLException { return connection.prepareCall(s, i, i1); } @Override public Map<String, Class<?>> getTypeMap() throws SQLException { return connection.getTypeMap(); } @Override public void setTypeMap(Map<String, Class<?>> map) throws SQLException { connection.setTypeMap(map); } @Override public int getHoldability() throws SQLException { return connection.getHoldability(); } @Override public void setHoldability(int i) throws SQLException { connection.setHoldability(i); } @Override public Savepoint setSavepoint() throws SQLException { return connection.setSavepoint(); } @Override public Savepoint setSavepoint(String s) throws SQLException { return connection.setSavepoint(s); } @Override public void rollback(Savepoint savepoint) throws SQLException { connection.rollback(savepoint); } @Override public void releaseSavepoint(Savepoint savepoint) throws SQLException { connection.releaseSavepoint(savepoint); } @Override public Statement createStatement(int i, int i1, int i2) throws SQLException { return connection.createStatement(i, i1, i2); } @Override public PreparedStatement prepareStatement(String s, int i, int i1, int i2) throws SQLException { return connection.prepareStatement(s, i, i1, i2); } @Override public CallableStatement prepareCall(String s, int i, int i1, int i2) throws SQLException { return connection.prepareCall(s, i, i1, i2); } @Override public PreparedStatement prepareStatement(String s, int i) throws SQLException { return connection.prepareStatement(s, i); } @Override public PreparedStatement prepareStatement(String s, int[] ints) throws SQLException { return connection.prepareStatement(s, ints); } @Override public PreparedStatement prepareStatement(String s, String[] strings) throws SQLException { return connection.prepareStatement(s, strings); } @Override public Clob createClob() throws SQLException { return connection.createClob(); } @Override public Blob createBlob() throws SQLException { return connection.createBlob(); } @Override public NClob createNClob() throws SQLException { return connection.createNClob(); } @Override public SQLXML createSQLXML() throws SQLException { return connection.createSQLXML(); } @Override public boolean isValid(int timeout) throws SQLException { return connection.isValid(timeout); } @Override public void setClientInfo(String name, String value) throws SQLClientInfoException { connection.setClientInfo(name, value); } @Override public String getClientInfo(String name) throws SQLException { return connection.getClientInfo(name); } @Override public Properties getClientInfo() throws SQLException { return connection.getClientInfo(); } @Override public void setClientInfo(Properties properties) throws SQLClientInfoException { connection.setClientInfo(properties); } @Override public Array createArrayOf(String typeName, Object[] elements) throws SQLException { return connection.createArrayOf(typeName, elements); } @Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return connection.createStruct(typeName, attributes); } @Override public <T> T unwrap(Class<T> iface) throws SQLException { return connection.unwrap(iface); } @Override public boolean isWrapperFor(Class<?> iface) throws SQLException { return connection.isWrapperFor(iface); } public String getSchema() throws SQLException { try { Method m = connection.getClass().getDeclaredMethod("getSchema"); return (String) m.invoke(connection); } catch (NoSuchMethodException e) { throw new IllegalStateException("getSchema does not exist in this Java version"); } catch (InvocationTargetException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw new IllegalStateException(e); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } } public void setSchema(String schema) throws SQLException { try { Method m = connection.getClass().getDeclaredMethod("setSchema", String.class); m.invoke(connection, schema); } catch (NoSuchMethodException e) { throw new IllegalStateException("setSchema does not exist in this Java version"); } catch (InvocationTargetException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw new IllegalStateException(e); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } } public void abort(Executor executor) throws SQLException { try { Method m = connection.getClass().getDeclaredMethod("abort"); m.invoke(connection, executor); } catch (NoSuchMethodException e) { throw new IllegalStateException("abort does not exist in this Java version"); } catch (InvocationTargetException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw new IllegalStateException(e); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } } public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { try { Method m = connection.getClass().getDeclaredMethod("setNetworkTimeout"); m.invoke(connection, executor, milliseconds); } catch (NoSuchMethodException e) { throw new IllegalStateException("setNetworkTimeout does not exist in this Java version"); } catch (InvocationTargetException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw new IllegalStateException(e); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } } public int getNetworkTimeout() throws SQLException { try { Method m = connection.getClass().getDeclaredMethod("getNetworkTimeout"); return (Integer) m.invoke(connection); } catch (NoSuchMethodException e) { throw new IllegalStateException("getNetworkTimeout does not exist in this Java version"); } catch (InvocationTargetException e) { if (e.getCause() instanceof SQLException) { throw (SQLException) e.getCause(); } else { throw new IllegalStateException(e); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/ClasspathStatementLocator.java
jdbi/src/main/java/org/skife/jdbi/v2/ClasspathStatementLocator.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.UnableToCreateStatementException; import org.skife.jdbi.v2.tweak.StatementLocator; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.Collections; import java.util.Map; import java.util.WeakHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * looks for [name], then [name].sql on the classpath */ public class ClasspathStatementLocator implements StatementLocator { private static final Pattern MULTILINE_COMMENTS = Pattern.compile("/\\*.*?\\*/"); private final Map<String, String> found = Collections.synchronizedMap(new WeakHashMap<String, String>()); /** * Very basic sanity test to see if a string looks like it might be sql */ public static boolean looksLikeSql(String sql) { final String local = left(stripStart(sql), 8).toLowerCase(); return local.startsWith("insert ") || local.startsWith("update ") || local.startsWith("select ") || local.startsWith("call ") || local.startsWith("delete ") || local.startsWith("create ") || local.startsWith("alter ") || local.startsWith("merge ") || local.startsWith("replace ") || local.startsWith("drop "); } /** * If the passed in name doesn't look like SQL it will search the classpath for a file * which looks like the provided name. * <p/> * The "looks like" algorithm is not very sophisticated, it basically looks for the string * to begin with insert, update, select, call, delete, create, alter, or drop followed * by a space. * <p/> * If no resource is found using the passed in string, the string s returned as-is * * @param name Name or statement literal * * @return SQL to execute (which will go to a StatementRRewrter first) * * @throws UnableToCreateStatementException * if an IOException occurs reading a found resource */ @Override @SuppressWarnings("PMD.EmptyCatchBlock") public String locate(String name, StatementContext ctx) throws Exception { final String cache_key; if (ctx.getSqlObjectType() != null) { cache_key = '/' + mungify(ctx.getSqlObjectType().getName() + '.' + name) + ".sql"; } else { cache_key = name; } if (found.containsKey(cache_key)) { return found.get(cache_key); } if (looksLikeSql(name)) { // No need to cache individual SQL statements that don't cause us to search the classpath return name; } final ClassLoader loader = selectClassLoader(); BufferedReader reader = null; try { InputStream in_stream = loader.getResourceAsStream(name); if (in_stream == null) { in_stream = loader.getResourceAsStream(name + ".sql"); } if (in_stream == null && ctx.getSqlObjectType() != null) { String filename = '/' + mungify(ctx.getSqlObjectType().getName() + '.' + name) + ".sql"; in_stream = loader.getResourceAsStream(filename); if (in_stream == null) { in_stream = ctx.getSqlObjectType().getResourceAsStream(filename); } } if (in_stream == null) { // Ensure we don't store an identity map entry which has a hard reference // to the key (through the value) by copying the value, avoids potential memory leak. found.put(cache_key, name == cache_key ? new String(name) : name); return name; } final StringBuffer buffer = new StringBuffer(); reader = new BufferedReader(new InputStreamReader(in_stream, Charset.forName("UTF-8"))); String line; try { while ((line = reader.readLine()) != null) { if (isComment(line)) { // comment continue; } buffer.append(line).append(" "); } } catch (IOException e) { throw new UnableToCreateStatementException(e.getMessage(), e, ctx); } String sql = MULTILINE_COMMENTS.matcher(buffer).replaceAll(""); found.put(cache_key, sql); return sql; } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { // nothing we can do here :-( } } } /** * There *must* be a better place to put this without creating a helpers class just for it */ private static ClassLoader selectClassLoader() { ClassLoader loader; if (Thread.currentThread().getContextClassLoader() != null) { loader = Thread.currentThread().getContextClassLoader(); } else { loader = ClasspathStatementLocator.class.getClassLoader(); } return loader; } private static boolean isComment(final String line) { return line.startsWith("#") || line.startsWith("--") || line.startsWith("//"); } private static final String SEP = "/"; // *Not* System.getProperty("file.separator"), which breaks in jars private static String mungify(String path) { return path.replaceAll("\\.", Matcher.quoteReplacement(SEP)); } // (scs) Logic copied from commons-lang3 3.1 with minor edits, per discussion on commit 023a14ade2d33bf8ccfa0f68294180455233ad52 private static String stripStart(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return ""; } int start = 0; while (start != strLen && Character.isWhitespace(str.charAt(start))) { start++; } return str.substring(start); } private static String left(String str, int len) { if (str == null || len < 0) { return ""; } if (str.length() <= len) { return str; } return str.substring(0, len); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/TransactionState.java
jdbi/src/main/java/org/skife/jdbi/v2/TransactionState.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; public enum TransactionState { ROLLBACK, COMMIT; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/VoidTransactionCallback.java
jdbi/src/main/java/org/skife/jdbi/v2/VoidTransactionCallback.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; /** * Abstract {@link TransactionCallback} that doesn't return a result. */ public abstract class VoidTransactionCallback implements TransactionCallback<Void> { /** * This implementation delegates to {@link #execute}. * * @param handle {@inheritDoc} * @return nothing * @throws Exception {@inheritDoc} */ @Override public final Void inTransaction(Handle handle, TransactionStatus status) throws Exception { execute(handle, status); return null; } /** * {@link #inTransaction} will delegate to this method. * * @param handle Handle to be used only within scope of this callback * @param status Allows rolling back the transaction * @throws Exception will result in a {@link org.skife.jdbi.v2.exceptions.CallbackFailedException} wrapping * the exception being thrown */ protected abstract void execute(Handle handle, TransactionStatus status) throws Exception; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/IntegerArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/IntegerArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * */ class IntegerArgument implements Argument { private final Integer value; IntegerArgument(Integer value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value == null) { statement.setNull(position, Types.INTEGER); } else { statement.setInt(position, value); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/LongArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/LongArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * */ class LongArgument implements Argument { private final Long value; LongArgument(Long value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setLong(position, value); } else { statement.setNull(position, Types.INTEGER); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/TransactionCallback.java
jdbi/src/main/java/org/skife/jdbi/v2/TransactionCallback.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; /** * Used as a callback which guarantees that the inTransaction method is invoked in * a transaction, and will be committed or rolled back as specified. */ public interface TransactionCallback<ReturnType> { ReturnType inTransaction(Handle conn, TransactionStatus status) throws Exception; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/Folder.java
jdbi/src/main/java/org/skife/jdbi/v2/Folder.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import java.sql.ResultSet; import java.sql.SQLException; /** * Used to define a function for <a href="http://en.wikipedia.org/wiki/Fold_(higher-order_function)">folding</a> * over the result set of a query. * @see org.skife.jdbi.v2.Query#fold(Object, Folder) * @deprecated Prefer Folder2, in jdbi3 Folder2 will be renamed Folder and this form will go away */ @Deprecated public interface Folder<AccumulatorType> { /** * Invoked once per row in the result set from the query. * * @param accumulator The initial value passed to {@link org.skife.jdbi.v2.Query#fold(Object, Folder)} * for the first call, the return value from the previous call thereafter. * @param rs The actual result set from the query. It will already have been advanced to the * correct row. Callbacks should not call {@link java.sql.ResultSet#next()} * @return A value which will be passed to the next invocation of this function. The final * invocation will be returned from the {@link org.skife.jdbi.v2.Query#fold(Object, Folder)} call. * @throws SQLException will be wrapped and rethrown as a {@link org.skife.jdbi.v2.exceptions.CallbackFailedException} */ AccumulatorType fold(AccumulatorType accumulator, ResultSet rs) throws SQLException; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/FloatArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/FloatArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * */ class FloatArgument implements Argument { private final Float value; FloatArgument(Float value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setFloat(position, value); } else { statement.setNull(position, Types.FLOAT); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/BlobArgument.java
jdbi/src/main/java/org/skife/jdbi/v2/BlobArgument.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.tweak.Argument; import java.sql.Blob; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * */ class BlobArgument implements Argument { private Blob value; BlobArgument(Blob value) { this.value = value; } @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { if (value != null) { statement.setBlob(position, value); } else { statement.setNull(position, Types.BLOB); } } @Override public String toString() { return String.valueOf(value); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/BaseStatement.java
jdbi/src/main/java/org/skife/jdbi/v2/BaseStatement.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2; import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; import org.skife.jdbi.v2.tweak.BaseStatementCustomizer; import org.skife.jdbi.v2.tweak.StatementCustomizer; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; abstract class BaseStatement { private static final StatementCleaningCustomizer STATEMENT_CLEANING_CUSTOMIZER = new StatementCleaningCustomizer(); private final Collection<StatementCustomizer> customizers = new ArrayList<StatementCustomizer>(); private final ConcreteStatementContext context; private final Foreman foreman; protected BaseStatement(final ConcreteStatementContext context, Foreman foreman) { this.context = context; this.foreman = foreman.createChild(); addCustomizer(STATEMENT_CLEANING_CUSTOMIZER); } protected final Foreman getForeman() { return foreman; } protected final ConcreteStatementContext getConcreteContext() { return this.context; } /** * Obtain the statement context associated with this statement */ public final StatementContext getContext() { return context; } protected void addCustomizers(final Collection<StatementCustomizer> customizers) { this.customizers.addAll(customizers); } protected void addCustomizer(final StatementCustomizer customizer) { this.customizers.add(customizer); } protected Collection<StatementCustomizer> getStatementCustomizers() { return this.customizers; } protected final void beforeExecution(final PreparedStatement stmt) { for (StatementCustomizer customizer : customizers) { try { customizer.beforeExecution(stmt, context); } catch (SQLException e) { throw new UnableToExecuteStatementException("Exception thrown in statement customization", e, context); } } } protected final void afterExecution(final PreparedStatement stmt) { for (StatementCustomizer customizer : customizers) { try { customizer.afterExecution(stmt, context); } catch (SQLException e) { throw new UnableToExecuteStatementException("Exception thrown in statement customization", e, context); } } } protected final void cleanup() { for (StatementCustomizer customizer : customizers) { try { customizer.cleanup(context); } catch (SQLException e) { throw new UnableToExecuteStatementException("Could not clean up", e, context); } } } protected void addCleanable(final Cleanable cleanable) { this.context.getCleanables().add(cleanable); } static class StatementCleaningCustomizer extends BaseStatementCustomizer { @Override public final void cleanup(final StatementContext context) throws SQLException { final List<SQLException> exceptions = new ArrayList<SQLException>(); try { List<Cleanable> cleanables = new ArrayList<Cleanable>(context.getCleanables()); Collections.reverse(cleanables); for (Cleanable cleanable : cleanables) { try { cleanable.cleanup(); } catch (SQLException sqlException) { exceptions.add(sqlException); } } context.getCleanables().clear(); } finally { if (exceptions.size() > 1) { // Chain multiple SQLExceptions together to be one big exceptions. // (Wonder if that actually works...) for (int i = 0; i < (exceptions.size() - 1); i++) { exceptions.get(i).setNextException(exceptions.get(i + 1)); } } if (exceptions.size() > 0) { throw exceptions.get(0); } } } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/URLMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/URLMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.net.URL; import java.sql.ResultSet; import java.sql.SQLException; public class URLMapper extends TypedMapper<URL> { public URLMapper() { super(); } public URLMapper(int index) { super(index); } public URLMapper(String name) { super(name); } @Override protected URL extractByName(ResultSet r, String name) throws SQLException { return r.getURL(name); } @Override protected URL extractByIndex(ResultSet r, int index) throws SQLException { return r.getURL(index); } public static final URLMapper FIRST = new URLMapper(); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/ShortMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/ShortMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.sql.ResultSet; import java.sql.SQLException; public class ShortMapper extends TypedMapper<Short> { public ShortMapper() { super(); } public ShortMapper(int index) { super(index); } public ShortMapper(String name) { super(name); } @Override protected Short extractByName(ResultSet r, String name) throws SQLException { return r.getShort(name); } @Override protected Short extractByIndex(ResultSet r, int index) throws SQLException { return r.getShort(index); } public static final ShortMapper FIRST = new ShortMapper(); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/TimestampMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/TimestampMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; /** * Convenience ResultSetMapper for extracting a single value result * from a query. */ public class TimestampMapper extends TypedMapper<Timestamp> { /** * An instance which extracts value from the first field */ public static final TimestampMapper FIRST = new TimestampMapper(1); /** * Create a new instance which extracts the value from the first column */ public TimestampMapper() { super(); } /** * Create a new instance which extracts the value positionally * in the result set * * @param index 1 based column index into the result set */ public TimestampMapper(int index) { super(index); } /** * Create a new instance which extracts the value by name or alias from the result set * * @param name The name or alias for the field */ public TimestampMapper(String name) { super(name); } @Override protected Timestamp extractByName(ResultSet r, String name) throws SQLException { return r.getTimestamp(name); } @Override protected Timestamp extractByIndex(ResultSet r, int index) throws SQLException { return r.getTimestamp(index); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/DoubleMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/DoubleMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.sql.ResultSet; import java.sql.SQLException; public class DoubleMapper extends TypedMapper<Double> { public DoubleMapper() { super(); } public DoubleMapper(int index) { super(index); } public DoubleMapper(String name) { super(name); } @Override protected Double extractByName(ResultSet r, String name) throws SQLException { return r.getDouble(name); } @Override protected Double extractByIndex(ResultSet r, int index) throws SQLException { return r.getDouble(index); } public static final DoubleMapper FIRST = new DoubleMapper(); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/BigDecimalMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/BigDecimalMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.SQLException; public class BigDecimalMapper extends TypedMapper<BigDecimal> { public BigDecimalMapper() { super(); } public BigDecimalMapper(int index) { super(index); } public BigDecimalMapper(String name) { super(name); } @Override protected BigDecimal extractByName(ResultSet r, String name) throws SQLException { return r.getBigDecimal(name); } @Override protected BigDecimal extractByIndex(ResultSet r, int index) throws SQLException { return r.getBigDecimal(index); } public static final BigDecimalMapper FIRST = new BigDecimalMapper(); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/StringMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/StringMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.sql.ResultSet; import java.sql.SQLException; /** * Convenience ResultSetMapper for extracting a single value result * from a query. */ public class StringMapper extends TypedMapper<String> { /** * An instance which extracts value from the first field */ public static final StringMapper FIRST = new StringMapper(1); /** * Create a new instance which extracts the value from the first column */ public StringMapper() { super(); } /** * Create a new instance which extracts the value positionally * in the result set * * @param index 1 based column index into the result set */ public StringMapper(int index) { super(index); } /** * Create a new instance which extracts the value by name or alias from the result set * * @param name The name or alias for the field */ public StringMapper(String name) { super(name); } @Override protected String extractByName(ResultSet r, String name) throws SQLException { return r.getString(name); } @Override protected String extractByIndex(ResultSet r, int index) throws SQLException { return r.getString(index); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/TypedMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/TypedMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import org.skife.jdbi.v2.StatementContext; import org.skife.jdbi.v2.tweak.ResultSetMapper; import java.sql.ResultSet; import java.sql.SQLException; /** * Convenience base class for implementing typed result set mappers. Provides * frequently used functionality. */ public abstract class TypedMapper<T> implements ResultSetMapper<T> { private final ResultSetMapper<T> internal; /** * Create a new instance which extracts the value from the first column */ public TypedMapper() { this(1); } /** * Create a new instance which extracts the value positionally * in the result set * * @param index 1 based column index into the result set */ public TypedMapper(int index) { internal = new IndexMapper(index); } /** * Create a new instance which extracts the value by name or alias from the result set * * @param name The name or alias for the field */ public TypedMapper(String name) { internal = new StringMapper(name); } @Override public final T map(int index, ResultSet r, StatementContext ctx) throws SQLException { return internal.map(index, r, ctx); } protected abstract T extractByName(ResultSet r, String name) throws SQLException; protected abstract T extractByIndex(ResultSet r, int index) throws SQLException; private class StringMapper implements ResultSetMapper<T> { private final String name; StringMapper(String name) { this.name = name; } @Override public T map(int index, ResultSet r, StatementContext ctx) throws SQLException { return extractByName(r, name); } } private class IndexMapper implements ResultSetMapper<T> { private final int index; IndexMapper(int index) { this.index = index; } @Override public T map(int index, ResultSet r, StatementContext ctx) throws SQLException { return extractByIndex(r, this.index); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/BooleanMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/BooleanMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.sql.ResultSet; import java.sql.SQLException; /** * Convenience ResultSetMapper for extracting a single value result * from a query. */ public class BooleanMapper extends TypedMapper<Boolean> { /** * An instance which extracts value from the first field */ public static final BooleanMapper FIRST = new BooleanMapper(1); /** * Create a new instance which extracts the value from the first column */ public BooleanMapper() { super(); } /** * Create a new instance which extracts the value positionally * in the result set * * @param index 1 based column index into the result set */ public BooleanMapper(int index) { super(index); } /** * Create a new instance which extracts the value by name or alias from the result set * * @param name The name or alias for the field */ public BooleanMapper(String name) { super(name); } @Override protected Boolean extractByName(ResultSet r, String name) throws SQLException { return r.getBoolean(name); } @Override protected Boolean extractByIndex(ResultSet r, int index) throws SQLException { return r.getBoolean(index); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/ByteMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/ByteMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.sql.ResultSet; import java.sql.SQLException; public class ByteMapper extends TypedMapper<Byte> { public ByteMapper() { super(); } public ByteMapper(int index) { super(index); } public ByteMapper(String name) { super(name); } @Override protected Byte extractByName(ResultSet r, String name) throws SQLException { return r.getByte(name); } @Override protected Byte extractByIndex(ResultSet r, int index) throws SQLException { return r.getByte(index); } public static final ByteMapper FIRST = new ByteMapper(); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/ByteArrayMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/ByteArrayMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.sql.ResultSet; import java.sql.SQLException; public class ByteArrayMapper extends TypedMapper<byte[]> { public ByteArrayMapper() { super(); } public ByteArrayMapper(int index) { super(index); } public ByteArrayMapper(String name) { super(name); } @Override protected byte[] extractByName(ResultSet r, String name) throws SQLException { return r.getBytes(name); } @Override protected byte[] extractByIndex(ResultSet r, int index) throws SQLException { return r.getBytes(index); } public static final ByteArrayMapper FIRST = new ByteArrayMapper(); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/LongMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/LongMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.sql.ResultSet; import java.sql.SQLException; /** * Convenience ResultSetMapper for extracting a single value result * from a query. */ public class LongMapper extends TypedMapper<Long> { /** * An instance which extracts value from the first field */ public static final LongMapper FIRST = new LongMapper(1); /** * Create a new instance which extracts the value from the first column */ public LongMapper() { super(); } /** * Create a new instance which extracts the value positionally * in the result set * * @param index 1 based column index into the result set */ public LongMapper(int index) { super(index); } /** * Create a new instance which extracts the value by name or alias from the result set * * @param name The name or alias for the field */ public LongMapper(String name) { super(name); } @Override protected Long extractByName(ResultSet r, String name) throws SQLException { return r.getLong(name); } @Override protected Long extractByIndex(ResultSet r, int index) throws SQLException { return r.getLong(index); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/IntegerMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/IntegerMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.sql.ResultSet; import java.sql.SQLException; /** * Convenience ResultSetMapper for extracting a single value result * from a query. */ public class IntegerMapper extends TypedMapper<Integer> { /** * An instance which extracts value from the first field */ public static final IntegerMapper FIRST = new IntegerMapper(1); /** * Create a new instance which extracts the value positionally * in the result set * * @param index 1 based column index into the result set */ public IntegerMapper(int index) { super(index); } /** * Create a new instance which extracts the value from the first column */ public IntegerMapper() { super(1); } /** * Create a new instance which extracts the value by name or alias from the result set * * @param name The name or alias for the field */ public IntegerMapper(String name) { super(name); } @Override protected Integer extractByName(ResultSet r, String name) throws SQLException { return r.getInt(name); } @Override protected Integer extractByIndex(ResultSet r, int index) throws SQLException { return r.getInt(index); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/util/FloatMapper.java
jdbi/src/main/java/org/skife/jdbi/v2/util/FloatMapper.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.util; import java.sql.ResultSet; import java.sql.SQLException; public class FloatMapper extends TypedMapper<Float> { public FloatMapper() { super(); } public FloatMapper(int index) { super(index); } public FloatMapper(String name) { super(name); } @Override protected Float extractByName(ResultSet r, String name) throws SQLException { return r.getFloat(name); } @Override protected Float extractByIndex(ResultSet r, int index) throws SQLException { return r.getFloat(index); } public static final FloatMapper FIRST = new FloatMapper(); }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToRestoreAutoCommitStateException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToRestoreAutoCommitStateException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; public class UnableToRestoreAutoCommitStateException extends DBIException { private static final long serialVersionUID = 2433069110223543423L; public UnableToRestoreAutoCommitStateException(Throwable throwable) { super(throwable); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToCloseResourceException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToCloseResourceException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; public class UnableToCloseResourceException extends DBIException { public UnableToCloseResourceException(String string, Throwable throwable) { super(string, throwable); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToManipulateTransactionIsolationLevelException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToManipulateTransactionIsolationLevelException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; import java.sql.SQLException; public class UnableToManipulateTransactionIsolationLevelException extends DBIException { public UnableToManipulateTransactionIsolationLevelException(int i, SQLException e) { super("Unable to set isolation level to " + i, e); } public UnableToManipulateTransactionIsolationLevelException(String msg, SQLException e) { super(msg, e); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/DBIException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/DBIException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; /** * Base runtime exception for exceptions thrown from jDBI */ public abstract class DBIException extends RuntimeException { public DBIException(String string, Throwable throwable) { super(string, throwable); } public DBIException(Throwable cause) { super(cause); } /** * Constructs a new runtime exception with the specified detail message. * The cause is not initialized, and may subsequently be initialized by a * call to {@link #initCause}. * * @param message the detail message. The detail message is saved for * later retrieval by the {@link #getMessage()} method. */ public DBIException(String message) { super(message); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/TransactionFailedException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/TransactionFailedException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; public class TransactionFailedException extends DBIException { public TransactionFailedException(String string, Throwable throwable) { super(string, throwable); } public TransactionFailedException(Throwable cause) { super(cause); } public TransactionFailedException(String message) { super(message); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/ResultSetException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/ResultSetException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; import org.skife.jdbi.v2.StatementContext; public class ResultSetException extends StatementException { public ResultSetException(String msg, Exception e, StatementContext ctx) { super(msg, e, ctx); } /** * @deprecated */ public ResultSetException(String msg, Exception e) { super(msg, e, null); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/CallbackFailedException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/CallbackFailedException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; /** * Exception used to indicate an exception thrown during a provided callback. The wrapped * throwable will be the client library thrown checked exception. */ public class CallbackFailedException extends DBIException { public CallbackFailedException(String string, Throwable throwable) { super(string, throwable); } public CallbackFailedException(Throwable cause) { super(cause); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToObtainConnectionException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToObtainConnectionException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; public class UnableToObtainConnectionException extends DBIException { public UnableToObtainConnectionException(Throwable cause) { super(cause); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/StatementException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/StatementException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; import org.skife.jdbi.v2.StatementContext; /** * */ public abstract class StatementException extends DBIException { private final StatementContext statementContext; public StatementException(String string, Throwable throwable, StatementContext ctx) { super(string, throwable); this.statementContext = ctx; } public StatementException(Throwable cause, StatementContext ctx) { super(cause); this.statementContext = ctx; } public StatementException(String message, StatementContext ctx) { super(message); this.statementContext = ctx; } /** * @deprecated */ public StatementException(String string, Throwable throwable) { super(string, throwable); this.statementContext = null; } /** * @deprecated */ public StatementException(Throwable cause) { super(cause); this.statementContext = null; } /** * @deprecated */ public StatementException(String message) { super(message); this.statementContext = null; } public StatementContext getStatementContext() { return statementContext; } @Override public String getMessage() { String base = super.getMessage(); StatementContext ctx = getStatementContext(); if (ctx == null) { return base; } else { return String.format("%s [statement:\"%s\", located:\"%s\", rewritten:\"%s\", arguments:%s]", base, ctx.getRawSql(), ctx.getLocatedSql(), ctx.getRewrittenSql(), ctx.getBinding()); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/NoResultsException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/NoResultsException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; import org.skife.jdbi.v2.StatementContext; public class NoResultsException extends StatementException { public NoResultsException(String msg, Throwable e, StatementContext ctx) { super(msg, e, ctx); } public NoResultsException(Throwable e, StatementContext ctx) { super(e, ctx); } public NoResultsException(String msg, StatementContext ctx) { super(msg, ctx); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToExecuteStatementException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToExecuteStatementException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; import org.skife.jdbi.v2.StatementContext; public class UnableToExecuteStatementException extends StatementException { public UnableToExecuteStatementException(Exception e, StatementContext ctx) { super(e, ctx); } public UnableToExecuteStatementException(String message, StatementContext ctx) { super(message, ctx); } public UnableToExecuteStatementException(String string, Throwable throwable, StatementContext ctx) { super(string, throwable, ctx); } /** * @deprecated */ public UnableToExecuteStatementException(Exception e) { super(e, null); } /** * @deprecated */ public UnableToExecuteStatementException(String message) { super(message, (StatementContext) null); } /** * @deprecated */ public UnableToExecuteStatementException(String string, Throwable throwable) { super(string, throwable, null); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToCreateStatementException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/UnableToCreateStatementException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; import org.skife.jdbi.v2.StatementContext; public class UnableToCreateStatementException extends StatementException { public UnableToCreateStatementException(String string, Throwable throwable, StatementContext ctx) { super(string, throwable, ctx); } public UnableToCreateStatementException(Exception e, StatementContext ctx) { super(e, ctx); } /** * @deprecated */ public UnableToCreateStatementException(String string, Throwable throwable) { super(string, throwable, null); } /** * @deprecated */ public UnableToCreateStatementException(Exception e) { super(e, null); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/exceptions/TransactionException.java
jdbi/src/main/java/org/skife/jdbi/v2/exceptions/TransactionException.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.exceptions; /** * */ public class TransactionException extends DBIException { public TransactionException(String string, Throwable throwable) { super(string, throwable); } public TransactionException(Throwable cause) { super(cause); } public TransactionException(String msg) { super(msg); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/logging/NoOpLog.java
jdbi/src/main/java/org/skife/jdbi/v2/logging/NoOpLog.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.logging; import org.skife.jdbi.v2.Handle; import org.skife.jdbi.v2.tweak.SQLLog; /** * Default SQLLog implementation, does nothing */ public final class NoOpLog implements SQLLog { static final BatchLogger batch = new BatchLogger() { @Override public void add(String sql) { } @Override public void log(long time) { } }; @Override public void logBeginTransaction(Handle h) { } @Override public void logCommitTransaction(long time, Handle h) { } @Override public void logRollbackTransaction(long time, Handle h) { } @Override public void logObtainHandle(long time, Handle h) { } @Override public void logReleaseHandle(Handle h) { } @Override public void logSQL(long time, String sql) { } @Override public void logPreparedBatch(long time, String sql, int count) { } @Override public BatchLogger logBatch() { return batch; } @Override public void logCheckpointTransaction(Handle h, String name) { } @Override public void logReleaseCheckpointTransaction(Handle h, String name) { } @Override public void logRollbackToCheckpoint(long time, Handle h, String checkpointName) { } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/logging/FormattedLog.java
jdbi/src/main/java/org/skife/jdbi/v2/logging/FormattedLog.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.logging; import org.skife.jdbi.v2.Handle; import org.skife.jdbi.v2.tweak.SQLLog; /** * Convenience class which handles log statement formatting */ public abstract class FormattedLog implements SQLLog { @Override public final void logSQL(long time, String sql) { if (isEnabled()) { log(String.format("statement:[%s] took %d millis", sql, time)); } } /** * Used to ask implementations if logging is enabled. * * @return true if statement logging is enabled */ protected abstract boolean isEnabled(); /** * Log the statement passed in * @param msg the message to log */ protected abstract void log(String msg); @Override public final void logPreparedBatch(long time, String sql, int count) { if (isEnabled()) { log(String.format("prepared batch with %d parts:[%s] took %d millis", count, sql, time)); } } @Override public final BatchLogger logBatch() { if (isEnabled()) { final StringBuilder builder = new StringBuilder(); builder.append("batch:["); return new BatchLogger() { private boolean added = false; @Override public final void add(String sql) { added = true; builder.append("[").append(sql).append("], "); } @Override public final void log(long time) { if (added) { builder.delete(builder.length() - 2, builder.length()); } builder.append("]"); FormattedLog.this.log(String.format("%s took %d millis", builder.toString(), time)); } }; } else { return NoOpLog.batch; } } @Override public void logBeginTransaction(Handle h) { if (isEnabled()) { log(String.format("begin transaction on [%s]", h)); } } @Override public void logCommitTransaction(long time, Handle h) { if (isEnabled()) { log(String.format("commit transaction on [%s] took %d millis", h, time)); } } @Override public void logRollbackTransaction(long time, Handle h) { if (isEnabled()) { log(String.format("rollback transaction on [%s] took %d millis", h, time)); } } @Override public void logObtainHandle(long time, Handle h) { if (this.isEnabled()) { log(String.format("Handle [%s] obtained in %d millis", h, time)); } } @Override public void logReleaseHandle(Handle h) { if (this.isEnabled()) { log(String.format("Handle [%s] released", h)); } } @Override public void logCheckpointTransaction(Handle h, String name) { if (this.isEnabled()) { log(String.format("checkpoint [%s] created on [%s]", name, h)); } } @Override public void logReleaseCheckpointTransaction(Handle h, String name) { if (this.isEnabled()) { log(String.format("checkpoint [%s] on [%s] released", name, h)); } } @Override public void logRollbackToCheckpoint(long time, Handle h, String checkpointName) { if (this.isEnabled()) { log(String.format("checkpoint [%s] on [%s] rolled back in %d millis", checkpointName, h, time)); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/logging/PrintStreamLog.java
jdbi/src/main/java/org/skife/jdbi/v2/logging/PrintStreamLog.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.logging; import java.io.PrintStream; /** * */ public class PrintStreamLog extends FormattedLog { private final PrintStream out; /** * Log to standard out. */ public PrintStreamLog() { this(System.out); } /** * Specify the print stream to log to * @param out The print stream to log to */ public PrintStreamLog(PrintStream out) { this.out = out; } @Override protected final boolean isEnabled() { return true; } @Override protected void log(String msg) { out.println(msg); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/logging/SLF4JLog.java
jdbi/src/main/java/org/skife/jdbi/v2/logging/SLF4JLog.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.logging; import org.skife.jdbi.v2.DBI; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SLF4JLog extends FormattedLog { public static enum Level { TRACE { @Override boolean isEnabled(Logger logger) { return logger.isTraceEnabled(); } @Override void log(Logger logger, String msg) { logger.trace(msg); } }, DEBUG { @Override boolean isEnabled(Logger logger) { return logger.isDebugEnabled(); } @Override void log(Logger logger, String msg) { logger.debug(msg); } }, INFO { @Override boolean isEnabled(Logger logger) { return logger.isInfoEnabled(); } @Override void log(Logger logger, String msg) { logger.info(msg); } }, WARN { @Override boolean isEnabled(Logger logger) { return logger.isWarnEnabled(); } @Override void log(Logger logger, String msg) { logger.warn(msg); } }, ERROR { @Override boolean isEnabled(Logger logger) { return logger.isErrorEnabled(); } @Override void log(Logger logger, String msg) { logger.error(msg); } }; abstract boolean isEnabled(Logger logger); abstract void log(Logger logger, String msg); } private final Logger logger; private final Level level; public SLF4JLog() { this(LoggerFactory.getLogger(DBI.class.getPackage().getName())); } public SLF4JLog(Logger logger) { this(logger, Level.TRACE); } public SLF4JLog(Logger logger, Level level) { this.logger = logger; this.level = level; } @Override protected boolean isEnabled() { return level.isEnabled(logger); } @Override protected void log(String msg) { level.log(logger, msg); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/RollbackCheckpointHandler.java
jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/RollbackCheckpointHandler.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.sqlobject; import java.util.concurrent.Callable; class RollbackCheckpointHandler implements Handler { @Override public Object invoke(HandleDing h, Object target, Object[] args, Callable<?> methodProxy) { h.getHandle().rollback(String.valueOf(args[0])); return null; } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/SqlCall.java
jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/SqlCall.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.sqlobject; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Support for stored proc invocation. Return value must be either null or OutParameters at present. */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface SqlCall { String value() default SqlQuery.DEFAULT_VALUE; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/CreateSqlObjectHandler.java
jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/CreateSqlObjectHandler.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.sqlobject; import java.util.concurrent.Callable; class CreateSqlObjectHandler implements Handler { private final Class<?> sqlObjectTypeToCreate; public CreateSqlObjectHandler(Class<?> sqlObjectTypeToCreate) { this.sqlObjectTypeToCreate = sqlObjectTypeToCreate; } @Override public Object invoke(HandleDing h, Object target, Object[] args, Callable<?> methodProxy) { return SqlObject.buildSqlObject(sqlObjectTypeToCreate, h); } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/Transaction.java
jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/Transaction.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.sqlobject; import org.skife.jdbi.v2.TransactionIsolationLevel; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface Transaction { TransactionIsolationLevel value() default TransactionIsolationLevel.INVALID_LEVEL; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/WithHandleHandler.java
jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/WithHandleHandler.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.sqlobject; import java.util.concurrent.Callable; import org.skife.jdbi.v2.Handle; import org.skife.jdbi.v2.exceptions.CallbackFailedException; import org.skife.jdbi.v2.tweak.HandleCallback; class WithHandleHandler implements Handler { @Override public Object invoke(HandleDing h, Object target, Object[] args, Callable<?> methodProxy) { final Handle handle = h.getHandle(); final HandleCallback<?> callback = (HandleCallback<?>) args[0]; try { return callback.withHandle(handle); } catch (Exception e) { throw new CallbackFailedException(e); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/BindFactory.java
jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/BindFactory.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.sqlobject; import java.lang.annotation.Annotation; class BindFactory implements BinderFactory { @Override public Binder build(Annotation annotation) { Bind bind = (Bind) annotation; try { return bind.binder().newInstance(); } catch (Exception e) { throw new IllegalStateException("unable to instantiate specified binder", e); } } }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false
killbill/killbill-commons
https://github.com/killbill/killbill-commons/blob/9239f88b55d9255c172143bab180b7aa042fcd36/jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/GetGeneratedKeys.java
jdbi/src/main/java/org/skife/jdbi/v2/sqlobject/GetGeneratedKeys.java
/* * Copyright 2004-2014 Brian McCallister * Copyright 2010-2014 Ning, Inc. * Copyright 2014-2020 Groupon, Inc * Copyright 2020-2020 Equinix, Inc * Copyright 2014-2020 The Billing Project, LLC * * The Billing Project licenses this file to you under the Apache License, version 2.0 * (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package org.skife.jdbi.v2.sqlobject; import org.skife.jdbi.v2.tweak.ResultSetMapper; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface GetGeneratedKeys { String columnName() default ""; Class<? extends ResultSetMapper> value() default FigureItOutResultSetMapper.class; }
java
Apache-2.0
9239f88b55d9255c172143bab180b7aa042fcd36
2026-01-05T02:38:41.530814Z
false