Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Re-enables foreign key checks. Fixes #8 #9

Merged
merged 1 commit into from

3 participants

@amir20
Owner

No description provided.

@amir20
Owner

@mdgreenfield Try using version 1.5-SNAPSHOT and see if that works.

@mdgreenfield
Collaborator

looks good now.

@mdgreenfield mdgreenfield merged commit 6e813f2 into from
@s-machina
Collaborator

Should this be done all the time? Or should it be configurable. Better yet, should it check the current db settings before doing it. Some dbs run without foreign key checks. Not ours I suppose, but many do.

Owner

My opinion is that the connection should undo whatever it did before with the connection. I initially set the fk check to false so it only makes to restore it to true.

Collaborator

I agree. What I'm saying is what if they db had foreign_key_check = 0 prior to you setting it to 0 yourself.

@amir20
Owner

I see, that makes sense. I didn't think someone would disable fk check before. But I could see why it would break if they did. I'll add that to 1.6. Or accept pull requests. :P

@mdgreenfield 1.5 is ready in maven.

@s-machina
Collaborator

Touché.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 17, 2012
  1. Re-enables foreign key checks. Fixes #8

    Amir Raminfar authored
This page is out of date. Refresh to see the latest.
View
21 src/main/java/com/opower/persistence/jpile/loader/HierarchicalInfileObjectLoader.java
@@ -12,20 +12,23 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SecondaryTable;
+
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.opower.persistence.jpile.infile.InfileDataBuffer;
import com.opower.persistence.jpile.reflection.CachedProxy;
import com.opower.persistence.jpile.reflection.PersistenceAnnotationInspector;
import com.opower.persistence.jpile.util.JdbcUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.ImmutableList.copyOf;
@@ -275,7 +278,9 @@ public void flush() {
}
/**
- * Closes all object loaders
+ * Closes all object loaders.
+ * <p/>
+ * Re-enables foreign key checks for the connection.
*/
@Override
public void close() {
@@ -283,9 +288,17 @@ public void close() {
logger.debug("Closing all object loaders.");
primaryObjectLoaders.clear();
secondaryTableObjectLoaders.clear();
+ JdbcUtil.execute(this.connection, new JdbcUtil.StatementCallback<Boolean>() {
+ @Override
+ public Boolean doInStatement(Statement statement) throws SQLException {
+ return statement.execute("SET FOREIGN_KEY_CHECKS = 1");
+ }
+ });
}
-
+ /**
+ * Disables foreign key checks for this connection by executing {@code SET FOREIGN_KEY_CHECKS = 0}
+ */
public void setConnection(Connection connection) {
this.connection = connection;
JdbcUtil.execute(this.connection, new JdbcUtil.StatementCallback<Boolean>() {
Something went wrong with that request. Please try again.