mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Organise imports
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.avaje.ebeaninternal.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.ExpressionList;
|
||||
import com.avaje.ebean.OrderBy;
|
||||
import com.avaje.ebean.Query;
|
||||
@@ -18,9 +21,6 @@ import com.avaje.ebeaninternal.server.querydefn.NaturalKeyBindParam;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetail;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Object Relational query - Internal extension to Query object.
|
||||
*/
|
||||
|
||||
+97
-97
@@ -1,97 +1,97 @@
|
||||
package com.avaje.ebeaninternal.server.autofetch;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.resource.ResourceManager;
|
||||
|
||||
public class AutoFetchManagerFactory {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(AutoFetchManagerFactory.class.getName());
|
||||
|
||||
|
||||
public static AutoFetchManager create(SpiEbeanServer server, ServerConfig serverConfig, ResourceManager resourceManager) {
|
||||
|
||||
AutoFetchManagerFactory me = new AutoFetchManagerFactory();
|
||||
return me.createAutoFetchManager(server, serverConfig, resourceManager);
|
||||
}
|
||||
|
||||
private AutoFetchManager createAutoFetchManager(SpiEbeanServer server, ServerConfig serverConfig, ResourceManager resourceManager){
|
||||
|
||||
AutoFetchManager manager = createAutoFetchManager(server.getName(), resourceManager);
|
||||
manager.setOwner(server, serverConfig);
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
private AutoFetchManager createAutoFetchManager(String serverName, ResourceManager resourceManager) {
|
||||
|
||||
File autoFetchFile = getAutoFetchFile(serverName, resourceManager);
|
||||
|
||||
AutoFetchManager autoFetchManager = null;
|
||||
|
||||
boolean readFile = GlobalProperties.getBoolean("autofetch.readfromfile", true);
|
||||
if (readFile) {
|
||||
autoFetchManager = deserializeAutoFetch(autoFetchFile);
|
||||
}
|
||||
|
||||
if (autoFetchManager == null) {
|
||||
// not deserialized from file so create as empty
|
||||
// It will be populated automatically by querying the
|
||||
// database meta data
|
||||
autoFetchManager = new DefaultAutoFetchManager(autoFetchFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
return autoFetchManager;
|
||||
}
|
||||
|
||||
private AutoFetchManager deserializeAutoFetch(File autoFetchFile) {
|
||||
try {
|
||||
|
||||
if (!autoFetchFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
FileInputStream fi = new FileInputStream(autoFetchFile);
|
||||
ObjectInputStream ois = new ObjectInputStream(fi);
|
||||
AutoFetchManager profListener = (AutoFetchManager) ois.readObject();
|
||||
|
||||
logger.info("AutoFetch deserialized from file ["+autoFetchFile.getAbsolutePath()+"]");
|
||||
|
||||
return profListener;
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, "Error loading autofetch file "+autoFetchFile.getAbsolutePath(), ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file name of the autoFetch meta data.
|
||||
*/
|
||||
private File getAutoFetchFile(String serverName, ResourceManager resourceManager) {
|
||||
|
||||
String fileName = ".ebean."+serverName+".autofetch";
|
||||
|
||||
File dir = resourceManager.getAutofetchDirectory();
|
||||
|
||||
if (!dir.exists()) {
|
||||
// automatically create the directory if it does not exist.
|
||||
// this is probably a fairly reasonable thing to do
|
||||
if (!dir.mkdirs()) {
|
||||
String m = "Unable to create directory [" + dir + "] for autofetch file ["+ fileName + "]";
|
||||
throw new PersistenceException(m);
|
||||
}
|
||||
}
|
||||
|
||||
return new File(dir, fileName);
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.autofetch;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.server.resource.ResourceManager;
|
||||
|
||||
public class AutoFetchManagerFactory {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(AutoFetchManagerFactory.class.getName());
|
||||
|
||||
|
||||
public static AutoFetchManager create(SpiEbeanServer server, ServerConfig serverConfig, ResourceManager resourceManager) {
|
||||
|
||||
AutoFetchManagerFactory me = new AutoFetchManagerFactory();
|
||||
return me.createAutoFetchManager(server, serverConfig, resourceManager);
|
||||
}
|
||||
|
||||
private AutoFetchManager createAutoFetchManager(SpiEbeanServer server, ServerConfig serverConfig, ResourceManager resourceManager){
|
||||
|
||||
AutoFetchManager manager = createAutoFetchManager(server.getName(), resourceManager);
|
||||
manager.setOwner(server, serverConfig);
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
private AutoFetchManager createAutoFetchManager(String serverName, ResourceManager resourceManager) {
|
||||
|
||||
File autoFetchFile = getAutoFetchFile(serverName, resourceManager);
|
||||
|
||||
AutoFetchManager autoFetchManager = null;
|
||||
|
||||
boolean readFile = GlobalProperties.getBoolean("autofetch.readfromfile", true);
|
||||
if (readFile) {
|
||||
autoFetchManager = deserializeAutoFetch(autoFetchFile);
|
||||
}
|
||||
|
||||
if (autoFetchManager == null) {
|
||||
// not deserialized from file so create as empty
|
||||
// It will be populated automatically by querying the
|
||||
// database meta data
|
||||
autoFetchManager = new DefaultAutoFetchManager(autoFetchFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
return autoFetchManager;
|
||||
}
|
||||
|
||||
private AutoFetchManager deserializeAutoFetch(File autoFetchFile) {
|
||||
try {
|
||||
|
||||
if (!autoFetchFile.exists()) {
|
||||
return null;
|
||||
}
|
||||
FileInputStream fi = new FileInputStream(autoFetchFile);
|
||||
ObjectInputStream ois = new ObjectInputStream(fi);
|
||||
AutoFetchManager profListener = (AutoFetchManager) ois.readObject();
|
||||
|
||||
logger.info("AutoFetch deserialized from file ["+autoFetchFile.getAbsolutePath()+"]");
|
||||
|
||||
return profListener;
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, "Error loading autofetch file "+autoFetchFile.getAbsolutePath(), ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file name of the autoFetch meta data.
|
||||
*/
|
||||
private File getAutoFetchFile(String serverName, ResourceManager resourceManager) {
|
||||
|
||||
String fileName = ".ebean."+serverName+".autofetch";
|
||||
|
||||
File dir = resourceManager.getAutofetchDirectory();
|
||||
|
||||
if (!dir.exists()) {
|
||||
// automatically create the directory if it does not exist.
|
||||
// this is probably a fairly reasonable thing to do
|
||||
if (!dir.mkdirs()) {
|
||||
String m = "Unable to create directory [" + dir + "] for autofetch file ["+ fileName + "]";
|
||||
throw new PersistenceException(m);
|
||||
}
|
||||
}
|
||||
|
||||
return new File(dir, fileName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+111
-112
@@ -1,112 +1,111 @@
|
||||
package com.avaje.ebeaninternal.server.autofetch;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.avaje.ebean.config.AutofetchConfig;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebeaninternal.server.lib.BackgroundThread;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetail;
|
||||
import com.avaje.ebeaninternal.server.transaction.log.SimpleLogger;
|
||||
|
||||
/**
|
||||
* Handles the logging aspects for the DefaultAutoFetchListener.
|
||||
* <p>
|
||||
* Note that java util logging loggers generally should not be serialised and
|
||||
* that is one of the main reasons for pulling out the logging to this class.
|
||||
* </p>
|
||||
*/
|
||||
public class DefaultAutoFetchManagerLogging {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DefaultAutoFetchManagerLogging.class.getName());
|
||||
|
||||
private final SimpleLogger fileLogger;
|
||||
|
||||
private final DefaultAutoFetchManager manager;
|
||||
|
||||
private final boolean useFileLogger;
|
||||
|
||||
private final boolean traceUsageCollection;
|
||||
|
||||
public DefaultAutoFetchManagerLogging(ServerConfig serverConfig, DefaultAutoFetchManager profileListener) {
|
||||
|
||||
this.manager = profileListener;
|
||||
|
||||
AutofetchConfig autofetchConfig = serverConfig.getAutofetchConfig();
|
||||
|
||||
traceUsageCollection = GlobalProperties.getBoolean("ebean.autofetch.traceUsageCollection", false);
|
||||
useFileLogger = autofetchConfig.isUseFileLogging();
|
||||
|
||||
if (!useFileLogger) {
|
||||
fileLogger = null;
|
||||
|
||||
} else {
|
||||
// a separate log file just like the transaction logging
|
||||
// for putting the profiling log messages. The benefit is that
|
||||
// this doesn't pollute the main log with heaps of messages.
|
||||
String baseDir = serverConfig.getLoggingDirectoryWithEval();
|
||||
fileLogger = new SimpleLogger(baseDir, "autofetch", true, "csv");
|
||||
}
|
||||
|
||||
int updateFreqInSecs = autofetchConfig.getProfileUpdateFrequency();
|
||||
|
||||
BackgroundThread.add(updateFreqInSecs, new UpdateProfile());
|
||||
}
|
||||
|
||||
private final class UpdateProfile implements Runnable {
|
||||
public void run() {
|
||||
manager.updateTunedQueryInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public void logError(Level level, String msg, Throwable e) {
|
||||
if (useFileLogger) {
|
||||
String errMsg = e == null ? "" : e.getMessage();
|
||||
fileLogger.log("\"Error\",\"" + msg+" "+errMsg+"\",,,,");
|
||||
}
|
||||
logger.log(level, msg, e);
|
||||
}
|
||||
|
||||
public void logToJavaLogger(String msg) {
|
||||
logger.info(msg);
|
||||
}
|
||||
|
||||
public void logSummary(String summaryInfo) {
|
||||
|
||||
String msg = "\"Summary\",\""+summaryInfo+"\",,,,";
|
||||
|
||||
if (useFileLogger) {
|
||||
fileLogger.log(msg);
|
||||
}
|
||||
logger.fine(msg);
|
||||
}
|
||||
|
||||
public void logChanged(TunedQueryInfo tunedFetch, OrmQueryDetail newQueryDetail) {
|
||||
|
||||
String msg = tunedFetch.getLogOutput(newQueryDetail);
|
||||
|
||||
if (useFileLogger) {
|
||||
fileLogger.log(msg);
|
||||
} else {
|
||||
logger.fine(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void logNew(TunedQueryInfo tunedFetch) {
|
||||
|
||||
String msg = tunedFetch.getLogOutput(null);
|
||||
|
||||
if (useFileLogger) {
|
||||
fileLogger.log(msg);
|
||||
} else {
|
||||
logger.fine(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTraceUsageCollection() {
|
||||
return traceUsageCollection;
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.autofetch;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.avaje.ebean.config.AutofetchConfig;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebeaninternal.server.lib.BackgroundThread;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetail;
|
||||
import com.avaje.ebeaninternal.server.transaction.log.SimpleLogger;
|
||||
|
||||
/**
|
||||
* Handles the logging aspects for the DefaultAutoFetchListener.
|
||||
* <p>
|
||||
* Note that java util logging loggers generally should not be serialised and
|
||||
* that is one of the main reasons for pulling out the logging to this class.
|
||||
* </p>
|
||||
*/
|
||||
public class DefaultAutoFetchManagerLogging {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DefaultAutoFetchManagerLogging.class.getName());
|
||||
|
||||
private final SimpleLogger fileLogger;
|
||||
|
||||
private final DefaultAutoFetchManager manager;
|
||||
|
||||
private final boolean useFileLogger;
|
||||
|
||||
private final boolean traceUsageCollection;
|
||||
|
||||
public DefaultAutoFetchManagerLogging(ServerConfig serverConfig, DefaultAutoFetchManager profileListener) {
|
||||
|
||||
this.manager = profileListener;
|
||||
|
||||
AutofetchConfig autofetchConfig = serverConfig.getAutofetchConfig();
|
||||
|
||||
traceUsageCollection = GlobalProperties.getBoolean("ebean.autofetch.traceUsageCollection", false);
|
||||
useFileLogger = autofetchConfig.isUseFileLogging();
|
||||
|
||||
if (!useFileLogger) {
|
||||
fileLogger = null;
|
||||
|
||||
} else {
|
||||
// a separate log file just like the transaction logging
|
||||
// for putting the profiling log messages. The benefit is that
|
||||
// this doesn't pollute the main log with heaps of messages.
|
||||
String baseDir = serverConfig.getLoggingDirectoryWithEval();
|
||||
fileLogger = new SimpleLogger(baseDir, "autofetch", true, "csv");
|
||||
}
|
||||
|
||||
int updateFreqInSecs = autofetchConfig.getProfileUpdateFrequency();
|
||||
|
||||
BackgroundThread.add(updateFreqInSecs, new UpdateProfile());
|
||||
}
|
||||
|
||||
private final class UpdateProfile implements Runnable {
|
||||
public void run() {
|
||||
manager.updateTunedQueryInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public void logError(Level level, String msg, Throwable e) {
|
||||
if (useFileLogger) {
|
||||
String errMsg = e == null ? "" : e.getMessage();
|
||||
fileLogger.log("\"Error\",\"" + msg+" "+errMsg+"\",,,,");
|
||||
}
|
||||
logger.log(level, msg, e);
|
||||
}
|
||||
|
||||
public void logToJavaLogger(String msg) {
|
||||
logger.info(msg);
|
||||
}
|
||||
|
||||
public void logSummary(String summaryInfo) {
|
||||
|
||||
String msg = "\"Summary\",\""+summaryInfo+"\",,,,";
|
||||
|
||||
if (useFileLogger) {
|
||||
fileLogger.log(msg);
|
||||
}
|
||||
logger.fine(msg);
|
||||
}
|
||||
|
||||
public void logChanged(TunedQueryInfo tunedFetch, OrmQueryDetail newQueryDetail) {
|
||||
|
||||
String msg = tunedFetch.getLogOutput(newQueryDetail);
|
||||
|
||||
if (useFileLogger) {
|
||||
fileLogger.log(msg);
|
||||
} else {
|
||||
logger.fine(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void logNew(TunedQueryInfo tunedFetch) {
|
||||
|
||||
String msg = tunedFetch.getLogOutput(null);
|
||||
|
||||
if (useFileLogger) {
|
||||
fileLogger.log(msg);
|
||||
} else {
|
||||
logger.fine(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTraceUsageCollection() {
|
||||
return traceUsageCollection;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import java.sql.SQLException;
|
||||
import com.avaje.ebean.CallableSql;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebeaninternal.api.BindParams;
|
||||
import com.avaje.ebeaninternal.api.BindParams.Param;
|
||||
import com.avaje.ebeaninternal.api.SpiCallableSql;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable;
|
||||
import com.avaje.ebeaninternal.api.BindParams.Param;
|
||||
|
||||
|
||||
public class DefaultCallableSql implements Serializable, SpiCallableSql {
|
||||
|
||||
@@ -19,6 +19,21 @@
|
||||
*/
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MBeanServerFactory;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebean.cache.ServerCacheFactory;
|
||||
import com.avaje.ebean.cache.ServerCacheManager;
|
||||
@@ -43,20 +58,6 @@ import com.avaje.ebeaninternal.server.lib.sql.DataSourcePool;
|
||||
import com.avaje.ebeaninternal.server.lib.thread.ThreadPool;
|
||||
import com.avaje.ebeaninternal.server.lib.thread.ThreadPoolManager;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MBeanServerFactory;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Default Server side implementation of ServerFactory.
|
||||
*/
|
||||
|
||||
@@ -6,11 +6,11 @@ import java.util.List;
|
||||
|
||||
import com.avaje.ebean.CallableSql;
|
||||
import com.avaje.ebeaninternal.api.BindParams;
|
||||
import com.avaje.ebeaninternal.api.BindParams.Param;
|
||||
import com.avaje.ebeaninternal.api.SpiCallableSql;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.api.TransactionEventTable;
|
||||
import com.avaje.ebeaninternal.api.BindParams.Param;
|
||||
import com.avaje.ebeaninternal.server.persist.PersistExecute;
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,9 +9,9 @@ import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.config.NamingConvention;
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebean.config.dbplatform.DbDdlSyntax;
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebean.config.dbplatform.DbTypeMap;
|
||||
import com.avaje.ebean.config.dbplatform.DbDdlSyntax;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.lib.util.StringHelper;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyCompound;
|
||||
import com.avaje.ebeaninternal.server.el.ElPropertyChainBuilder;
|
||||
@@ -11,10 +15,6 @@ import com.avaje.ebeaninternal.server.type.CtCompoundProperty;
|
||||
import com.avaje.ebeaninternal.server.type.CtCompoundPropertyElAdapter;
|
||||
import com.avaje.ebeaninternal.server.type.CtCompoundType;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Property mapped to an Immutable Compound Value Object.
|
||||
* <p>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.meta.DeployTableJoin;
|
||||
@@ -7,9 +10,6 @@ import com.avaje.ebeaninternal.server.deploy.meta.DeployTableJoinColumn;
|
||||
import com.avaje.ebeaninternal.server.query.SplitName;
|
||||
import com.avaje.ebeaninternal.server.query.SqlBeanLoad;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* Represents a join to another table.
|
||||
*/
|
||||
|
||||
@@ -1,455 +1,456 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.id;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
|
||||
import com.avaje.ebeaninternal.server.query.SplitName;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Bind an Id that is an Embedded bean.
|
||||
*/
|
||||
public final class IdBinderEmbedded implements IdBinder {
|
||||
|
||||
private final BeanPropertyAssocOne<?> embIdProperty;
|
||||
|
||||
private final boolean idInExpandedForm;
|
||||
|
||||
private BeanProperty[] props;
|
||||
|
||||
private BeanDescriptor<?> idDesc;
|
||||
|
||||
private String idInValueSql;
|
||||
|
||||
|
||||
public IdBinderEmbedded(boolean idInExpandedForm, BeanPropertyAssocOne<?> embIdProperty) {
|
||||
this.idInExpandedForm = idInExpandedForm;
|
||||
this.embIdProperty = embIdProperty;
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
this.idDesc = embIdProperty.getTargetDescriptor();
|
||||
this.props = embIdProperty.getProperties();
|
||||
this.idInValueSql = idInExpandedForm ? idInExpanded() : idInCompressed();
|
||||
}
|
||||
|
||||
private String idInExpanded() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
sb.append(embIdProperty.getName());
|
||||
sb.append(".");
|
||||
sb.append(props[i].getName());
|
||||
sb.append("=?");
|
||||
}
|
||||
sb.append(")");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String idInCompressed() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("?");
|
||||
}
|
||||
sb.append(")");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getOrderBy(String pathPrefix, boolean ascending){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
if (pathPrefix != null){
|
||||
sb.append(pathPrefix).append(".");
|
||||
}
|
||||
|
||||
sb.append(embIdProperty.getName()).append(".");
|
||||
sb.append(props[i].getName());
|
||||
if (!ascending){
|
||||
sb.append(" desc");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object v = props[i].getValue(id);
|
||||
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
|
||||
name.add(rdn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
|
||||
Object id = embIdProperty.getValue(bean);
|
||||
createLdapNameById(name, id);
|
||||
}
|
||||
|
||||
public BeanDescriptor<?> getIdBeanDescriptor() {
|
||||
return idDesc;
|
||||
}
|
||||
|
||||
public int getPropertyCount() {
|
||||
return props.length;
|
||||
}
|
||||
|
||||
public String getIdProperty() {
|
||||
return embIdProperty.getName();
|
||||
}
|
||||
|
||||
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
|
||||
|
||||
prefix = SplitName.add(prefix, embIdProperty.getName());
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].buildSelectExpressionChain(prefix, selectChain);
|
||||
}
|
||||
}
|
||||
|
||||
public BeanProperty findBeanProperty(String dbColumnName) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (dbColumnName.equalsIgnoreCase(props[i].getDbColumn())) {
|
||||
return props[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isComplexId() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getDefaultOrderBy() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
|
||||
sb.append(embIdProperty.getName());
|
||||
sb.append(".");
|
||||
sb.append(props[i].getName());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public BeanProperty[] getProperties() {
|
||||
return props;
|
||||
}
|
||||
|
||||
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
request.addBindValue(props[i].getValue(value));
|
||||
}
|
||||
}
|
||||
|
||||
public String getIdInValueExprDelete(int size) {
|
||||
if (!idInExpandedForm){
|
||||
return getIdInValueExpr(size);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
|
||||
for (int j = 0; j < size; j++) {
|
||||
if (j > 0){
|
||||
sb.append(" or ");
|
||||
}
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
sb.append(props[i].getDbColumn());
|
||||
sb.append("=?");
|
||||
}
|
||||
sb.append(")");
|
||||
}
|
||||
sb.append(") ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getIdInValueExpr(int size) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (!idInExpandedForm){
|
||||
sb.append(" in");
|
||||
}
|
||||
sb.append(" (");
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (i > 0){
|
||||
if (idInExpandedForm) {
|
||||
sb.append(" or ");
|
||||
} else {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append(idInValueSql);
|
||||
}
|
||||
sb.append(") ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getIdInValueExpr() {
|
||||
return idInValueSql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the lucene string term value into embedded id.
|
||||
*/
|
||||
public Object readTerm(String idTermValue) {
|
||||
|
||||
String[] split = idTermValue.split("|");
|
||||
if (split.length != props.length){
|
||||
String msg = "Failed to split ["+idTermValue+"] using | for id.";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
Object embId = idDesc.createVanillaBean();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object v = props[i].getScalarType().parse(split[i]);
|
||||
props[i].setValue(embId, v);
|
||||
}
|
||||
return embId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the embedded id as a Lucene string term value.
|
||||
*/
|
||||
public String writeTerm(Object idValue) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object v = props[i].getValue(idValue);
|
||||
String formatValue = props[i].getScalarType().format(v);
|
||||
if (i > 0){
|
||||
sb.append("|");
|
||||
}
|
||||
sb.append(formatValue);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object[] getIdValues(Object bean) {
|
||||
bean = embIdProperty.getValue(bean);
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue(bean);
|
||||
}
|
||||
return bindvalues;
|
||||
}
|
||||
|
||||
public Object[] getBindValues(Object value) {
|
||||
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue(value);
|
||||
}
|
||||
return bindvalues;
|
||||
}
|
||||
|
||||
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue(value);
|
||||
sqlUpdate.addParameter(embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void bindId(DataBind dataBind, Object value) throws SQLException {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue(value);
|
||||
props[i].bind(dataBind, embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public Object readData(DataInput dataInput) throws IOException {
|
||||
|
||||
Object embId = idDesc.createVanillaBean();
|
||||
boolean notNull = true;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].readData(dataInput);
|
||||
props[i].setValue(embId, value);
|
||||
if (value == null) {
|
||||
notNull = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (notNull) {
|
||||
return embId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue(idValue);
|
||||
props[i].writeData(dataOutput, embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadIgnore(DbReadContext ctx) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].loadIgnore(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
public Object read(DbReadContext ctx) throws SQLException {
|
||||
|
||||
Object embId = idDesc.createVanillaBean();
|
||||
boolean notNull = true;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].readSet(ctx, embId, null);
|
||||
if (value == null) {
|
||||
notNull = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (notNull) {
|
||||
return embId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
|
||||
|
||||
Object embId = read(ctx);
|
||||
if (embId != null) {
|
||||
embIdProperty.setValue(bean, embId);
|
||||
return embId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].appendSelect(ctx, subQuery);
|
||||
}
|
||||
}
|
||||
|
||||
public String getAssocIdInExpr(String prefix) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
if (prefix != null) {
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getName());
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getAssocOneIdExpr(String prefix, String operator) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
if (prefix != null) {
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
|
||||
sb.append(embIdProperty.getName());
|
||||
sb.append(".");
|
||||
sb.append(props[i].getName());
|
||||
sb.append(operator);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getBindIdSql(String baseTableAlias) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
if (baseTableAlias != null) {
|
||||
sb.append(baseTableAlias);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getDbColumn());
|
||||
sb.append(" = ? ");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getBindIdInSql(String baseTableAlias) {
|
||||
|
||||
if (idInExpandedForm){
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
if (baseTableAlias != null){
|
||||
sb.append(baseTableAlias);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getDbColumn());
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object convertSetId(Object idValue, Object bean) {
|
||||
|
||||
// can not cast/convert if it is embedded
|
||||
if (bean != null) {
|
||||
// support PropertyChangeSupport
|
||||
embIdProperty.setValueIntercept(bean, idValue);
|
||||
}
|
||||
|
||||
return idValue;
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.deploy.id;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocOne;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
|
||||
import com.avaje.ebeaninternal.server.query.SplitName;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
|
||||
/**
|
||||
* Bind an Id that is an Embedded bean.
|
||||
*/
|
||||
public final class IdBinderEmbedded implements IdBinder {
|
||||
|
||||
private final BeanPropertyAssocOne<?> embIdProperty;
|
||||
|
||||
private final boolean idInExpandedForm;
|
||||
|
||||
private BeanProperty[] props;
|
||||
|
||||
private BeanDescriptor<?> idDesc;
|
||||
|
||||
private String idInValueSql;
|
||||
|
||||
|
||||
public IdBinderEmbedded(boolean idInExpandedForm, BeanPropertyAssocOne<?> embIdProperty) {
|
||||
this.idInExpandedForm = idInExpandedForm;
|
||||
this.embIdProperty = embIdProperty;
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
this.idDesc = embIdProperty.getTargetDescriptor();
|
||||
this.props = embIdProperty.getProperties();
|
||||
this.idInValueSql = idInExpandedForm ? idInExpanded() : idInCompressed();
|
||||
}
|
||||
|
||||
private String idInExpanded() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
sb.append(embIdProperty.getName());
|
||||
sb.append(".");
|
||||
sb.append(props[i].getName());
|
||||
sb.append("=?");
|
||||
}
|
||||
sb.append(")");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String idInCompressed() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("?");
|
||||
}
|
||||
sb.append(")");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getOrderBy(String pathPrefix, boolean ascending){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
if (pathPrefix != null){
|
||||
sb.append(pathPrefix).append(".");
|
||||
}
|
||||
|
||||
sb.append(embIdProperty.getName()).append(".");
|
||||
sb.append(props[i].getName());
|
||||
if (!ascending){
|
||||
sb.append(" desc");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object v = props[i].getValue(id);
|
||||
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
|
||||
name.add(rdn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
|
||||
Object id = embIdProperty.getValue(bean);
|
||||
createLdapNameById(name, id);
|
||||
}
|
||||
|
||||
public BeanDescriptor<?> getIdBeanDescriptor() {
|
||||
return idDesc;
|
||||
}
|
||||
|
||||
public int getPropertyCount() {
|
||||
return props.length;
|
||||
}
|
||||
|
||||
public String getIdProperty() {
|
||||
return embIdProperty.getName();
|
||||
}
|
||||
|
||||
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
|
||||
|
||||
prefix = SplitName.add(prefix, embIdProperty.getName());
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].buildSelectExpressionChain(prefix, selectChain);
|
||||
}
|
||||
}
|
||||
|
||||
public BeanProperty findBeanProperty(String dbColumnName) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (dbColumnName.equalsIgnoreCase(props[i].getDbColumn())) {
|
||||
return props[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isComplexId() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getDefaultOrderBy() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
|
||||
sb.append(embIdProperty.getName());
|
||||
sb.append(".");
|
||||
sb.append(props[i].getName());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public BeanProperty[] getProperties() {
|
||||
return props;
|
||||
}
|
||||
|
||||
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
request.addBindValue(props[i].getValue(value));
|
||||
}
|
||||
}
|
||||
|
||||
public String getIdInValueExprDelete(int size) {
|
||||
if (!idInExpandedForm){
|
||||
return getIdInValueExpr(size);
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
|
||||
for (int j = 0; j < size; j++) {
|
||||
if (j > 0){
|
||||
sb.append(" or ");
|
||||
}
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
sb.append(props[i].getDbColumn());
|
||||
sb.append("=?");
|
||||
}
|
||||
sb.append(")");
|
||||
}
|
||||
sb.append(") ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getIdInValueExpr(int size) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (!idInExpandedForm){
|
||||
sb.append(" in");
|
||||
}
|
||||
sb.append(" (");
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (i > 0){
|
||||
if (idInExpandedForm) {
|
||||
sb.append(" or ");
|
||||
} else {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append(idInValueSql);
|
||||
}
|
||||
sb.append(") ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getIdInValueExpr() {
|
||||
return idInValueSql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the lucene string term value into embedded id.
|
||||
*/
|
||||
public Object readTerm(String idTermValue) {
|
||||
|
||||
String[] split = idTermValue.split("|");
|
||||
if (split.length != props.length){
|
||||
String msg = "Failed to split ["+idTermValue+"] using | for id.";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
Object embId = idDesc.createVanillaBean();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object v = props[i].getScalarType().parse(split[i]);
|
||||
props[i].setValue(embId, v);
|
||||
}
|
||||
return embId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the embedded id as a Lucene string term value.
|
||||
*/
|
||||
public String writeTerm(Object idValue) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object v = props[i].getValue(idValue);
|
||||
String formatValue = props[i].getScalarType().format(v);
|
||||
if (i > 0){
|
||||
sb.append("|");
|
||||
}
|
||||
sb.append(formatValue);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object[] getIdValues(Object bean) {
|
||||
bean = embIdProperty.getValue(bean);
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue(bean);
|
||||
}
|
||||
return bindvalues;
|
||||
}
|
||||
|
||||
public Object[] getBindValues(Object value) {
|
||||
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue(value);
|
||||
}
|
||||
return bindvalues;
|
||||
}
|
||||
|
||||
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue(value);
|
||||
sqlUpdate.addParameter(embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void bindId(DataBind dataBind, Object value) throws SQLException {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue(value);
|
||||
props[i].bind(dataBind, embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public Object readData(DataInput dataInput) throws IOException {
|
||||
|
||||
Object embId = idDesc.createVanillaBean();
|
||||
boolean notNull = true;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].readData(dataInput);
|
||||
props[i].setValue(embId, value);
|
||||
if (value == null) {
|
||||
notNull = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (notNull) {
|
||||
return embId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = props[i].getValue(idValue);
|
||||
props[i].writeData(dataOutput, embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadIgnore(DbReadContext ctx) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].loadIgnore(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
public Object read(DbReadContext ctx) throws SQLException {
|
||||
|
||||
Object embId = idDesc.createVanillaBean();
|
||||
boolean notNull = true;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].readSet(ctx, embId, null);
|
||||
if (value == null) {
|
||||
notNull = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (notNull) {
|
||||
return embId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
|
||||
|
||||
Object embId = read(ctx);
|
||||
if (embId != null) {
|
||||
embIdProperty.setValue(bean, embId);
|
||||
return embId;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].appendSelect(ctx, subQuery);
|
||||
}
|
||||
}
|
||||
|
||||
public String getAssocIdInExpr(String prefix) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
if (prefix != null) {
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getName());
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getAssocOneIdExpr(String prefix, String operator) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
if (prefix != null) {
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
|
||||
sb.append(embIdProperty.getName());
|
||||
sb.append(".");
|
||||
sb.append(props[i].getName());
|
||||
sb.append(operator);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getBindIdSql(String baseTableAlias) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
if (baseTableAlias != null) {
|
||||
sb.append(baseTableAlias);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getDbColumn());
|
||||
sb.append(" = ? ");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getBindIdInSql(String baseTableAlias) {
|
||||
|
||||
if (idInExpandedForm){
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
if (baseTableAlias != null){
|
||||
sb.append(baseTableAlias);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getDbColumn());
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object convertSetId(Object idValue, Object bean) {
|
||||
|
||||
// can not cast/convert if it is embedded
|
||||
if (bean != null) {
|
||||
// support PropertyChangeSupport
|
||||
embIdProperty.setValueIntercept(bean, idValue);
|
||||
}
|
||||
|
||||
return idValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,461 +1,462 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.id;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
|
||||
import com.avaje.ebeaninternal.server.lib.util.MapFromString;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Bind an Id that is made up of multiple separate properties.
|
||||
* <p>
|
||||
* The id passed in for binding is expected to be a map with the key being the
|
||||
* String name of the property and the value being that properties bind value.
|
||||
* </p>
|
||||
*/
|
||||
public final class IdBinderMultiple implements IdBinder {
|
||||
|
||||
private final BeanProperty[] props;
|
||||
|
||||
private final String idProperties;
|
||||
|
||||
private final String idInValueSql;
|
||||
|
||||
public IdBinderMultiple(BeanProperty[] idProps) {
|
||||
this.props = idProps;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < idProps.length; i++) {
|
||||
if (i > 0){
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(idProps[i].getName());
|
||||
}
|
||||
idProperties = InternString.intern(sb.toString());
|
||||
|
||||
sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0){
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("?");
|
||||
}
|
||||
sb.append(")");
|
||||
|
||||
idInValueSql = sb.toString();
|
||||
}
|
||||
|
||||
public void initialise(){
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public String getOrderBy(String pathPrefix, boolean ascending){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" ");
|
||||
}
|
||||
if (pathPrefix != null){
|
||||
sb.append(pathPrefix).append(".");
|
||||
}
|
||||
sb.append(props[i].getName());
|
||||
if (!ascending){
|
||||
sb.append(" desc");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
|
||||
|
||||
if (id instanceof Map<?,?> == false){
|
||||
throw new RuntimeException("Expecting a Map for concatinated key");
|
||||
}
|
||||
|
||||
Map<?,?> mapId = (Map<?,?>)id;
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
|
||||
Object v = mapId.get(props[i].getName());
|
||||
if (v == null){
|
||||
throw new RuntimeException("No value in Map for key "+props[i].getName());
|
||||
}
|
||||
|
||||
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
|
||||
name.add(rdn);
|
||||
}
|
||||
}
|
||||
|
||||
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].buildSelectExpressionChain(prefix, selectChain);
|
||||
}
|
||||
}
|
||||
|
||||
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
|
||||
Object v = props[i].getValue(bean);
|
||||
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
|
||||
name.add(rdn);
|
||||
}
|
||||
}
|
||||
|
||||
public int getPropertyCount() {
|
||||
return props.length;
|
||||
}
|
||||
|
||||
public String getIdProperty() {
|
||||
return idProperties;
|
||||
}
|
||||
|
||||
|
||||
public BeanProperty findBeanProperty(String dbColumnName) {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (dbColumnName.equalsIgnoreCase(props[i].getDbColumn())){
|
||||
return props[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isComplexId(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getDefaultOrderBy() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0){
|
||||
sb.append(",");
|
||||
}
|
||||
|
||||
sb.append(props[i].getName());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public BeanProperty[] getProperties() {
|
||||
return props;
|
||||
}
|
||||
|
||||
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
request.addBindValue(props[i].getValue(value));
|
||||
}
|
||||
}
|
||||
|
||||
public String getIdInValueExprDelete(int size) {
|
||||
return getIdInValueExpr(size);
|
||||
}
|
||||
|
||||
public String getIdInValueExpr(int size) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" in");
|
||||
sb.append(" (");
|
||||
sb.append(idInValueSql);
|
||||
for (int i = 1; i < size; i++) {
|
||||
sb.append(",").append(idInValueSql);
|
||||
}
|
||||
sb.append(") ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getBindIdInSql(String baseTableAlias) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
if (baseTableAlias != null){
|
||||
sb.append(baseTableAlias);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getDbColumn());
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object[] getIdValues(Object bean){
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue(bean);
|
||||
}
|
||||
return bindvalues;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object[] getBindValues(Object idValue){
|
||||
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
// concatenated id as a Map
|
||||
try {
|
||||
Map<String, ?> uidMap = (Map<String, ?>) idValue;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = uidMap.get(props[i].getName());
|
||||
bindvalues[i] = value;
|
||||
}
|
||||
|
||||
return bindvalues;
|
||||
|
||||
} catch (ClassCastException e) {
|
||||
String msg = "Expecting concatinated idValue to be a Map";
|
||||
throw new PersistenceException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Object readTerm(String idTermValue) {
|
||||
|
||||
String[] split = idTermValue.split("|");
|
||||
if (split.length != props.length){
|
||||
String msg = "Failed to split ["+idTermValue+"] using | for id.";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
Map<String, Object> uidMap = new LinkedHashMap<String, Object>();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object v = props[i].getScalarType().parse(split[i]);
|
||||
uidMap.put(props[i].getName(), v);
|
||||
}
|
||||
return uidMap;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public String writeTerm(Object idValue) {
|
||||
|
||||
Map<String, ?> uidMap = (Map<String, ?>) idValue;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object v = uidMap.get(props[i].getName());
|
||||
String formatValue = props[i].getScalarType().format(v);
|
||||
if (i > 0){
|
||||
sb.append("|");
|
||||
}
|
||||
sb.append(formatValue);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object readData(DataInput dataInput) throws IOException {
|
||||
|
||||
LinkedHashMap<String,Object> map = new LinkedHashMap<String, Object>();
|
||||
|
||||
boolean notNull = true;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].readData(dataInput);
|
||||
map.put(props[i].getName(), value);
|
||||
if (value == null) {
|
||||
notNull = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (notNull) {
|
||||
return map;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
|
||||
|
||||
Map<String,Object> map = (Map<String,Object>)idValue;
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = map.get(props[i].getName());
|
||||
//Object embFieldValue = props[i].getValue(idValue);
|
||||
props[i].writeData(dataOutput, embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadIgnore(DbReadContext ctx) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].loadIgnore(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
|
||||
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
boolean notNull = false;
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].readSet(ctx, bean, null);
|
||||
if (value != null){
|
||||
map.put(props[i].getName(), value);
|
||||
notNull = true;
|
||||
}
|
||||
}
|
||||
if (notNull){
|
||||
return map;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object read(DbReadContext ctx) throws SQLException {
|
||||
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
boolean notNull = false;
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].read(ctx);
|
||||
if (value != null){
|
||||
map.put(props[i].getName(), value);
|
||||
notNull = true;
|
||||
}
|
||||
}
|
||||
if (notNull){
|
||||
return map;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void bindId(DefaultSqlUpdate sqlUpdate, Object idValue) {
|
||||
// concatenated id as a Map
|
||||
try {
|
||||
Map<String, ?> uidMap = (Map<String, ?>) idValue;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = uidMap.get(props[i].getName());
|
||||
sqlUpdate.addParameter(value);
|
||||
}
|
||||
|
||||
} catch (ClassCastException e) {
|
||||
String msg = "Expecting concatinated idValue to be a Map";
|
||||
throw new PersistenceException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void bindId(DataBind bind, Object idValue) throws SQLException {
|
||||
|
||||
// concatenated id as a Map
|
||||
try {
|
||||
Map<String, ?> uidMap = (Map<String, ?>) idValue;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = uidMap.get(props[i].getName());
|
||||
props[i].bind(bind, value);
|
||||
}
|
||||
|
||||
} catch (ClassCastException e) {
|
||||
String msg = "Expecting concatinated idValue to be a Map";
|
||||
throw new PersistenceException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].appendSelect(ctx, subQuery);
|
||||
}
|
||||
}
|
||||
|
||||
public String getAssocIdInExpr(String prefix) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
if (prefix != null) {
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getName());
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getAssocOneIdExpr(String prefix, String operator){
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
if (prefix != null){
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getName());
|
||||
sb.append(operator);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getBindIdSql(String baseTableAlias) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
if (baseTableAlias != null){
|
||||
sb.append(baseTableAlias);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getDbColumn());
|
||||
sb.append(" = ? ");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object convertSetId(Object idValue, Object bean) {
|
||||
|
||||
// allow Map or String for concatenated id
|
||||
Map<?,?> mapVal = null;
|
||||
if (idValue instanceof Map<?,?>) {
|
||||
mapVal = (Map<?,?>) idValue;
|
||||
} else {
|
||||
mapVal = MapFromString.parse(idValue.toString());
|
||||
}
|
||||
|
||||
// Use a new LinkedHashMap to control the order
|
||||
LinkedHashMap<String,Object> newMap = new LinkedHashMap<String, Object>();
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
BeanProperty prop = props[i];
|
||||
|
||||
Object value = mapVal.get(prop.getName());
|
||||
|
||||
// Convert the property type if required
|
||||
value = props[i].getScalarType().toBeanType(value);
|
||||
newMap.put(prop.getName(), value);
|
||||
if (bean != null) {
|
||||
// support PropertyChangeSupport
|
||||
prop.setValueIntercept(bean, value);
|
||||
}
|
||||
}
|
||||
|
||||
return newMap;
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.deploy.id;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
|
||||
import com.avaje.ebeaninternal.server.lib.util.MapFromString;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
|
||||
/**
|
||||
* Bind an Id that is made up of multiple separate properties.
|
||||
* <p>
|
||||
* The id passed in for binding is expected to be a map with the key being the
|
||||
* String name of the property and the value being that properties bind value.
|
||||
* </p>
|
||||
*/
|
||||
public final class IdBinderMultiple implements IdBinder {
|
||||
|
||||
private final BeanProperty[] props;
|
||||
|
||||
private final String idProperties;
|
||||
|
||||
private final String idInValueSql;
|
||||
|
||||
public IdBinderMultiple(BeanProperty[] idProps) {
|
||||
this.props = idProps;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < idProps.length; i++) {
|
||||
if (i > 0){
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(idProps[i].getName());
|
||||
}
|
||||
idProperties = InternString.intern(sb.toString());
|
||||
|
||||
sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0){
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("?");
|
||||
}
|
||||
sb.append(")");
|
||||
|
||||
idInValueSql = sb.toString();
|
||||
}
|
||||
|
||||
public void initialise(){
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public String getOrderBy(String pathPrefix, boolean ascending){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" ");
|
||||
}
|
||||
if (pathPrefix != null){
|
||||
sb.append(pathPrefix).append(".");
|
||||
}
|
||||
sb.append(props[i].getName());
|
||||
if (!ascending){
|
||||
sb.append(" desc");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
|
||||
|
||||
if (id instanceof Map<?,?> == false){
|
||||
throw new RuntimeException("Expecting a Map for concatinated key");
|
||||
}
|
||||
|
||||
Map<?,?> mapId = (Map<?,?>)id;
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
|
||||
Object v = mapId.get(props[i].getName());
|
||||
if (v == null){
|
||||
throw new RuntimeException("No value in Map for key "+props[i].getName());
|
||||
}
|
||||
|
||||
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
|
||||
name.add(rdn);
|
||||
}
|
||||
}
|
||||
|
||||
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].buildSelectExpressionChain(prefix, selectChain);
|
||||
}
|
||||
}
|
||||
|
||||
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
|
||||
Object v = props[i].getValue(bean);
|
||||
Rdn rdn = new Rdn(props[i].getDbColumn(), v);
|
||||
name.add(rdn);
|
||||
}
|
||||
}
|
||||
|
||||
public int getPropertyCount() {
|
||||
return props.length;
|
||||
}
|
||||
|
||||
public String getIdProperty() {
|
||||
return idProperties;
|
||||
}
|
||||
|
||||
|
||||
public BeanProperty findBeanProperty(String dbColumnName) {
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (dbColumnName.equalsIgnoreCase(props[i].getDbColumn())){
|
||||
return props[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isComplexId(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getDefaultOrderBy() {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0){
|
||||
sb.append(",");
|
||||
}
|
||||
|
||||
sb.append(props[i].getName());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public BeanProperty[] getProperties() {
|
||||
return props;
|
||||
}
|
||||
|
||||
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
request.addBindValue(props[i].getValue(value));
|
||||
}
|
||||
}
|
||||
|
||||
public String getIdInValueExprDelete(int size) {
|
||||
return getIdInValueExpr(size);
|
||||
}
|
||||
|
||||
public String getIdInValueExpr(int size) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" in");
|
||||
sb.append(" (");
|
||||
sb.append(idInValueSql);
|
||||
for (int i = 1; i < size; i++) {
|
||||
sb.append(",").append(idInValueSql);
|
||||
}
|
||||
sb.append(") ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getBindIdInSql(String baseTableAlias) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
if (baseTableAlias != null){
|
||||
sb.append(baseTableAlias);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getDbColumn());
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object[] getIdValues(Object bean){
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
bindvalues[i] = props[i].getValue(bean);
|
||||
}
|
||||
return bindvalues;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object[] getBindValues(Object idValue){
|
||||
|
||||
Object[] bindvalues = new Object[props.length];
|
||||
// concatenated id as a Map
|
||||
try {
|
||||
Map<String, ?> uidMap = (Map<String, ?>) idValue;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = uidMap.get(props[i].getName());
|
||||
bindvalues[i] = value;
|
||||
}
|
||||
|
||||
return bindvalues;
|
||||
|
||||
} catch (ClassCastException e) {
|
||||
String msg = "Expecting concatinated idValue to be a Map";
|
||||
throw new PersistenceException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Object readTerm(String idTermValue) {
|
||||
|
||||
String[] split = idTermValue.split("|");
|
||||
if (split.length != props.length){
|
||||
String msg = "Failed to split ["+idTermValue+"] using | for id.";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
Map<String, Object> uidMap = new LinkedHashMap<String, Object>();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object v = props[i].getScalarType().parse(split[i]);
|
||||
uidMap.put(props[i].getName(), v);
|
||||
}
|
||||
return uidMap;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public String writeTerm(Object idValue) {
|
||||
|
||||
Map<String, ?> uidMap = (Map<String, ?>) idValue;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object v = uidMap.get(props[i].getName());
|
||||
String formatValue = props[i].getScalarType().format(v);
|
||||
if (i > 0){
|
||||
sb.append("|");
|
||||
}
|
||||
sb.append(formatValue);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object readData(DataInput dataInput) throws IOException {
|
||||
|
||||
LinkedHashMap<String,Object> map = new LinkedHashMap<String, Object>();
|
||||
|
||||
boolean notNull = true;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].readData(dataInput);
|
||||
map.put(props[i].getName(), value);
|
||||
if (value == null) {
|
||||
notNull = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (notNull) {
|
||||
return map;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
|
||||
|
||||
Map<String,Object> map = (Map<String,Object>)idValue;
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object embFieldValue = map.get(props[i].getName());
|
||||
//Object embFieldValue = props[i].getValue(idValue);
|
||||
props[i].writeData(dataOutput, embFieldValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadIgnore(DbReadContext ctx) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].loadIgnore(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
|
||||
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
boolean notNull = false;
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].readSet(ctx, bean, null);
|
||||
if (value != null){
|
||||
map.put(props[i].getName(), value);
|
||||
notNull = true;
|
||||
}
|
||||
}
|
||||
if (notNull){
|
||||
return map;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object read(DbReadContext ctx) throws SQLException {
|
||||
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
boolean notNull = false;
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = props[i].read(ctx);
|
||||
if (value != null){
|
||||
map.put(props[i].getName(), value);
|
||||
notNull = true;
|
||||
}
|
||||
}
|
||||
if (notNull){
|
||||
return map;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void bindId(DefaultSqlUpdate sqlUpdate, Object idValue) {
|
||||
// concatenated id as a Map
|
||||
try {
|
||||
Map<String, ?> uidMap = (Map<String, ?>) idValue;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = uidMap.get(props[i].getName());
|
||||
sqlUpdate.addParameter(value);
|
||||
}
|
||||
|
||||
} catch (ClassCastException e) {
|
||||
String msg = "Expecting concatinated idValue to be a Map";
|
||||
throw new PersistenceException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void bindId(DataBind bind, Object idValue) throws SQLException {
|
||||
|
||||
// concatenated id as a Map
|
||||
try {
|
||||
Map<String, ?> uidMap = (Map<String, ?>) idValue;
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object value = uidMap.get(props[i].getName());
|
||||
props[i].bind(bind, value);
|
||||
}
|
||||
|
||||
} catch (ClassCastException e) {
|
||||
String msg = "Expecting concatinated idValue to be a Map";
|
||||
throw new PersistenceException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
props[i].appendSelect(ctx, subQuery);
|
||||
}
|
||||
}
|
||||
|
||||
public String getAssocIdInExpr(String prefix) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("(");
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
if (prefix != null) {
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getName());
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getAssocOneIdExpr(String prefix, String operator){
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
if (prefix != null){
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getName());
|
||||
sb.append(operator);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getBindIdSql(String baseTableAlias) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(" and ");
|
||||
}
|
||||
if (baseTableAlias != null){
|
||||
sb.append(baseTableAlias);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(props[i].getDbColumn());
|
||||
sb.append(" = ? ");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object convertSetId(Object idValue, Object bean) {
|
||||
|
||||
// allow Map or String for concatenated id
|
||||
Map<?,?> mapVal = null;
|
||||
if (idValue instanceof Map<?,?>) {
|
||||
mapVal = (Map<?,?>) idValue;
|
||||
} else {
|
||||
mapVal = MapFromString.parse(idValue.toString());
|
||||
}
|
||||
|
||||
// Use a new LinkedHashMap to control the order
|
||||
LinkedHashMap<String,Object> newMap = new LinkedHashMap<String, Object>();
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
BeanProperty prop = props[i];
|
||||
|
||||
Object value = mapVal.get(prop.getName());
|
||||
|
||||
// Convert the property type if required
|
||||
value = props[i].getScalarType().toBeanType(value);
|
||||
newMap.put(prop.getName(), value);
|
||||
if (bean != null) {
|
||||
// support PropertyChangeSupport
|
||||
prop.setValueIntercept(bean, value);
|
||||
}
|
||||
}
|
||||
|
||||
return newMap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,233 +1,234 @@
|
||||
package com.avaje.ebeaninternal.server.deploy.id;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Bind an Id where the Id is made of a single property (not embedded).
|
||||
*/
|
||||
public final class IdBinderSimple implements IdBinder {
|
||||
|
||||
private final BeanProperty idProperty;
|
||||
|
||||
private final String bindIdSql;
|
||||
|
||||
private final BeanProperty[] properties;
|
||||
|
||||
private final Class<?> expectedType;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final ScalarType scalarType;
|
||||
|
||||
public IdBinderSimple(BeanProperty idProperty) {
|
||||
this.idProperty = idProperty;
|
||||
this.scalarType = idProperty.getScalarType();
|
||||
this.expectedType = idProperty.getPropertyType();
|
||||
this.properties = new BeanProperty[1];
|
||||
properties[0] = idProperty;
|
||||
bindIdSql = InternString.intern(idProperty.getDbColumn()+" = ? ");
|
||||
}
|
||||
|
||||
public void initialise(){
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public Object readTerm(String idTermValue) {
|
||||
return scalarType.parse(idTermValue);
|
||||
}
|
||||
|
||||
public String writeTerm(Object idValue) {
|
||||
return scalarType.format(idValue);
|
||||
}
|
||||
|
||||
public String getOrderBy(String pathPrefix, boolean ascending){
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (pathPrefix != null){
|
||||
sb.append(pathPrefix).append(".");
|
||||
}
|
||||
sb.append(idProperty.getName());
|
||||
if (!ascending){
|
||||
sb.append(" desc");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
|
||||
|
||||
idProperty.buildSelectExpressionChain(prefix, selectChain);
|
||||
}
|
||||
|
||||
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
|
||||
Rdn rdn = new Rdn(idProperty.getDbColumn(), id);
|
||||
name.add(rdn);
|
||||
}
|
||||
|
||||
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
|
||||
Object id = idProperty.getValue(bean);
|
||||
createLdapNameById(name, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 1.
|
||||
*/
|
||||
public int getPropertyCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String getIdProperty() {
|
||||
return idProperty.getName();
|
||||
}
|
||||
|
||||
public BeanProperty findBeanProperty(String dbColumnName) {
|
||||
if (dbColumnName.equalsIgnoreCase(idProperty.getDbColumn())){
|
||||
return idProperty;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isComplexId(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDefaultOrderBy() {
|
||||
return idProperty.getName();
|
||||
}
|
||||
|
||||
public BeanProperty[] getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String getBindIdInSql(String baseTableAlias) {
|
||||
if (baseTableAlias == null){
|
||||
return idProperty.getDbColumn();
|
||||
} else {
|
||||
return baseTableAlias+"."+idProperty.getDbColumn();
|
||||
}
|
||||
}
|
||||
|
||||
public String getBindIdSql(String baseTableAlias) {
|
||||
if (baseTableAlias == null){
|
||||
return bindIdSql;
|
||||
} else {
|
||||
return baseTableAlias+"."+bindIdSql;
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] getIdValues(Object bean){
|
||||
return new Object[]{idProperty.getValue(bean)};
|
||||
}
|
||||
|
||||
public Object[] getBindValues(Object idValue){
|
||||
return new Object[]{idValue};
|
||||
}
|
||||
|
||||
public String getIdInValueExprDelete(int size) {
|
||||
return getIdInValueExpr(size);
|
||||
}
|
||||
|
||||
public String getIdInValueExpr(int size) {
|
||||
StringBuilder sb = new StringBuilder(2*size+10);
|
||||
sb.append(" in");
|
||||
sb.append(" (?");
|
||||
for (int i = 1; i < size; i++) {
|
||||
sb.append(",?");
|
||||
}
|
||||
sb.append(") ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
|
||||
value = convertSetId(value, null);
|
||||
request.addBindValue(value);
|
||||
}
|
||||
|
||||
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
|
||||
sqlUpdate.addParameter(value);
|
||||
}
|
||||
|
||||
public void bindId(DataBind dataBind, Object value) throws SQLException {
|
||||
value = idProperty.toBeanType(value);
|
||||
idProperty.bind(dataBind, value);
|
||||
}
|
||||
|
||||
public void writeData(DataOutput os, Object value) throws IOException {
|
||||
idProperty.writeData(os, value);
|
||||
}
|
||||
|
||||
public Object readData(DataInput is) throws IOException {
|
||||
return idProperty.readData(is);
|
||||
}
|
||||
|
||||
public void loadIgnore(DbReadContext ctx) {
|
||||
idProperty.loadIgnore(ctx);
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
|
||||
Object id = idProperty.read(ctx);
|
||||
if (id != null){
|
||||
idProperty.setValue(bean, id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public Object read(DbReadContext ctx) throws SQLException {
|
||||
return idProperty.read(ctx);
|
||||
}
|
||||
|
||||
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
|
||||
idProperty.appendSelect(ctx, subQuery);
|
||||
}
|
||||
|
||||
public String getAssocOneIdExpr(String prefix, String operator){
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (prefix != null){
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(idProperty.getName());
|
||||
sb.append(operator);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getAssocIdInExpr(String prefix) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (prefix != null) {
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(idProperty.getName());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object convertSetId(Object idValue, Object bean) {
|
||||
|
||||
if (!idValue.getClass().equals(expectedType)){
|
||||
idValue = scalarType.toBeanType(idValue);
|
||||
}
|
||||
|
||||
if (bean != null) {
|
||||
// support PropertyChangeSupport
|
||||
idProperty.setValueIntercept(bean, idValue);
|
||||
}
|
||||
|
||||
return idValue;
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.deploy.id;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.naming.InvalidNameException;
|
||||
import javax.naming.ldap.LdapName;
|
||||
import javax.naming.ldap.Rdn;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.DefaultSqlUpdate;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
|
||||
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
|
||||
/**
|
||||
* Bind an Id where the Id is made of a single property (not embedded).
|
||||
*/
|
||||
public final class IdBinderSimple implements IdBinder {
|
||||
|
||||
private final BeanProperty idProperty;
|
||||
|
||||
private final String bindIdSql;
|
||||
|
||||
private final BeanProperty[] properties;
|
||||
|
||||
private final Class<?> expectedType;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final ScalarType scalarType;
|
||||
|
||||
public IdBinderSimple(BeanProperty idProperty) {
|
||||
this.idProperty = idProperty;
|
||||
this.scalarType = idProperty.getScalarType();
|
||||
this.expectedType = idProperty.getPropertyType();
|
||||
this.properties = new BeanProperty[1];
|
||||
properties[0] = idProperty;
|
||||
bindIdSql = InternString.intern(idProperty.getDbColumn()+" = ? ");
|
||||
}
|
||||
|
||||
public void initialise(){
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public Object readTerm(String idTermValue) {
|
||||
return scalarType.parse(idTermValue);
|
||||
}
|
||||
|
||||
public String writeTerm(Object idValue) {
|
||||
return scalarType.format(idValue);
|
||||
}
|
||||
|
||||
public String getOrderBy(String pathPrefix, boolean ascending){
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (pathPrefix != null){
|
||||
sb.append(pathPrefix).append(".");
|
||||
}
|
||||
sb.append(idProperty.getName());
|
||||
if (!ascending){
|
||||
sb.append(" desc");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void buildSelectExpressionChain(String prefix, List<String> selectChain) {
|
||||
|
||||
idProperty.buildSelectExpressionChain(prefix, selectChain);
|
||||
}
|
||||
|
||||
public void createLdapNameById(LdapName name, Object id) throws InvalidNameException {
|
||||
Rdn rdn = new Rdn(idProperty.getDbColumn(), id);
|
||||
name.add(rdn);
|
||||
}
|
||||
|
||||
public void createLdapNameByBean(LdapName name, Object bean) throws InvalidNameException {
|
||||
Object id = idProperty.getValue(bean);
|
||||
createLdapNameById(name, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 1.
|
||||
*/
|
||||
public int getPropertyCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String getIdProperty() {
|
||||
return idProperty.getName();
|
||||
}
|
||||
|
||||
public BeanProperty findBeanProperty(String dbColumnName) {
|
||||
if (dbColumnName.equalsIgnoreCase(idProperty.getDbColumn())){
|
||||
return idProperty;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isComplexId(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDefaultOrderBy() {
|
||||
return idProperty.getName();
|
||||
}
|
||||
|
||||
public BeanProperty[] getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public String getBindIdInSql(String baseTableAlias) {
|
||||
if (baseTableAlias == null){
|
||||
return idProperty.getDbColumn();
|
||||
} else {
|
||||
return baseTableAlias+"."+idProperty.getDbColumn();
|
||||
}
|
||||
}
|
||||
|
||||
public String getBindIdSql(String baseTableAlias) {
|
||||
if (baseTableAlias == null){
|
||||
return bindIdSql;
|
||||
} else {
|
||||
return baseTableAlias+"."+bindIdSql;
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] getIdValues(Object bean){
|
||||
return new Object[]{idProperty.getValue(bean)};
|
||||
}
|
||||
|
||||
public Object[] getBindValues(Object idValue){
|
||||
return new Object[]{idValue};
|
||||
}
|
||||
|
||||
public String getIdInValueExprDelete(int size) {
|
||||
return getIdInValueExpr(size);
|
||||
}
|
||||
|
||||
public String getIdInValueExpr(int size) {
|
||||
StringBuilder sb = new StringBuilder(2*size+10);
|
||||
sb.append(" in");
|
||||
sb.append(" (?");
|
||||
for (int i = 1; i < size; i++) {
|
||||
sb.append(",?");
|
||||
}
|
||||
sb.append(") ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void addIdInBindValue(SpiExpressionRequest request, Object value) {
|
||||
value = convertSetId(value, null);
|
||||
request.addBindValue(value);
|
||||
}
|
||||
|
||||
public void bindId(DefaultSqlUpdate sqlUpdate, Object value) {
|
||||
sqlUpdate.addParameter(value);
|
||||
}
|
||||
|
||||
public void bindId(DataBind dataBind, Object value) throws SQLException {
|
||||
value = idProperty.toBeanType(value);
|
||||
idProperty.bind(dataBind, value);
|
||||
}
|
||||
|
||||
public void writeData(DataOutput os, Object value) throws IOException {
|
||||
idProperty.writeData(os, value);
|
||||
}
|
||||
|
||||
public Object readData(DataInput is) throws IOException {
|
||||
return idProperty.readData(is);
|
||||
}
|
||||
|
||||
public void loadIgnore(DbReadContext ctx) {
|
||||
idProperty.loadIgnore(ctx);
|
||||
}
|
||||
|
||||
public Object readSet(DbReadContext ctx, Object bean) throws SQLException {
|
||||
Object id = idProperty.read(ctx);
|
||||
if (id != null){
|
||||
idProperty.setValue(bean, id);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public Object read(DbReadContext ctx) throws SQLException {
|
||||
return idProperty.read(ctx);
|
||||
}
|
||||
|
||||
public void appendSelect(DbSqlContext ctx, boolean subQuery) {
|
||||
idProperty.appendSelect(ctx, subQuery);
|
||||
}
|
||||
|
||||
public String getAssocOneIdExpr(String prefix, String operator){
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (prefix != null){
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(idProperty.getName());
|
||||
sb.append(operator);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String getAssocIdInExpr(String prefix) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (prefix != null) {
|
||||
sb.append(prefix);
|
||||
sb.append(".");
|
||||
}
|
||||
sb.append(idProperty.getName());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Object convertSetId(Object idValue, Object bean) {
|
||||
|
||||
if (!idValue.getClass().equals(expectedType)){
|
||||
idValue = scalarType.toBeanType(idValue);
|
||||
}
|
||||
|
||||
if (bean != null) {
|
||||
// support PropertyChangeSupport
|
||||
idProperty.setValueIntercept(bean, idValue);
|
||||
}
|
||||
|
||||
return idValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ import com.avaje.ebean.annotation.LdapAttribute;
|
||||
import com.avaje.ebean.annotation.LdapId;
|
||||
import com.avaje.ebean.annotation.UpdatedTimestamp;
|
||||
import com.avaje.ebean.config.EncryptDeploy;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.ebean.config.EncryptDeploy.Mode;
|
||||
import com.avaje.ebean.config.GlobalProperties;
|
||||
import com.avaje.ebean.config.dbplatform.DbEncrypt;
|
||||
import com.avaje.ebean.config.dbplatform.DbEncryptFunction;
|
||||
import com.avaje.ebean.config.dbplatform.IdType;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.avaje.ebeaninternal.server.lib.sql;
|
||||
|
||||
import com.avaje.ebeaninternal.jdbc.PreparedStatementDelegator;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLWarning;
|
||||
|
||||
import com.avaje.ebeaninternal.jdbc.PreparedStatementDelegator;
|
||||
|
||||
/**
|
||||
* Implements the Statement methods for ExtendedPreparedStatement.
|
||||
* <p>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.lib.sql;
|
||||
|
||||
import com.avaje.ebeaninternal.jdbc.ConnectionDelegator;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
@@ -16,6 +14,8 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.avaje.ebeaninternal.jdbc.ConnectionDelegator;
|
||||
|
||||
/**
|
||||
* Is a connection that belongs to a DataSourcePool.
|
||||
*
|
||||
|
||||
@@ -6,8 +6,6 @@ import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import com.avaje.ebeaninternal.server.lib.util.StringHelper;
|
||||
|
||||
/**
|
||||
* Parse an xml document into a Dnode tree.
|
||||
*/
|
||||
|
||||
@@ -11,8 +11,8 @@ import com.avaje.ebeaninternal.api.BindParams;
|
||||
import com.avaje.ebeaninternal.api.SpiSqlUpdate;
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestUpdateSql;
|
||||
import com.avaje.ebeaninternal.server.core.PstmtBatch;
|
||||
import com.avaje.ebeaninternal.server.core.PersistRequestUpdateSql.SqlType;
|
||||
import com.avaje.ebeaninternal.server.core.PstmtBatch;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import com.avaje.ebeaninternal.server.util.BindParamsParser;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,10 @@
|
||||
package com.avaje.ebeaninternal.server.query;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebean.config.dbplatform.DatabasePlatform;
|
||||
import com.avaje.ebean.config.dbplatform.SqlLimitResponse;
|
||||
import com.avaje.ebean.config.dbplatform.SqlLimiter;
|
||||
@@ -12,10 +17,6 @@ import com.avaje.ebeaninternal.server.deploy.DeployParser;
|
||||
import com.avaje.ebeaninternal.server.persist.Binder;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryLimitRequest;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Factory for SqlSelectClause based on raw sql.
|
||||
* <p>
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.query;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.bean.EntityBeanIntercept;
|
||||
@@ -16,12 +22,6 @@ import com.avaje.ebeaninternal.server.deploy.TableJoin;
|
||||
import com.avaje.ebeaninternal.server.deploy.id.IdBinder;
|
||||
import com.avaje.ebeaninternal.server.lib.util.StringHelper;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Normal bean included in the query.
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.text.json;
|
||||
|
||||
import com.avaje.ebean.text.json.JsonElement;
|
||||
import com.avaje.ebean.text.json.JsonElementArray;
|
||||
import com.avaje.ebean.text.json.JsonElementBoolean;
|
||||
import com.avaje.ebean.text.json.JsonElementNull;
|
||||
import com.avaje.ebean.text.json.JsonElementNumber;
|
||||
import com.avaje.ebean.text.json.JsonElementObject;
|
||||
import com.avaje.ebean.text.json.JsonElementString;
|
||||
import com.avaje.ebean.text.json.JsonElement;
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -13,8 +13,8 @@ import java.util.logging.Logger;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionLogBuffer;
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionLogWriter;
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionLogBuffer.LogEntry;
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionLogWriter;
|
||||
|
||||
/**
|
||||
* Default transaction logger implementation.
|
||||
|
||||
+1
-1
@@ -6,8 +6,8 @@ import java.util.logging.Logger;
|
||||
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionLogBuffer;
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionLogWriter;
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionLogBuffer.LogEntry;
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionLogWriter;
|
||||
|
||||
/**
|
||||
* A transactionLogger that uses a java.util.logging.Logger.
|
||||
|
||||
@@ -3,8 +3,8 @@ package com.avaje.ebeaninternal.server.type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
import com.avaje.ebeaninternal.server.query.SplitName;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.Encryptor;
|
||||
import com.avaje.ebean.config.EncryptKey;
|
||||
import com.avaje.ebean.config.EncryptKeyManager;
|
||||
import com.avaje.ebean.config.Encryptor;
|
||||
|
||||
public class DataEncryptSupport {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user