Skip to content

Commit

Permalink
Reorganized code to new packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
komu committed Apr 30, 2015
1 parent 878d12e commit c7b40ec
Show file tree
Hide file tree
Showing 103 changed files with 275 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/scopes/Dialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/scopes/Support_and_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## x.x.x (yyyy-mm-dd)

### Breaking changes

- Renamed base package `fi.evident.dalesbred` to `org.dalesbred`.
- Other package renames:
- `fi.evident.dalesbred.dialects` -> `org.dalesbred.dialect`
- `fi.evident.dalesbred.lob` -> `org.dalesbred.datatype`
- `fi.evident.dalesbred.results` -> `org.dalesbred.result`
- `fi.evident.dalesbred.support` -> `org.dalesbred.integration`
- `fi.evident.dalesbred.tx` -> `org.dalesbred.transaction`
- Moved some classes to new packages:
- All annotations to `org.dalesbred.annotation`
- All transaction-related classes to `org.dalesbred.transaction`.
- `fi.evident.dalesbred.SqlQuery` -> `org.dalesbred.query.SqlQuery`
- `fi.evident.dalesbred.SqlArray` -> `org.dalesbred.datatype.SqlArray`

- Moved classes that are technically `public`, but are not part of Dalesbred's supported
API to `org.dalesbred.internal`.

## 0.8.0 (2015-04-08)

- Support instantiating arrays and collections of instantiable types from database arrays.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import org.dalesbred.Database;
import org.dalesbred.connection.DriverManagerDataSourceProvider;
import org.dalesbred.dialects.Dialect;
import org.dalesbred.dialect.Dialect;
import org.dalesbred.transaction.TransactionCallback;
import org.jetbrains.annotations.NotNull;
import org.junit.internal.AssumptionViolatedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
package org.dalesbred.junit;

import org.dalesbred.Database;
import org.dalesbred.dialects.DefaultDialect;
import org.dalesbred.dialect.DefaultDialect;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;

Expand Down
34 changes: 24 additions & 10 deletions dalesbred/src/main/java/org/dalesbred/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@

package org.dalesbred;

import org.dalesbred.annotation.SQL;
import org.dalesbred.connection.ConnectionProvider;
import org.dalesbred.connection.DataSourceConnectionProvider;
import org.dalesbred.connection.DriverManagerDataSourceProvider;
import org.dalesbred.dialects.Dialect;
import org.dalesbred.datatype.ConfidentialValue;
import org.dalesbred.dialect.Dialect;
import org.dalesbred.instantiation.DefaultInstantiatorRegistry;
import org.dalesbred.instantiation.InstantiatorRegistry;
import org.dalesbred.instantiation.TypeConversionRegistry;
import org.dalesbred.results.*;
import org.dalesbred.support.proxy.TransactionalProxyFactory;
import org.dalesbred.integration.proxy.TransactionalProxyFactory;
import org.dalesbred.query.SqlQuery;
import org.dalesbred.result.*;
import org.dalesbred.transaction.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -282,8 +285,8 @@ public <T> T executeQuery(@NotNull ResultSetProcessor<T> processor, @NotNull Sql
return withCurrentTransaction(query, tx -> {
logQuery(query);

try (PreparedStatement ps = tx.getConnection().prepareStatement(query.sql)) {
bindArguments(ps, query.args);
try (PreparedStatement ps = tx.getConnection().prepareStatement(query.getSql())) {
bindArguments(ps, query.getArguments());

long startTime = currentTimeMillis();
try (ResultSet resultSet = ps.executeQuery()) {
Expand Down Expand Up @@ -495,8 +498,8 @@ public int update(@NotNull SqlQuery query) {
return withCurrentTransaction(query, tx -> {
logQuery(query);

try (PreparedStatement ps = tx.getConnection().prepareStatement(query.sql)) {
bindArguments(ps, query.args);
try (PreparedStatement ps = tx.getConnection().prepareStatement(query.getSql())) {
bindArguments(ps, query.getArguments());
long startTime = currentTimeMillis();
int count = ps.executeUpdate();
logQueryExecution(query, currentTimeMillis() - startTime);
Expand Down Expand Up @@ -525,8 +528,8 @@ public <T> T updateAndProcessGeneratedKeys(@NotNull ResultSetProcessor<T> genera
return withCurrentTransaction(query, tx -> {
logQuery(query);

try (PreparedStatement ps = prepareStatement(tx.getConnection(), query.sql, columnNames)) {
bindArguments(ps, query.args);
try (PreparedStatement ps = prepareStatement(tx.getConnection(), query.getSql(), columnNames)) {
bindArguments(ps, query.getArguments());
long startTime = currentTimeMillis();
ps.executeUpdate();
logQueryExecution(query, currentTimeMillis() - startTime);
Expand Down Expand Up @@ -590,7 +593,18 @@ private void bindArguments(@NotNull PreparedStatement ps, @NotNull Iterable<?> a
int i = 1;

for (Object arg : args)
dialect.bindArgument(ps, i++, instantiatorRegistry.valueToDatabase(SqlQuery.unwrapConfidential(arg)));
dialect.bindArgument(ps, i++, instantiatorRegistry.valueToDatabase(unwrapConfidential(arg)));
}

/**
* If the argument is a confidential value, returns it unwrapped, otherwise returns the value as it is.
*/
@Nullable
private static Object unwrapConfidential(@Nullable Object arg) {
if (arg instanceof ConfidentialValue)
return ((ConfidentialValue) arg).getValue();
else
return arg;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.dalesbred;

import org.dalesbred.query.SqlQuery;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down
1 change: 1 addition & 0 deletions dalesbred/src/main/java/org/dalesbred/DebugContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.dalesbred;

import org.dalesbred.query.SqlQuery;
import org.jetbrains.annotations.Nullable;

final class DebugContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package org.dalesbred;

import org.dalesbred.query.SqlQuery;

/**
* Exception thrown when expecting a unique result from a call, but invalid number
* of results was returned by the database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred;
package org.dalesbred.annotation;

import java.lang.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred;
package org.dalesbred.annotation;

/**
* Annotation used for marking members that are only accessed reflectively, e.g. constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred;
package org.dalesbred.annotation;

import org.intellij.lang.annotations.Language;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2015 Evident Solutions Oy
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.dalesbred.datatype;

import org.jetbrains.annotations.Nullable;

/**
* Confidential wrapper for objects. You can bind ConfidentialValues as query
* parameters which will execute th
* will not reveal their representation in toString, but
*/
public final class ConfidentialValue {

@Nullable
private final Object value;

public ConfidentialValue(@Nullable Object value) {
this.value = value;
}

/**
* Wraps the value in a confidential wrapper which prevents it from ever being shown
* in any logs or stack-traces, but it can still be used normally as a query-parameter.
*/
public static Object confidential(Object value) {
return new ConfidentialValue(value);
}

@Nullable
public Object getValue() {
return value;
}

@Override
public String toString() {
return "****";
}

@Override
public boolean equals(Object obj) {
if (obj == this) return true;

if (obj instanceof ConfidentialValue) {
ConfidentialValue rhs = (ConfidentialValue) obj;
return (value == null) ? rhs.value == null : value.equals(rhs.value);
}

return false;
}

@Override
public int hashCode() {
return (value != null) ? value.hashCode() : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred.lob;
package org.dalesbred.datatype;

import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred.lob;
package org.dalesbred.datatype;

import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred;
package org.dalesbred.datatype;

import org.dalesbred.internal.utils.Require;
import org.jetbrains.annotations.NotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
*/

/**
* Support for handling large objects.
* Special data types.
*/
package org.dalesbred.lob;
package org.dalesbred.datatype;
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
* THE SOFTWARE.
*/

package org.dalesbred.dialects;
package org.dalesbred.dialect;

import org.dalesbred.SqlArray;
import org.dalesbred.lob.InputStreamWithSize;
import org.dalesbred.lob.ReaderWithSize;
import org.dalesbred.datatype.InputStreamWithSize;
import org.dalesbred.datatype.ReaderWithSize;
import org.dalesbred.datatype.SqlArray;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.Document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred.dialects;
package org.dalesbred.dialect;

/**
* Default dialect used for databases that don't have special support.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred.dialects;
package org.dalesbred.dialect;

import org.dalesbred.DatabaseException;
import org.dalesbred.DatabaseSQLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred.dialects;
package org.dalesbred.dialect;

/**
* Support for HSQLDB.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred.dialects;
package org.dalesbred.dialect;

/**
* Support for MySQL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred.dialects;
package org.dalesbred.dialect;

/**
* Support for Oracle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred.dialects;
package org.dalesbred.dialect;

import org.dalesbred.instantiation.TypeConversion;
import org.dalesbred.instantiation.TypeConversionRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* THE SOFTWARE.
*/

package org.dalesbred.dialects;
package org.dalesbred.dialect;

/**
* Support for Microsoft SQL Server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
/**
* Support for different databases.
*/
package org.dalesbred.dialects;
package org.dalesbred.dialect;
Loading

0 comments on commit c7b40ec

Please sign in to comment.