repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
yyxhdy/ManyEAs | src/jmetal/core/Problem.java | // Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import java.io.Serializable;
import jmetal.util.JMException; | } // getNumberOfObjectives
/**
* Gets the lower bound of the ith encodings.variable of the problem.
*
* @param i
* The index of the encodings.variable.
* @return The lower bound.
*/
public double getLowerLimit(int i) {
return lowerLimit_[i];
} // getLowerLimit
/**
* Gets the upper bound of the ith encodings.variable of the problem.
*
* @param i
* The index of the encodings.variable.
* @return The upper bound.
*/
public double getUpperLimit(int i) {
return upperLimit_[i];
} // getUpperLimit
/**
* Evaluates a <code>Solution</code> object.
*
* @param solution
* The <code>Solution</code> to evaluate.
*/ | // Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/core/Problem.java
import java.io.Serializable;
import jmetal.util.JMException;
} // getNumberOfObjectives
/**
* Gets the lower bound of the ith encodings.variable of the problem.
*
* @param i
* The index of the encodings.variable.
* @return The lower bound.
*/
public double getLowerLimit(int i) {
return lowerLimit_[i];
} // getLowerLimit
/**
* Gets the upper bound of the ith encodings.variable of the problem.
*
* @param i
* The index of the encodings.variable.
* @return The upper bound.
*/
public double getUpperLimit(int i) {
return upperLimit_[i];
} // getUpperLimit
/**
* Evaluates a <code>Solution</code> object.
*
* @param solution
* The <code>Solution</code> to evaluate.
*/ | public abstract void evaluate(Solution solution) throws JMException; |
yyxhdy/ManyEAs | src/jmetal/encodings/variable/Real.java | // Path: src/jmetal/core/Variable.java
// public abstract class Variable implements Serializable {
//
// /**
// * Creates an exact copy of a <code>Variable</code> object.
// * @return the copy of the object.
// */
// public abstract Variable deepCopy();
//
// /**
// * Gets the double value representating the encodings.variable.
// * It is used in subclasses of <code>Variable</code> (i.e. <code>Real</code>
// * and <code>Int</code>).
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public double getValue() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method getValue");
// throw new JMException("Exception in " + name + ".getValue()") ;
// } // getValue
//
// /**
// * Sets a double value to a encodings.variable in subclasses of <code>Variable</code>.
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public void setValue(double value) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method setValue");
// throw new JMException("Exception in " + name + ".setValue()") ;
// } // setValue
//
// /**
// * Gets the lower bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have a lower bound,
// * a call to this method is considered a fatal error by default,
// * and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public double getLowerBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getLowerBound()");
// throw new JMException("Exception in " + name + ".getLowerBound()") ;
// } // getLowerBound
//
// /**
// * Gets the upper bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have an upper
// * bound, a call to this method is considered a fatal error by default, and the
// * program is terminated. Those classes requiring this method must redefine it.
// */
// public double getUpperBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getUpperBound()");
// throw new JMException("Exception in " + name + ".getUpperBound()") ;
// } // getUpperBound
//
// /**
// * Sets the lower bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have a lower bound, a call to this method
// * is considered a fatal error by default and the program is terminated.
// * Those classes requiring this method must to redefine it.
// */
// public void setLowerBound(double lowerBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setLowerBound()");
// throw new JMException("Exception in " + name + ".setLowerBound()") ;
// } // setLowerBound
//
// /**
// * Sets the upper bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have an upper bound, a call to this method
// * is considered a fatal error by default, and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public void setUpperBound(double upperBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setUpperBound()");
// throw new JMException("Exception in " + name + ".setUpperBound()") ;
// } // setUpperBound
//
// /**
// * Gets the type of the encodings.variable. The types are defined in class Problem.
// * @return The type of the encodings.variable
// */
//
// public Class getVariableType() {
// return this.getClass() ;
// } // getVariableType
// } // Variable
//
// Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import jmetal.util.Configuration;
import jmetal.util.JMException;
import jmetal.util.PseudoRandom;
import jmetal.core.Variable; | public Real(Variable variable) throws JMException{
lowerBound_ = variable.getLowerBound();
upperBound_ = variable.getUpperBound();
value_ = variable.getValue();
} //Real
/**
* Gets the value of the <code>Real</code> encodings.variable.
* @return the value.
*/
public double getValue() {
return value_;
} // getValue
/**
* Sets the value of the encodings.variable.
* @param value The value.
*/
public void setValue(double value) {
value_ = value;
} // setValue
/**
* Returns a exact copy of the <code>Real</code> encodings.variable
* @return the copy
*/
public Variable deepCopy(){
try {
return new Real(this);
} catch (JMException e) { | // Path: src/jmetal/core/Variable.java
// public abstract class Variable implements Serializable {
//
// /**
// * Creates an exact copy of a <code>Variable</code> object.
// * @return the copy of the object.
// */
// public abstract Variable deepCopy();
//
// /**
// * Gets the double value representating the encodings.variable.
// * It is used in subclasses of <code>Variable</code> (i.e. <code>Real</code>
// * and <code>Int</code>).
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public double getValue() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method getValue");
// throw new JMException("Exception in " + name + ".getValue()") ;
// } // getValue
//
// /**
// * Sets a double value to a encodings.variable in subclasses of <code>Variable</code>.
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public void setValue(double value) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method setValue");
// throw new JMException("Exception in " + name + ".setValue()") ;
// } // setValue
//
// /**
// * Gets the lower bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have a lower bound,
// * a call to this method is considered a fatal error by default,
// * and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public double getLowerBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getLowerBound()");
// throw new JMException("Exception in " + name + ".getLowerBound()") ;
// } // getLowerBound
//
// /**
// * Gets the upper bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have an upper
// * bound, a call to this method is considered a fatal error by default, and the
// * program is terminated. Those classes requiring this method must redefine it.
// */
// public double getUpperBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getUpperBound()");
// throw new JMException("Exception in " + name + ".getUpperBound()") ;
// } // getUpperBound
//
// /**
// * Sets the lower bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have a lower bound, a call to this method
// * is considered a fatal error by default and the program is terminated.
// * Those classes requiring this method must to redefine it.
// */
// public void setLowerBound(double lowerBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setLowerBound()");
// throw new JMException("Exception in " + name + ".setLowerBound()") ;
// } // setLowerBound
//
// /**
// * Sets the upper bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have an upper bound, a call to this method
// * is considered a fatal error by default, and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public void setUpperBound(double upperBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setUpperBound()");
// throw new JMException("Exception in " + name + ".setUpperBound()") ;
// } // setUpperBound
//
// /**
// * Gets the type of the encodings.variable. The types are defined in class Problem.
// * @return The type of the encodings.variable
// */
//
// public Class getVariableType() {
// return this.getClass() ;
// } // getVariableType
// } // Variable
//
// Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/encodings/variable/Real.java
import jmetal.util.Configuration;
import jmetal.util.JMException;
import jmetal.util.PseudoRandom;
import jmetal.core.Variable;
public Real(Variable variable) throws JMException{
lowerBound_ = variable.getLowerBound();
upperBound_ = variable.getUpperBound();
value_ = variable.getValue();
} //Real
/**
* Gets the value of the <code>Real</code> encodings.variable.
* @return the value.
*/
public double getValue() {
return value_;
} // getValue
/**
* Sets the value of the encodings.variable.
* @param value The value.
*/
public void setValue(double value) {
value_ = value;
} // setValue
/**
* Returns a exact copy of the <code>Real</code> encodings.variable
* @return the copy
*/
public Variable deepCopy(){
try {
return new Real(this);
} catch (JMException e) { | Configuration.logger_.severe("Real.deepCopy.execute: JMException"); |
yyxhdy/ManyEAs | src/jmetal/core/Operator.java | // Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import jmetal.util.JMException; | // Operator.java
//
// Authors:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.core;
/**
* Class representing an operator
*/
public abstract class Operator implements Serializable {
/**
* Stores the current operator parameters.
* It is defined as a Map of pairs <<code>String</code>, <code>Object</code>>,
* and it allow objects to be accessed by their names, which are specified
* by the string.
*/
protected final Map<String , Object> parameters_;
/**
* Constructor.
*/
public Operator(HashMap<String , Object> parameters) {
parameters_ = parameters;
} // Operator
/**
* Abstract method that must be defined by all the operators. When invoked,
* this method executes the operator represented by the current object.
* @param object This param inherits from Object to allow different kinds
* of parameters for each operator. For example, a selection
* operator typically receives a <code>SolutionSet</code> as
* a parameter, while a mutation operator receives a
* <code>Solution</code>.
* @return An object reference. The returned value depends on the operator.
*/ | // Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/core/Operator.java
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import jmetal.util.JMException;
// Operator.java
//
// Authors:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.core;
/**
* Class representing an operator
*/
public abstract class Operator implements Serializable {
/**
* Stores the current operator parameters.
* It is defined as a Map of pairs <<code>String</code>, <code>Object</code>>,
* and it allow objects to be accessed by their names, which are specified
* by the string.
*/
protected final Map<String , Object> parameters_;
/**
* Constructor.
*/
public Operator(HashMap<String , Object> parameters) {
parameters_ = parameters;
} // Operator
/**
* Abstract method that must be defined by all the operators. When invoked,
* this method executes the operator represented by the current object.
* @param object This param inherits from Object to allow different kinds
* of parameters for each operator. For example, a selection
* operator typically receives a <code>SolutionSet</code> as
* a parameter, while a mutation operator receives a
* <code>Solution</code>.
* @return An object reference. The returned value depends on the operator.
*/ | abstract public Object execute(Object object) throws JMException ; |
yyxhdy/ManyEAs | src/jmetal/core/Algorithm.java | // Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import jmetal.util.JMException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map; | // Algorithm.java
//
// Authors:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
////
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.core;
/**
* This class implements a generic template for the algorithms developed in
* jMetal. Every algorithm must have a mapping between the parameters and and
* their names, and another mapping between the operators and their names. The
* class declares an abstract method called <code>execute</code>, which defines
* the behavior of the algorithm.
*/
public abstract class Algorithm implements Serializable {
/**
* Stores the problem to solve
*/
protected Problem problem_;
/**
* Stores the operators used by the algorithm, such as selection, crossover,
* etc.
*/
protected Map<String, Operator> operators_ = null;
/**
* Stores algorithm specific parameters. For example, in NSGA-II these
* parameters include the population size and the maximum number of function
* evaluations.
*/
protected Map<String, Object> inputParameters_ = null;
/**
* Stores output parameters, which are retrieved by Main object to obtain
* information from an algorithm.
*/
private Map<String, Object> outPutParameters_ = null;
/**
* Constructor
*
* @param problem
* The problem to be solved
*/
public Algorithm(Problem problem) {
problem_ = problem;
}
/**
* Launches the execution of an specific algorithm.
*
* @return a <code>SolutionSet</code> that is a set of non dominated
* solutions as a result of the algorithm execution
*/ | // Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/core/Algorithm.java
import jmetal.util.JMException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
// Algorithm.java
//
// Authors:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
////
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.core;
/**
* This class implements a generic template for the algorithms developed in
* jMetal. Every algorithm must have a mapping between the parameters and and
* their names, and another mapping between the operators and their names. The
* class declares an abstract method called <code>execute</code>, which defines
* the behavior of the algorithm.
*/
public abstract class Algorithm implements Serializable {
/**
* Stores the problem to solve
*/
protected Problem problem_;
/**
* Stores the operators used by the algorithm, such as selection, crossover,
* etc.
*/
protected Map<String, Operator> operators_ = null;
/**
* Stores algorithm specific parameters. For example, in NSGA-II these
* parameters include the population size and the maximum number of function
* evaluations.
*/
protected Map<String, Object> inputParameters_ = null;
/**
* Stores output parameters, which are retrieved by Main object to obtain
* information from an algorithm.
*/
private Map<String, Object> outPutParameters_ = null;
/**
* Constructor
*
* @param problem
* The problem to be solved
*/
public Algorithm(Problem problem) {
problem_ = problem;
}
/**
* Launches the execution of an specific algorithm.
*
* @return a <code>SolutionSet</code> that is a set of non dominated
* solutions as a result of the algorithm execution
*/ | public abstract SolutionSet execute() throws JMException, |
yyxhdy/ManyEAs | src/jmetal/problems/WFG/Transformations.java | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import jmetal.util.JMException;
import jmetal.util.Configuration; | // Transformations.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.problems.WFG;
/**
* Class implementing the basics transformations for WFG
*/
public class Transformations {
/**
* Stores a default epsilon value
*/
private static final float epsilon = (float)1.0e-10;
/**
* b_poly transformation
* @throws JMException
*/ | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/problems/WFG/Transformations.java
import jmetal.util.JMException;
import jmetal.util.Configuration;
// Transformations.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.problems.WFG;
/**
* Class implementing the basics transformations for WFG
*/
public class Transformations {
/**
* Stores a default epsilon value
*/
private static final float epsilon = (float)1.0e-10;
/**
* b_poly transformation
* @throws JMException
*/ | public float b_poly(float y, float alpha) throws JMException{ |
yyxhdy/ManyEAs | src/jmetal/problems/WFG/Transformations.java | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import jmetal.util.JMException;
import jmetal.util.Configuration; | // Transformations.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.problems.WFG;
/**
* Class implementing the basics transformations for WFG
*/
public class Transformations {
/**
* Stores a default epsilon value
*/
private static final float epsilon = (float)1.0e-10;
/**
* b_poly transformation
* @throws JMException
*/
public float b_poly(float y, float alpha) throws JMException{
if (!(alpha>0)) {
| // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/problems/WFG/Transformations.java
import jmetal.util.JMException;
import jmetal.util.Configuration;
// Transformations.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.problems.WFG;
/**
* Class implementing the basics transformations for WFG
*/
public class Transformations {
/**
* Stores a default epsilon value
*/
private static final float epsilon = (float)1.0e-10;
/**
* b_poly transformation
* @throws JMException
*/
public float b_poly(float y, float alpha) throws JMException{
if (!(alpha>0)) {
| Configuration.logger_.severe("WFG.Transformations.b_poly: Param alpha " + |
yyxhdy/ManyEAs | src/jmetal/core/Variable.java | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import jmetal.util.JMException;
import java.io.Serializable;
import jmetal.util.Configuration; | // SolutionType.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.core;
/**
* This abstract class is the base for defining new types of variables.
* Many methods of <code>Variable</code> (<code>getValue</code>,
* <code>setValue</code>,<code>
* getLowerLimit</code>,<code>setLowerLimit</code>,<code>getUpperLimit</code>,
* <code>setUpperLimit</code>)
* are not applicable to all the subclasses of <code>Variable</code>.
* For this reason, they are defined by default as giving a fatal error.
*/
public abstract class Variable implements Serializable {
/**
* Creates an exact copy of a <code>Variable</code> object.
* @return the copy of the object.
*/
public abstract Variable deepCopy();
/**
* Gets the double value representating the encodings.variable.
* It is used in subclasses of <code>Variable</code> (i.e. <code>Real</code>
* and <code>Int</code>).
* As not all objects belonging to a subclass of <code>Variable</code> have a
* double value, a call to this method it is considered a fatal error by
* default, and the program is terminated. Those classes requiring this method
* must redefine it.
*/ | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/core/Variable.java
import jmetal.util.JMException;
import java.io.Serializable;
import jmetal.util.Configuration;
// SolutionType.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.core;
/**
* This abstract class is the base for defining new types of variables.
* Many methods of <code>Variable</code> (<code>getValue</code>,
* <code>setValue</code>,<code>
* getLowerLimit</code>,<code>setLowerLimit</code>,<code>getUpperLimit</code>,
* <code>setUpperLimit</code>)
* are not applicable to all the subclasses of <code>Variable</code>.
* For this reason, they are defined by default as giving a fatal error.
*/
public abstract class Variable implements Serializable {
/**
* Creates an exact copy of a <code>Variable</code> object.
* @return the copy of the object.
*/
public abstract Variable deepCopy();
/**
* Gets the double value representating the encodings.variable.
* It is used in subclasses of <code>Variable</code> (i.e. <code>Real</code>
* and <code>Int</code>).
* As not all objects belonging to a subclass of <code>Variable</code> have a
* double value, a call to this method it is considered a fatal error by
* default, and the program is terminated. Those classes requiring this method
* must redefine it.
*/ | public double getValue() throws JMException { |
yyxhdy/ManyEAs | src/jmetal/core/Variable.java | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import jmetal.util.JMException;
import java.io.Serializable;
import jmetal.util.Configuration; | // SolutionType.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.core;
/**
* This abstract class is the base for defining new types of variables.
* Many methods of <code>Variable</code> (<code>getValue</code>,
* <code>setValue</code>,<code>
* getLowerLimit</code>,<code>setLowerLimit</code>,<code>getUpperLimit</code>,
* <code>setUpperLimit</code>)
* are not applicable to all the subclasses of <code>Variable</code>.
* For this reason, they are defined by default as giving a fatal error.
*/
public abstract class Variable implements Serializable {
/**
* Creates an exact copy of a <code>Variable</code> object.
* @return the copy of the object.
*/
public abstract Variable deepCopy();
/**
* Gets the double value representating the encodings.variable.
* It is used in subclasses of <code>Variable</code> (i.e. <code>Real</code>
* and <code>Int</code>).
* As not all objects belonging to a subclass of <code>Variable</code> have a
* double value, a call to this method it is considered a fatal error by
* default, and the program is terminated. Those classes requiring this method
* must redefine it.
*/
public double getValue() throws JMException {
Class cls = java.lang.String.class;
String name = cls.getName(); | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/core/Variable.java
import jmetal.util.JMException;
import java.io.Serializable;
import jmetal.util.Configuration;
// SolutionType.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.core;
/**
* This abstract class is the base for defining new types of variables.
* Many methods of <code>Variable</code> (<code>getValue</code>,
* <code>setValue</code>,<code>
* getLowerLimit</code>,<code>setLowerLimit</code>,<code>getUpperLimit</code>,
* <code>setUpperLimit</code>)
* are not applicable to all the subclasses of <code>Variable</code>.
* For this reason, they are defined by default as giving a fatal error.
*/
public abstract class Variable implements Serializable {
/**
* Creates an exact copy of a <code>Variable</code> object.
* @return the copy of the object.
*/
public abstract Variable deepCopy();
/**
* Gets the double value representating the encodings.variable.
* It is used in subclasses of <code>Variable</code> (i.e. <code>Real</code>
* and <code>Int</code>).
* As not all objects belonging to a subclass of <code>Variable</code> have a
* double value, a call to this method it is considered a fatal error by
* default, and the program is terminated. Those classes requiring this method
* must redefine it.
*/
public double getValue() throws JMException {
Class cls = java.lang.String.class;
String name = cls.getName(); | Configuration.logger_.severe("Class " + name + " does not implement " + |
yyxhdy/ManyEAs | src/jmetal/operators/mutation/MutationFactory.java | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import jmetal.util.JMException;
import java.util.HashMap;
import jmetal.util.Configuration; | // MutationFactory.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.operators.mutation;
/**
* Class implementing a factory for Mutation objects.
*/
public class MutationFactory {
/**
* Gets a crossover operator through its name.
*
* @param name
* of the operator
* @return the operator
* @throws JMException
*/
public static Mutation getMutationOperator(String name, HashMap parameters) | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/operators/mutation/MutationFactory.java
import jmetal.util.JMException;
import java.util.HashMap;
import jmetal.util.Configuration;
// MutationFactory.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.operators.mutation;
/**
* Class implementing a factory for Mutation objects.
*/
public class MutationFactory {
/**
* Gets a crossover operator through its name.
*
* @param name
* of the operator
* @return the operator
* @throws JMException
*/
public static Mutation getMutationOperator(String name, HashMap parameters) | throws JMException { |
yyxhdy/ManyEAs | src/jmetal/operators/mutation/MutationFactory.java | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import jmetal.util.JMException;
import java.util.HashMap;
import jmetal.util.Configuration; | // MutationFactory.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.operators.mutation;
/**
* Class implementing a factory for Mutation objects.
*/
public class MutationFactory {
/**
* Gets a crossover operator through its name.
*
* @param name
* of the operator
* @return the operator
* @throws JMException
*/
public static Mutation getMutationOperator(String name, HashMap parameters)
throws JMException {
if (name.equalsIgnoreCase("PolynomialMutation"))
return new PolynomialMutation(parameters);
else if (name.equalsIgnoreCase("BitFlipMutation"))
return new BitFlipMutation(parameters);
else if (name.equalsIgnoreCase("NonUniformMutation"))
return new NonUniformMutation(parameters);
else if (name.equalsIgnoreCase("NonUniformMutation"))
return new NonUniformMutation(parameters);
else if (name.equalsIgnoreCase("UniformMutation"))
return new UniformMutation(parameters);
else { | // Path: src/jmetal/util/Configuration.java
// public class Configuration implements Serializable {
//
// /**
// * Logger object
// */
// public static Logger logger_ = Logger.getLogger("jMetal");
//
// } // Configuration
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/operators/mutation/MutationFactory.java
import jmetal.util.JMException;
import java.util.HashMap;
import jmetal.util.Configuration;
// MutationFactory.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.operators.mutation;
/**
* Class implementing a factory for Mutation objects.
*/
public class MutationFactory {
/**
* Gets a crossover operator through its name.
*
* @param name
* of the operator
* @return the operator
* @throws JMException
*/
public static Mutation getMutationOperator(String name, HashMap parameters)
throws JMException {
if (name.equalsIgnoreCase("PolynomialMutation"))
return new PolynomialMutation(parameters);
else if (name.equalsIgnoreCase("BitFlipMutation"))
return new BitFlipMutation(parameters);
else if (name.equalsIgnoreCase("NonUniformMutation"))
return new NonUniformMutation(parameters);
else if (name.equalsIgnoreCase("NonUniformMutation"))
return new NonUniformMutation(parameters);
else if (name.equalsIgnoreCase("UniformMutation"))
return new UniformMutation(parameters);
else { | Configuration.logger_.severe("Operator '" + name + "' not found "); |
yyxhdy/ManyEAs | src/jmetal/encodings/variable/BinaryReal.java | // Path: src/jmetal/core/Variable.java
// public abstract class Variable implements Serializable {
//
// /**
// * Creates an exact copy of a <code>Variable</code> object.
// * @return the copy of the object.
// */
// public abstract Variable deepCopy();
//
// /**
// * Gets the double value representating the encodings.variable.
// * It is used in subclasses of <code>Variable</code> (i.e. <code>Real</code>
// * and <code>Int</code>).
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public double getValue() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method getValue");
// throw new JMException("Exception in " + name + ".getValue()") ;
// } // getValue
//
// /**
// * Sets a double value to a encodings.variable in subclasses of <code>Variable</code>.
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public void setValue(double value) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method setValue");
// throw new JMException("Exception in " + name + ".setValue()") ;
// } // setValue
//
// /**
// * Gets the lower bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have a lower bound,
// * a call to this method is considered a fatal error by default,
// * and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public double getLowerBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getLowerBound()");
// throw new JMException("Exception in " + name + ".getLowerBound()") ;
// } // getLowerBound
//
// /**
// * Gets the upper bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have an upper
// * bound, a call to this method is considered a fatal error by default, and the
// * program is terminated. Those classes requiring this method must redefine it.
// */
// public double getUpperBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getUpperBound()");
// throw new JMException("Exception in " + name + ".getUpperBound()") ;
// } // getUpperBound
//
// /**
// * Sets the lower bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have a lower bound, a call to this method
// * is considered a fatal error by default and the program is terminated.
// * Those classes requiring this method must to redefine it.
// */
// public void setLowerBound(double lowerBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setLowerBound()");
// throw new JMException("Exception in " + name + ".setLowerBound()") ;
// } // setLowerBound
//
// /**
// * Sets the upper bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have an upper bound, a call to this method
// * is considered a fatal error by default, and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public void setUpperBound(double upperBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setUpperBound()");
// throw new JMException("Exception in " + name + ".setUpperBound()") ;
// } // setUpperBound
//
// /**
// * Gets the type of the encodings.variable. The types are defined in class Problem.
// * @return The type of the encodings.variable
// */
//
// public Class getVariableType() {
// return this.getClass() ;
// } // getVariableType
// } // Variable
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import jmetal.util.JMException;
import java.util.BitSet;
import jmetal.core.Variable; | double value = 0.0;
for (int i = 0; i < numberOfBits_; i++) {
if (bits_.get(i)) {
value += Math.pow(2.0, i);
}
}
value_ = value * (upperBound_ - lowerBound_)
/ (Math.pow(2.0, numberOfBits_) - 1.0);
value_ += lowerBound_;
} // decode
/**
* Returns the double value of the encodings.variable.
*
* @return the double value.
*/
public double getValue() {
return value_;
} // getValue
/**
* This implementation is efficient for binary string of length up to 24
* bits, and for positive intervals.
*
* @see jmetal.core.Variable#setValue(double)
*
* Contributor: jl hippolyte
*/
@Override | // Path: src/jmetal/core/Variable.java
// public abstract class Variable implements Serializable {
//
// /**
// * Creates an exact copy of a <code>Variable</code> object.
// * @return the copy of the object.
// */
// public abstract Variable deepCopy();
//
// /**
// * Gets the double value representating the encodings.variable.
// * It is used in subclasses of <code>Variable</code> (i.e. <code>Real</code>
// * and <code>Int</code>).
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public double getValue() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method getValue");
// throw new JMException("Exception in " + name + ".getValue()") ;
// } // getValue
//
// /**
// * Sets a double value to a encodings.variable in subclasses of <code>Variable</code>.
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public void setValue(double value) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method setValue");
// throw new JMException("Exception in " + name + ".setValue()") ;
// } // setValue
//
// /**
// * Gets the lower bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have a lower bound,
// * a call to this method is considered a fatal error by default,
// * and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public double getLowerBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getLowerBound()");
// throw new JMException("Exception in " + name + ".getLowerBound()") ;
// } // getLowerBound
//
// /**
// * Gets the upper bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have an upper
// * bound, a call to this method is considered a fatal error by default, and the
// * program is terminated. Those classes requiring this method must redefine it.
// */
// public double getUpperBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getUpperBound()");
// throw new JMException("Exception in " + name + ".getUpperBound()") ;
// } // getUpperBound
//
// /**
// * Sets the lower bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have a lower bound, a call to this method
// * is considered a fatal error by default and the program is terminated.
// * Those classes requiring this method must to redefine it.
// */
// public void setLowerBound(double lowerBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setLowerBound()");
// throw new JMException("Exception in " + name + ".setLowerBound()") ;
// } // setLowerBound
//
// /**
// * Sets the upper bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have an upper bound, a call to this method
// * is considered a fatal error by default, and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public void setUpperBound(double upperBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setUpperBound()");
// throw new JMException("Exception in " + name + ".setUpperBound()") ;
// } // setUpperBound
//
// /**
// * Gets the type of the encodings.variable. The types are defined in class Problem.
// * @return The type of the encodings.variable
// */
//
// public Class getVariableType() {
// return this.getClass() ;
// } // getVariableType
// } // Variable
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/encodings/variable/BinaryReal.java
import jmetal.util.JMException;
import java.util.BitSet;
import jmetal.core.Variable;
double value = 0.0;
for (int i = 0; i < numberOfBits_; i++) {
if (bits_.get(i)) {
value += Math.pow(2.0, i);
}
}
value_ = value * (upperBound_ - lowerBound_)
/ (Math.pow(2.0, numberOfBits_) - 1.0);
value_ += lowerBound_;
} // decode
/**
* Returns the double value of the encodings.variable.
*
* @return the double value.
*/
public double getValue() {
return value_;
} // getValue
/**
* This implementation is efficient for binary string of length up to 24
* bits, and for positive intervals.
*
* @see jmetal.core.Variable#setValue(double)
*
* Contributor: jl hippolyte
*/
@Override | public void setValue(double value) throws JMException { |
yyxhdy/ManyEAs | src/jmetal/encodings/variable/BinaryReal.java | // Path: src/jmetal/core/Variable.java
// public abstract class Variable implements Serializable {
//
// /**
// * Creates an exact copy of a <code>Variable</code> object.
// * @return the copy of the object.
// */
// public abstract Variable deepCopy();
//
// /**
// * Gets the double value representating the encodings.variable.
// * It is used in subclasses of <code>Variable</code> (i.e. <code>Real</code>
// * and <code>Int</code>).
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public double getValue() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method getValue");
// throw new JMException("Exception in " + name + ".getValue()") ;
// } // getValue
//
// /**
// * Sets a double value to a encodings.variable in subclasses of <code>Variable</code>.
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public void setValue(double value) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method setValue");
// throw new JMException("Exception in " + name + ".setValue()") ;
// } // setValue
//
// /**
// * Gets the lower bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have a lower bound,
// * a call to this method is considered a fatal error by default,
// * and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public double getLowerBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getLowerBound()");
// throw new JMException("Exception in " + name + ".getLowerBound()") ;
// } // getLowerBound
//
// /**
// * Gets the upper bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have an upper
// * bound, a call to this method is considered a fatal error by default, and the
// * program is terminated. Those classes requiring this method must redefine it.
// */
// public double getUpperBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getUpperBound()");
// throw new JMException("Exception in " + name + ".getUpperBound()") ;
// } // getUpperBound
//
// /**
// * Sets the lower bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have a lower bound, a call to this method
// * is considered a fatal error by default and the program is terminated.
// * Those classes requiring this method must to redefine it.
// */
// public void setLowerBound(double lowerBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setLowerBound()");
// throw new JMException("Exception in " + name + ".setLowerBound()") ;
// } // setLowerBound
//
// /**
// * Sets the upper bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have an upper bound, a call to this method
// * is considered a fatal error by default, and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public void setUpperBound(double upperBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setUpperBound()");
// throw new JMException("Exception in " + name + ".setUpperBound()") ;
// } // setUpperBound
//
// /**
// * Gets the type of the encodings.variable. The types are defined in class Problem.
// * @return The type of the encodings.variable
// */
//
// public Class getVariableType() {
// return this.getClass() ;
// } // getVariableType
// } // Variable
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
| import jmetal.util.JMException;
import java.util.BitSet;
import jmetal.core.Variable; | int ithPowerOf2 = (int) Math.pow(2, i);
if (ithPowerOf2 <= remain) {
// System.out
// .println(ithPowerOf2thValue + " <= " + remain);
bitSet.set(i);
remain -= ithPowerOf2;
} else {
bitSet.clear(i);
}
}
}
this.bits_ = bitSet;
this.decode();
} else {
if (lowerBound_ < 0)
throw new JMException("Unsupported lowerbound: " + lowerBound_
+ " > 0");
if (numberOfBits_ > 30)
throw new JMException("Unsupported bit string length"
+ numberOfBits_ + " is > 30 bits");
}
}// setValue
/**
* Creates an exact copy of a <code>BinaryReal</code> object.
*
* @return The copy of the object
*/ | // Path: src/jmetal/core/Variable.java
// public abstract class Variable implements Serializable {
//
// /**
// * Creates an exact copy of a <code>Variable</code> object.
// * @return the copy of the object.
// */
// public abstract Variable deepCopy();
//
// /**
// * Gets the double value representating the encodings.variable.
// * It is used in subclasses of <code>Variable</code> (i.e. <code>Real</code>
// * and <code>Int</code>).
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public double getValue() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method getValue");
// throw new JMException("Exception in " + name + ".getValue()") ;
// } // getValue
//
// /**
// * Sets a double value to a encodings.variable in subclasses of <code>Variable</code>.
// * As not all objects belonging to a subclass of <code>Variable</code> have a
// * double value, a call to this method it is considered a fatal error by
// * default, and the program is terminated. Those classes requiring this method
// * must redefine it.
// */
// public void setValue(double value) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name + " does not implement " +
// "method setValue");
// throw new JMException("Exception in " + name + ".setValue()") ;
// } // setValue
//
// /**
// * Gets the lower bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have a lower bound,
// * a call to this method is considered a fatal error by default,
// * and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public double getLowerBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getLowerBound()");
// throw new JMException("Exception in " + name + ".getLowerBound()") ;
// } // getLowerBound
//
// /**
// * Gets the upper bound value of a encodings.variable. As not all
// * objects belonging to a subclass of <code>Variable</code> have an upper
// * bound, a call to this method is considered a fatal error by default, and the
// * program is terminated. Those classes requiring this method must redefine it.
// */
// public double getUpperBound() throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method getUpperBound()");
// throw new JMException("Exception in " + name + ".getUpperBound()") ;
// } // getUpperBound
//
// /**
// * Sets the lower bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have a lower bound, a call to this method
// * is considered a fatal error by default and the program is terminated.
// * Those classes requiring this method must to redefine it.
// */
// public void setLowerBound(double lowerBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setLowerBound()");
// throw new JMException("Exception in " + name + ".setLowerBound()") ;
// } // setLowerBound
//
// /**
// * Sets the upper bound for a encodings.variable. As not all objects belonging to a
// * subclass of <code>Variable</code> have an upper bound, a call to this method
// * is considered a fatal error by default, and the program is terminated.
// * Those classes requiring this method must redefine it.
// */
// public void setUpperBound(double upperBound) throws JMException {
// Class cls = java.lang.String.class;
// String name = cls.getName();
// Configuration.logger_.severe("Class " + name +
// " does not implement method setUpperBound()");
// throw new JMException("Exception in " + name + ".setUpperBound()") ;
// } // setUpperBound
//
// /**
// * Gets the type of the encodings.variable. The types are defined in class Problem.
// * @return The type of the encodings.variable
// */
//
// public Class getVariableType() {
// return this.getClass() ;
// } // getVariableType
// } // Variable
//
// Path: src/jmetal/util/JMException.java
// public class JMException extends Exception implements Serializable {
//
// /**
// * Constructor
// * @param Error message
// */
// public JMException (String message){
// super(message);
// } // JmetalException
// }
// Path: src/jmetal/encodings/variable/BinaryReal.java
import jmetal.util.JMException;
import java.util.BitSet;
import jmetal.core.Variable;
int ithPowerOf2 = (int) Math.pow(2, i);
if (ithPowerOf2 <= remain) {
// System.out
// .println(ithPowerOf2thValue + " <= " + remain);
bitSet.set(i);
remain -= ithPowerOf2;
} else {
bitSet.clear(i);
}
}
}
this.bits_ = bitSet;
this.decode();
} else {
if (lowerBound_ < 0)
throw new JMException("Unsupported lowerbound: " + lowerBound_
+ " > 0");
if (numberOfBits_ > 30)
throw new JMException("Unsupported bit string length"
+ numberOfBits_ + " is > 30 bits");
}
}// setValue
/**
* Creates an exact copy of a <code>BinaryReal</code> object.
*
* @return The copy of the object
*/ | public Variable deepCopy() { |
briangormanly/4dflib | src/main/java/com/fdflib/util/FdfSettings.java | // Path: src/main/java/com/fdflib/persistence/database/DatabaseUtil.java
// public class DatabaseUtil {
//
// private static org.slf4j.Logger fdfLog = LoggerFactory.getLogger(JdbcConnection.class);
//
// public enum DatabaseType {
// MYSQL, POSTGRES, ORACLE, MSSQL, HSQL
// }
//
// public enum DatabaseProtocol {
// JDBC_MYSQL, JDBC_POSTGRES, JDBC_HSQL
// }
//
// public enum DatabaseEncoding {
// UTF8
// }
//
// public static String returnDBConnectionString() {
// String protocolString = "";
// String encodingString = "";
// String connection = "";
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_MYSQL) {
// protocolString = "jdbc:mysql://";
//
// if(FdfSettings.DB_ENCODING == DatabaseUtil.DatabaseEncoding.UTF8) {
// if(FdfSettings.USE_SSL == true) {
// encodingString = "?characterEncoding=UTF-8&autoReconnect=true&useSSL=true";
// }
// else {
// encodingString = "?characterEncoding=UTF-8&autoReconnect=true&useSSL=false";
// }
// }
// else {
// if(FdfSettings.USE_SSL == true) {
// encodingString = "?autoReconnect=true&useSSL=true";
// }
// else {
// encodingString = "?autoReconnect=true&useSSL=false";
// }
// }
//
// connection = protocolString + FdfSettings.DB_HOST + "/" + FdfSettings.DB_NAME + encodingString;
// }
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_POSTGRES) {
// protocolString = "jdbc:postgresql://";
//
// if(FdfSettings.DB_ENCODING == DatabaseUtil.DatabaseEncoding.UTF8) {
// encodingString = "?characterEncoding=UTF-8";
// }
//
// connection = protocolString + FdfSettings.DB_HOST + "/" + FdfSettings.DB_NAME.toLowerCase()
// + encodingString;
// }
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_HSQL) {
//
// if(FdfSettings.HSQL_DB_FILE) {
// protocolString = "jdbc:hsqldb:file:" + FdfSettings.HQSL_DB_FILE_LOCATION + FdfSettings.DB_NAME
// + ";sql.syntax_mys=true";
// }
// else {
// protocolString = "jdbc:hsqldb:mem:" + FdfSettings.DB_NAME + ";sql.syntax_mys=true";
// }
//
// connection = protocolString;
// }
//
// fdfLog.debug("Returning DB connection string: {}", connection);
// return connection;
// }
//
// public static String returnDBConnectionStringWithoutDatabase() {
// String protocolString = "";
// String encodingString = "";
// String questionMark = "?";
// String sslString ="";
// String connection = "";
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_MYSQL) {
// protocolString = "jdbc:mysql://";
//
// if(FdfSettings.DB_ENCODING == DatabaseUtil.DatabaseEncoding.UTF8) {
// if(FdfSettings.USE_SSL == true) {
// encodingString = "/?characterEncoding=UTF-8&autoReconnect=true&useSSL=true";
// }
// else {
// encodingString = "/?characterEncoding=UTF-8&autoReconnect=true&useSSL=false";
// }
// }
// else {
// if(FdfSettings.USE_SSL == true) {
// encodingString = "/?autoReconnect=true&useSSL=true";
// }
// else {
// encodingString = "/?autoReconnect=true&useSSL=false";
// }
// }
//
// connection = protocolString + FdfSettings.DB_HOST + encodingString;
// }
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_POSTGRES) {
// protocolString = "jdbc:postgresql://";
//
// if(FdfSettings.DB_ENCODING == DatabaseUtil.DatabaseEncoding.UTF8) {
// encodingString = "/?characterEncoding=UTF-8";
// }
//
// connection = protocolString + FdfSettings.DB_HOST + encodingString;
// }
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_HSQL) {
// if(FdfSettings.HSQL_DB_FILE) {
// protocolString = "jdbc:hsqldb:file:" + FdfSettings.HQSL_DB_FILE_LOCATION + FdfSettings.DB_NAME
// + ";sql.syntax_mys=true";
// }
// else {
// protocolString = "jdbc:hsqldb:mem:" + FdfSettings.DB_NAME + ";sql.syntax_mys=true";
// }
//
// connection = protocolString;
// }
//
// fdfLog.debug("Returning DB connection string: {}", connection);
// return connection;
// }
// }
| import com.fdflib.persistence.database.DatabaseUtil;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadFactory; | /**
* 4DFLib
* Copyright (c) 2015-2016 Brian Gormanly
* 4dflib.com
*
* 4DFLib is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.fdflib.util;
/**
* Created by brian.gormanly on 5/19/15.
*/
public class FdfSettings {
private static final FdfSettings INSTANCE = new FdfSettings();
static Logger fdfLog = LoggerFactory.getLogger(FdfSettings.class);
public List<Class> modelClasses = new ArrayList<>(); | // Path: src/main/java/com/fdflib/persistence/database/DatabaseUtil.java
// public class DatabaseUtil {
//
// private static org.slf4j.Logger fdfLog = LoggerFactory.getLogger(JdbcConnection.class);
//
// public enum DatabaseType {
// MYSQL, POSTGRES, ORACLE, MSSQL, HSQL
// }
//
// public enum DatabaseProtocol {
// JDBC_MYSQL, JDBC_POSTGRES, JDBC_HSQL
// }
//
// public enum DatabaseEncoding {
// UTF8
// }
//
// public static String returnDBConnectionString() {
// String protocolString = "";
// String encodingString = "";
// String connection = "";
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_MYSQL) {
// protocolString = "jdbc:mysql://";
//
// if(FdfSettings.DB_ENCODING == DatabaseUtil.DatabaseEncoding.UTF8) {
// if(FdfSettings.USE_SSL == true) {
// encodingString = "?characterEncoding=UTF-8&autoReconnect=true&useSSL=true";
// }
// else {
// encodingString = "?characterEncoding=UTF-8&autoReconnect=true&useSSL=false";
// }
// }
// else {
// if(FdfSettings.USE_SSL == true) {
// encodingString = "?autoReconnect=true&useSSL=true";
// }
// else {
// encodingString = "?autoReconnect=true&useSSL=false";
// }
// }
//
// connection = protocolString + FdfSettings.DB_HOST + "/" + FdfSettings.DB_NAME + encodingString;
// }
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_POSTGRES) {
// protocolString = "jdbc:postgresql://";
//
// if(FdfSettings.DB_ENCODING == DatabaseUtil.DatabaseEncoding.UTF8) {
// encodingString = "?characterEncoding=UTF-8";
// }
//
// connection = protocolString + FdfSettings.DB_HOST + "/" + FdfSettings.DB_NAME.toLowerCase()
// + encodingString;
// }
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_HSQL) {
//
// if(FdfSettings.HSQL_DB_FILE) {
// protocolString = "jdbc:hsqldb:file:" + FdfSettings.HQSL_DB_FILE_LOCATION + FdfSettings.DB_NAME
// + ";sql.syntax_mys=true";
// }
// else {
// protocolString = "jdbc:hsqldb:mem:" + FdfSettings.DB_NAME + ";sql.syntax_mys=true";
// }
//
// connection = protocolString;
// }
//
// fdfLog.debug("Returning DB connection string: {}", connection);
// return connection;
// }
//
// public static String returnDBConnectionStringWithoutDatabase() {
// String protocolString = "";
// String encodingString = "";
// String questionMark = "?";
// String sslString ="";
// String connection = "";
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_MYSQL) {
// protocolString = "jdbc:mysql://";
//
// if(FdfSettings.DB_ENCODING == DatabaseUtil.DatabaseEncoding.UTF8) {
// if(FdfSettings.USE_SSL == true) {
// encodingString = "/?characterEncoding=UTF-8&autoReconnect=true&useSSL=true";
// }
// else {
// encodingString = "/?characterEncoding=UTF-8&autoReconnect=true&useSSL=false";
// }
// }
// else {
// if(FdfSettings.USE_SSL == true) {
// encodingString = "/?autoReconnect=true&useSSL=true";
// }
// else {
// encodingString = "/?autoReconnect=true&useSSL=false";
// }
// }
//
// connection = protocolString + FdfSettings.DB_HOST + encodingString;
// }
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_POSTGRES) {
// protocolString = "jdbc:postgresql://";
//
// if(FdfSettings.DB_ENCODING == DatabaseUtil.DatabaseEncoding.UTF8) {
// encodingString = "/?characterEncoding=UTF-8";
// }
//
// connection = protocolString + FdfSettings.DB_HOST + encodingString;
// }
//
// if(FdfSettings.DB_PROTOCOL == DatabaseUtil.DatabaseProtocol.JDBC_HSQL) {
// if(FdfSettings.HSQL_DB_FILE) {
// protocolString = "jdbc:hsqldb:file:" + FdfSettings.HQSL_DB_FILE_LOCATION + FdfSettings.DB_NAME
// + ";sql.syntax_mys=true";
// }
// else {
// protocolString = "jdbc:hsqldb:mem:" + FdfSettings.DB_NAME + ";sql.syntax_mys=true";
// }
//
// connection = protocolString;
// }
//
// fdfLog.debug("Returning DB connection string: {}", connection);
// return connection;
// }
// }
// Path: src/main/java/com/fdflib/util/FdfSettings.java
import com.fdflib.persistence.database.DatabaseUtil;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadFactory;
/**
* 4DFLib
* Copyright (c) 2015-2016 Brian Gormanly
* 4dflib.com
*
* 4DFLib is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.fdflib.util;
/**
* Created by brian.gormanly on 5/19/15.
*/
public class FdfSettings {
private static final FdfSettings INSTANCE = new FdfSettings();
static Logger fdfLog = LoggerFactory.getLogger(FdfSettings.class);
public List<Class> modelClasses = new ArrayList<>(); | public static DatabaseUtil.DatabaseType PERSISTENCE = DatabaseUtil.DatabaseType.HSQL; |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/SearchTemplate.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/SearchOperations.java
// public interface SearchOperations {
//
// /**
// * Search among messages, users, tags and groups for the given string
// * @param searchString
// * @return search results potentially containing messages, users, tags and groups as well as stats
// */
// SearchResults search(String searchString);
//
// /**
// * Search among messages, users, tags and groups for the given string
// * @param searchString
// * @param page the page number in the search result (max 50 results per page)
// * @return search results potentially containing messages, users, tags and groups as well as stats
// */
// SearchResults search(String searchString, int page);
//
// /**
// * Search among messages, users, tags and groups for the given string
// * @param searchString
// * @param page the page number in the search result
// * @param numberPerPage number of results per page (max 50)
// * @return search results potentially containing messages, users, tags and groups as well as stats
// */
// SearchResults search(String searchString, int page, int numberPerPage);
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/SearchResults.java
// public class SearchResults {
//
// private MessageInfo messages;
// private List<YammerProfile> users;
// private List<Group> groups;
// private SearchStats stats;
// private List<Topic> topics;
//
// public SearchResults(MessageInfo messages, List<YammerProfile> users, List<Group> groups, SearchStats searchStats, List<Topic> topics) {
// this.messages = messages;
// this.users = users;
// this.groups = groups;
// this.stats=searchStats;
// this.topics=topics;
// }
//
// public MessageInfo getMessages() {
// return messages;
// }
//
// public List<YammerProfile> getUsers() {
// return users;
// }
//
// public List<Group> getGroups() {
// return groups;
// }
//
// public List<Topic> getTopics() {
// return topics;
// }
//
// public int getUserCount(){
// return stats.userCount;
// }
// public int getGroupCount(){
// return stats.groupCount;
// }
// public int getMessageCount(){
// return stats.messageCount;
// }
// public int getTopicCount(){
// return stats.topicCount;
// }
//
//
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("SearchResults [messages=").append(messages).append(", users=").append(users)
// .append(", groups=").append(groups).append(", stats=").append(stats).append(", topics=").append(topics)
// .append("]");
// return builder.toString();
// }
//
//
//
// public static class SearchStats{
// private int groupCount;
// private int messageCount;
// private int topicCount;
// private int userCount;
// public SearchStats(int groupCount, int messageCount, int topicCount, int userCount) {
// this.groupCount = groupCount;
// this.messageCount = messageCount;
// this.topicCount = topicCount;
// this.userCount = userCount;
// }
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("SearchStats [groupCount=").append(groupCount).append(", messageCount=")
// .append(messageCount).append(", topicCount=").append(topicCount).append(", userCount=")
// .append(userCount).append("]");
// return builder.toString();
// }
//
// }
//
//
// }
| import org.springframework.social.yammer.api.SearchOperations;
import org.springframework.social.yammer.api.SearchResults;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class SearchTemplate extends AbstractYammerOperations implements SearchOperations {
private RestTemplate restTemplate;
public SearchTemplate(RestTemplate restTemplate) {
this.restTemplate=restTemplate;
}
| // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/SearchOperations.java
// public interface SearchOperations {
//
// /**
// * Search among messages, users, tags and groups for the given string
// * @param searchString
// * @return search results potentially containing messages, users, tags and groups as well as stats
// */
// SearchResults search(String searchString);
//
// /**
// * Search among messages, users, tags and groups for the given string
// * @param searchString
// * @param page the page number in the search result (max 50 results per page)
// * @return search results potentially containing messages, users, tags and groups as well as stats
// */
// SearchResults search(String searchString, int page);
//
// /**
// * Search among messages, users, tags and groups for the given string
// * @param searchString
// * @param page the page number in the search result
// * @param numberPerPage number of results per page (max 50)
// * @return search results potentially containing messages, users, tags and groups as well as stats
// */
// SearchResults search(String searchString, int page, int numberPerPage);
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/SearchResults.java
// public class SearchResults {
//
// private MessageInfo messages;
// private List<YammerProfile> users;
// private List<Group> groups;
// private SearchStats stats;
// private List<Topic> topics;
//
// public SearchResults(MessageInfo messages, List<YammerProfile> users, List<Group> groups, SearchStats searchStats, List<Topic> topics) {
// this.messages = messages;
// this.users = users;
// this.groups = groups;
// this.stats=searchStats;
// this.topics=topics;
// }
//
// public MessageInfo getMessages() {
// return messages;
// }
//
// public List<YammerProfile> getUsers() {
// return users;
// }
//
// public List<Group> getGroups() {
// return groups;
// }
//
// public List<Topic> getTopics() {
// return topics;
// }
//
// public int getUserCount(){
// return stats.userCount;
// }
// public int getGroupCount(){
// return stats.groupCount;
// }
// public int getMessageCount(){
// return stats.messageCount;
// }
// public int getTopicCount(){
// return stats.topicCount;
// }
//
//
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("SearchResults [messages=").append(messages).append(", users=").append(users)
// .append(", groups=").append(groups).append(", stats=").append(stats).append(", topics=").append(topics)
// .append("]");
// return builder.toString();
// }
//
//
//
// public static class SearchStats{
// private int groupCount;
// private int messageCount;
// private int topicCount;
// private int userCount;
// public SearchStats(int groupCount, int messageCount, int topicCount, int userCount) {
// this.groupCount = groupCount;
// this.messageCount = messageCount;
// this.topicCount = topicCount;
// this.userCount = userCount;
// }
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("SearchStats [groupCount=").append(groupCount).append(", messageCount=")
// .append(messageCount).append(", topicCount=").append(topicCount).append(", userCount=")
// .append(userCount).append("]");
// return builder.toString();
// }
//
// }
//
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/SearchTemplate.java
import org.springframework.social.yammer.api.SearchOperations;
import org.springframework.social.yammer.api.SearchResults;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class SearchTemplate extends AbstractYammerOperations implements SearchOperations {
private RestTemplate restTemplate;
public SearchTemplate(RestTemplate restTemplate) {
this.restTemplate=restTemplate;
}
| public SearchResults search(String searchString){ |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/GroupMixin.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Group.java
// public static class GroupStats{
// private final int updates;
// private final int members;
// private final Date lastMessageAt;
// private final long lastMessageId;
//
// public GroupStats(int updates, int members, Date lastMessageAt, long lastMessageId) {
// this.updates = updates;
// this.members = members;
// this.lastMessageAt = lastMessageAt;
// this.lastMessageId = lastMessageId;
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerDateDeserializer.java
// public class YammerDateDeserializer extends JsonDeserializer<Date> {
//
// //Example format: 2011/03/03 21:12:57 +0000
// public static final String DATE_FORMAT_MASK = "yyy/MM/dd HH:mm:ss Z";
// public static final Locale LOCALE = Locale.ENGLISH;
//
//
// @Override
// public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
// try {
// return createDateFormatter().parse(jp.getText());
// } catch (ParseException e) {
// return null;
// }
// }
//
// SimpleDateFormat createDateFormatter(){
// return new SimpleDateFormat(DATE_FORMAT_MASK, LOCALE);
// }
//
// }
| import java.util.Date;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.yammer.api.Group.GroupStats;
import org.springframework.social.yammer.api.impl.YammerDateDeserializer; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class GroupMixin {
@JsonCreator
GroupMixin(
@JsonProperty("privacy")String privacy,
@JsonProperty("web_url")String webUrl, | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Group.java
// public static class GroupStats{
// private final int updates;
// private final int members;
// private final Date lastMessageAt;
// private final long lastMessageId;
//
// public GroupStats(int updates, int members, Date lastMessageAt, long lastMessageId) {
// this.updates = updates;
// this.members = members;
// this.lastMessageAt = lastMessageAt;
// this.lastMessageId = lastMessageId;
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerDateDeserializer.java
// public class YammerDateDeserializer extends JsonDeserializer<Date> {
//
// //Example format: 2011/03/03 21:12:57 +0000
// public static final String DATE_FORMAT_MASK = "yyy/MM/dd HH:mm:ss Z";
// public static final Locale LOCALE = Locale.ENGLISH;
//
//
// @Override
// public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
// try {
// return createDateFormatter().parse(jp.getText());
// } catch (ParseException e) {
// return null;
// }
// }
//
// SimpleDateFormat createDateFormatter(){
// return new SimpleDateFormat(DATE_FORMAT_MASK, LOCALE);
// }
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/GroupMixin.java
import java.util.Date;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.yammer.api.Group.GroupStats;
import org.springframework.social.yammer.api.impl.YammerDateDeserializer;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class GroupMixin {
@JsonCreator
GroupMixin(
@JsonProperty("privacy")String privacy,
@JsonProperty("web_url")String webUrl, | @JsonProperty("stats") GroupStats stats, |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/GroupMixin.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Group.java
// public static class GroupStats{
// private final int updates;
// private final int members;
// private final Date lastMessageAt;
// private final long lastMessageId;
//
// public GroupStats(int updates, int members, Date lastMessageAt, long lastMessageId) {
// this.updates = updates;
// this.members = members;
// this.lastMessageAt = lastMessageAt;
// this.lastMessageId = lastMessageId;
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerDateDeserializer.java
// public class YammerDateDeserializer extends JsonDeserializer<Date> {
//
// //Example format: 2011/03/03 21:12:57 +0000
// public static final String DATE_FORMAT_MASK = "yyy/MM/dd HH:mm:ss Z";
// public static final Locale LOCALE = Locale.ENGLISH;
//
//
// @Override
// public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
// try {
// return createDateFormatter().parse(jp.getText());
// } catch (ParseException e) {
// return null;
// }
// }
//
// SimpleDateFormat createDateFormatter(){
// return new SimpleDateFormat(DATE_FORMAT_MASK, LOCALE);
// }
//
// }
| import java.util.Date;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.yammer.api.Group.GroupStats;
import org.springframework.social.yammer.api.impl.YammerDateDeserializer; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class GroupMixin {
@JsonCreator
GroupMixin(
@JsonProperty("privacy")String privacy,
@JsonProperty("web_url")String webUrl,
@JsonProperty("stats") GroupStats stats,
@JsonProperty("mugshot_url")String mugshotUrl,
@JsonProperty("url") String url,
@JsonProperty("description")String description,
@JsonProperty("full_name") String fullName,
@JsonProperty("name") String name,
@JsonProperty("id") long id, | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Group.java
// public static class GroupStats{
// private final int updates;
// private final int members;
// private final Date lastMessageAt;
// private final long lastMessageId;
//
// public GroupStats(int updates, int members, Date lastMessageAt, long lastMessageId) {
// this.updates = updates;
// this.members = members;
// this.lastMessageAt = lastMessageAt;
// this.lastMessageId = lastMessageId;
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerDateDeserializer.java
// public class YammerDateDeserializer extends JsonDeserializer<Date> {
//
// //Example format: 2011/03/03 21:12:57 +0000
// public static final String DATE_FORMAT_MASK = "yyy/MM/dd HH:mm:ss Z";
// public static final Locale LOCALE = Locale.ENGLISH;
//
//
// @Override
// public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
// try {
// return createDateFormatter().parse(jp.getText());
// } catch (ParseException e) {
// return null;
// }
// }
//
// SimpleDateFormat createDateFormatter(){
// return new SimpleDateFormat(DATE_FORMAT_MASK, LOCALE);
// }
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/GroupMixin.java
import java.util.Date;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.yammer.api.Group.GroupStats;
import org.springframework.social.yammer.api.impl.YammerDateDeserializer;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class GroupMixin {
@JsonCreator
GroupMixin(
@JsonProperty("privacy")String privacy,
@JsonProperty("web_url")String webUrl,
@JsonProperty("stats") GroupStats stats,
@JsonProperty("mugshot_url")String mugshotUrl,
@JsonProperty("url") String url,
@JsonProperty("description")String description,
@JsonProperty("full_name") String fullName,
@JsonProperty("name") String name,
@JsonProperty("id") long id, | @JsonProperty("created_at") @JsonDeserialize(using=YammerDateDeserializer.class) Date createdAt |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/YammerThreadMixin.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public class Topic {
//
// private String type;
// private String webUrl;
// private String normalizedName;
// private List<TopicExpert> experts;
// private String name;
// private long id;
//
// public Topic(String type, String webUrl, String normalizedName, List<TopicExpert> experts, String name, long id) {
// this.type = type;
// this.webUrl = webUrl;
// this.normalizedName = normalizedName;
// this.experts = experts;
// this.name = name;
// this.id = id;
// }
//
// public String getType() {
// return type;
// }
//
// public String getWebUrl() {
// return webUrl;
// }
//
// public String getNormalizedName() {
// return normalizedName;
// }
//
// public List<TopicExpert> getExperts() {
// return experts;
// }
//
// public String getName() {
// return name;
// }
//
// public long getId() {
// return id;
// }
//
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerDateDeserializer.java
// public class YammerDateDeserializer extends JsonDeserializer<Date> {
//
// //Example format: 2011/03/03 21:12:57 +0000
// public static final String DATE_FORMAT_MASK = "yyy/MM/dd HH:mm:ss Z";
// public static final Locale LOCALE = Locale.ENGLISH;
//
//
// @Override
// public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
// try {
// return createDateFormatter().parse(jp.getText());
// } catch (ParseException e) {
// return null;
// }
// }
//
// SimpleDateFormat createDateFormatter(){
// return new SimpleDateFormat(DATE_FORMAT_MASK, LOCALE);
// }
//
// }
| import java.util.Date;
import java.util.List;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.yammer.api.Topic;
import org.springframework.social.yammer.api.YammerThread.ThreadStats;
import org.springframework.social.yammer.api.impl.YammerDateDeserializer; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class YammerThreadMixin {
@JsonCreator
public YammerThreadMixin( | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public class Topic {
//
// private String type;
// private String webUrl;
// private String normalizedName;
// private List<TopicExpert> experts;
// private String name;
// private long id;
//
// public Topic(String type, String webUrl, String normalizedName, List<TopicExpert> experts, String name, long id) {
// this.type = type;
// this.webUrl = webUrl;
// this.normalizedName = normalizedName;
// this.experts = experts;
// this.name = name;
// this.id = id;
// }
//
// public String getType() {
// return type;
// }
//
// public String getWebUrl() {
// return webUrl;
// }
//
// public String getNormalizedName() {
// return normalizedName;
// }
//
// public List<TopicExpert> getExperts() {
// return experts;
// }
//
// public String getName() {
// return name;
// }
//
// public long getId() {
// return id;
// }
//
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerDateDeserializer.java
// public class YammerDateDeserializer extends JsonDeserializer<Date> {
//
// //Example format: 2011/03/03 21:12:57 +0000
// public static final String DATE_FORMAT_MASK = "yyy/MM/dd HH:mm:ss Z";
// public static final Locale LOCALE = Locale.ENGLISH;
//
//
// @Override
// public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
// try {
// return createDateFormatter().parse(jp.getText());
// } catch (ParseException e) {
// return null;
// }
// }
//
// SimpleDateFormat createDateFormatter(){
// return new SimpleDateFormat(DATE_FORMAT_MASK, LOCALE);
// }
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/YammerThreadMixin.java
import java.util.Date;
import java.util.List;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.yammer.api.Topic;
import org.springframework.social.yammer.api.YammerThread.ThreadStats;
import org.springframework.social.yammer.api.impl.YammerDateDeserializer;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class YammerThreadMixin {
@JsonCreator
public YammerThreadMixin( | @JsonProperty("stats") ThreadStats stats, |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/YammerThreadMixin.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public class Topic {
//
// private String type;
// private String webUrl;
// private String normalizedName;
// private List<TopicExpert> experts;
// private String name;
// private long id;
//
// public Topic(String type, String webUrl, String normalizedName, List<TopicExpert> experts, String name, long id) {
// this.type = type;
// this.webUrl = webUrl;
// this.normalizedName = normalizedName;
// this.experts = experts;
// this.name = name;
// this.id = id;
// }
//
// public String getType() {
// return type;
// }
//
// public String getWebUrl() {
// return webUrl;
// }
//
// public String getNormalizedName() {
// return normalizedName;
// }
//
// public List<TopicExpert> getExperts() {
// return experts;
// }
//
// public String getName() {
// return name;
// }
//
// public long getId() {
// return id;
// }
//
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerDateDeserializer.java
// public class YammerDateDeserializer extends JsonDeserializer<Date> {
//
// //Example format: 2011/03/03 21:12:57 +0000
// public static final String DATE_FORMAT_MASK = "yyy/MM/dd HH:mm:ss Z";
// public static final Locale LOCALE = Locale.ENGLISH;
//
//
// @Override
// public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
// try {
// return createDateFormatter().parse(jp.getText());
// } catch (ParseException e) {
// return null;
// }
// }
//
// SimpleDateFormat createDateFormatter(){
// return new SimpleDateFormat(DATE_FORMAT_MASK, LOCALE);
// }
//
// }
| import java.util.Date;
import java.util.List;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.yammer.api.Topic;
import org.springframework.social.yammer.api.YammerThread.ThreadStats;
import org.springframework.social.yammer.api.impl.YammerDateDeserializer; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class YammerThreadMixin {
@JsonCreator
public YammerThreadMixin(
@JsonProperty("stats") ThreadStats stats,
@JsonProperty("type") String type,
@JsonProperty("privacy") String privacy,
@JsonProperty("thread_starter_id") long threadStarterId,
@JsonProperty("has_attachments") boolean hasAttachments,
@JsonProperty("web_url") String webUrl,
@JsonProperty("id") long id,
@JsonProperty("direct_message") boolean directMessage, | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public class Topic {
//
// private String type;
// private String webUrl;
// private String normalizedName;
// private List<TopicExpert> experts;
// private String name;
// private long id;
//
// public Topic(String type, String webUrl, String normalizedName, List<TopicExpert> experts, String name, long id) {
// this.type = type;
// this.webUrl = webUrl;
// this.normalizedName = normalizedName;
// this.experts = experts;
// this.name = name;
// this.id = id;
// }
//
// public String getType() {
// return type;
// }
//
// public String getWebUrl() {
// return webUrl;
// }
//
// public String getNormalizedName() {
// return normalizedName;
// }
//
// public List<TopicExpert> getExperts() {
// return experts;
// }
//
// public String getName() {
// return name;
// }
//
// public long getId() {
// return id;
// }
//
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerDateDeserializer.java
// public class YammerDateDeserializer extends JsonDeserializer<Date> {
//
// //Example format: 2011/03/03 21:12:57 +0000
// public static final String DATE_FORMAT_MASK = "yyy/MM/dd HH:mm:ss Z";
// public static final Locale LOCALE = Locale.ENGLISH;
//
//
// @Override
// public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
// try {
// return createDateFormatter().parse(jp.getText());
// } catch (ParseException e) {
// return null;
// }
// }
//
// SimpleDateFormat createDateFormatter(){
// return new SimpleDateFormat(DATE_FORMAT_MASK, LOCALE);
// }
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/YammerThreadMixin.java
import java.util.Date;
import java.util.List;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.yammer.api.Topic;
import org.springframework.social.yammer.api.YammerThread.ThreadStats;
import org.springframework.social.yammer.api.impl.YammerDateDeserializer;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class YammerThreadMixin {
@JsonCreator
public YammerThreadMixin(
@JsonProperty("stats") ThreadStats stats,
@JsonProperty("type") String type,
@JsonProperty("privacy") String privacy,
@JsonProperty("thread_starter_id") long threadStarterId,
@JsonProperty("has_attachments") boolean hasAttachments,
@JsonProperty("web_url") String webUrl,
@JsonProperty("id") long id,
@JsonProperty("direct_message") boolean directMessage, | @JsonProperty("topics") List<Topic> topics |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/YammerThreadMixin.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public class Topic {
//
// private String type;
// private String webUrl;
// private String normalizedName;
// private List<TopicExpert> experts;
// private String name;
// private long id;
//
// public Topic(String type, String webUrl, String normalizedName, List<TopicExpert> experts, String name, long id) {
// this.type = type;
// this.webUrl = webUrl;
// this.normalizedName = normalizedName;
// this.experts = experts;
// this.name = name;
// this.id = id;
// }
//
// public String getType() {
// return type;
// }
//
// public String getWebUrl() {
// return webUrl;
// }
//
// public String getNormalizedName() {
// return normalizedName;
// }
//
// public List<TopicExpert> getExperts() {
// return experts;
// }
//
// public String getName() {
// return name;
// }
//
// public long getId() {
// return id;
// }
//
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerDateDeserializer.java
// public class YammerDateDeserializer extends JsonDeserializer<Date> {
//
// //Example format: 2011/03/03 21:12:57 +0000
// public static final String DATE_FORMAT_MASK = "yyy/MM/dd HH:mm:ss Z";
// public static final Locale LOCALE = Locale.ENGLISH;
//
//
// @Override
// public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
// try {
// return createDateFormatter().parse(jp.getText());
// } catch (ParseException e) {
// return null;
// }
// }
//
// SimpleDateFormat createDateFormatter(){
// return new SimpleDateFormat(DATE_FORMAT_MASK, LOCALE);
// }
//
// }
| import java.util.Date;
import java.util.List;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.yammer.api.Topic;
import org.springframework.social.yammer.api.YammerThread.ThreadStats;
import org.springframework.social.yammer.api.impl.YammerDateDeserializer; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class YammerThreadMixin {
@JsonCreator
public YammerThreadMixin(
@JsonProperty("stats") ThreadStats stats,
@JsonProperty("type") String type,
@JsonProperty("privacy") String privacy,
@JsonProperty("thread_starter_id") long threadStarterId,
@JsonProperty("has_attachments") boolean hasAttachments,
@JsonProperty("web_url") String webUrl,
@JsonProperty("id") long id,
@JsonProperty("direct_message") boolean directMessage,
@JsonProperty("topics") List<Topic> topics
) { }
@JsonIgnoreProperties(ignoreUnknown=true)
abstract static class YammerThreadStatsMixin{
@JsonCreator
public YammerThreadStatsMixin( | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public class Topic {
//
// private String type;
// private String webUrl;
// private String normalizedName;
// private List<TopicExpert> experts;
// private String name;
// private long id;
//
// public Topic(String type, String webUrl, String normalizedName, List<TopicExpert> experts, String name, long id) {
// this.type = type;
// this.webUrl = webUrl;
// this.normalizedName = normalizedName;
// this.experts = experts;
// this.name = name;
// this.id = id;
// }
//
// public String getType() {
// return type;
// }
//
// public String getWebUrl() {
// return webUrl;
// }
//
// public String getNormalizedName() {
// return normalizedName;
// }
//
// public List<TopicExpert> getExperts() {
// return experts;
// }
//
// public String getName() {
// return name;
// }
//
// public long getId() {
// return id;
// }
//
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerDateDeserializer.java
// public class YammerDateDeserializer extends JsonDeserializer<Date> {
//
// //Example format: 2011/03/03 21:12:57 +0000
// public static final String DATE_FORMAT_MASK = "yyy/MM/dd HH:mm:ss Z";
// public static final Locale LOCALE = Locale.ENGLISH;
//
//
// @Override
// public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
// try {
// return createDateFormatter().parse(jp.getText());
// } catch (ParseException e) {
// return null;
// }
// }
//
// SimpleDateFormat createDateFormatter(){
// return new SimpleDateFormat(DATE_FORMAT_MASK, LOCALE);
// }
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/YammerThreadMixin.java
import java.util.Date;
import java.util.List;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.springframework.social.yammer.api.Topic;
import org.springframework.social.yammer.api.YammerThread.ThreadStats;
import org.springframework.social.yammer.api.impl.YammerDateDeserializer;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class YammerThreadMixin {
@JsonCreator
public YammerThreadMixin(
@JsonProperty("stats") ThreadStats stats,
@JsonProperty("type") String type,
@JsonProperty("privacy") String privacy,
@JsonProperty("thread_starter_id") long threadStarterId,
@JsonProperty("has_attachments") boolean hasAttachments,
@JsonProperty("web_url") String webUrl,
@JsonProperty("id") long id,
@JsonProperty("direct_message") boolean directMessage,
@JsonProperty("topics") List<Topic> topics
) { }
@JsonIgnoreProperties(ignoreUnknown=true)
abstract static class YammerThreadStatsMixin{
@JsonCreator
public YammerThreadStatsMixin( | @JsonProperty("first_reply_at") @JsonDeserialize(using=YammerDateDeserializer.class) Date firstReplyAt, |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/TopicMixin.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
| import java.util.List;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.social.yammer.api.Topic.TopicExpert; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class TopicMixin {
@JsonCreator
public TopicMixin(
@JsonProperty("type") String type,
@JsonProperty("web_url") String webUrl,
@JsonProperty("normalized_name") String normalizedName, | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/TopicMixin.java
import java.util.List;
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.social.yammer.api.Topic.TopicExpert;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
/**
* @author Morten Andersen-Gott
*
*/
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class TopicMixin {
@JsonCreator
public TopicMixin(
@JsonProperty("type") String type,
@JsonProperty("web_url") String webUrl,
@JsonProperty("normalized_name") String normalizedName, | @JsonProperty("experts") List<TopicExpert> experts, |
magott/spring-social-yammer | spring-social-yammer/src/test/java/org/springframework/social/yammer/api/impl/SearchTemplateTest.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/SearchResults.java
// public class SearchResults {
//
// private MessageInfo messages;
// private List<YammerProfile> users;
// private List<Group> groups;
// private SearchStats stats;
// private List<Topic> topics;
//
// public SearchResults(MessageInfo messages, List<YammerProfile> users, List<Group> groups, SearchStats searchStats, List<Topic> topics) {
// this.messages = messages;
// this.users = users;
// this.groups = groups;
// this.stats=searchStats;
// this.topics=topics;
// }
//
// public MessageInfo getMessages() {
// return messages;
// }
//
// public List<YammerProfile> getUsers() {
// return users;
// }
//
// public List<Group> getGroups() {
// return groups;
// }
//
// public List<Topic> getTopics() {
// return topics;
// }
//
// public int getUserCount(){
// return stats.userCount;
// }
// public int getGroupCount(){
// return stats.groupCount;
// }
// public int getMessageCount(){
// return stats.messageCount;
// }
// public int getTopicCount(){
// return stats.topicCount;
// }
//
//
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("SearchResults [messages=").append(messages).append(", users=").append(users)
// .append(", groups=").append(groups).append(", stats=").append(stats).append(", topics=").append(topics)
// .append("]");
// return builder.toString();
// }
//
//
//
// public static class SearchStats{
// private int groupCount;
// private int messageCount;
// private int topicCount;
// private int userCount;
// public SearchStats(int groupCount, int messageCount, int topicCount, int userCount) {
// this.groupCount = groupCount;
// this.messageCount = messageCount;
// this.topicCount = topicCount;
// this.userCount = userCount;
// }
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("SearchStats [groupCount=").append(groupCount).append(", messageCount=")
// .append(messageCount).append(", topicCount=").append(topicCount).append(", userCount=")
// .append(userCount).append("]");
// return builder.toString();
// }
//
// }
//
//
// }
| import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.client.match.RequestMatchers.method;
import static org.springframework.test.web.client.match.RequestMatchers.requestTo;
import static org.springframework.test.web.client.response.ResponseCreators.withResponse;
import static org.springframework.test.web.client.response.ResponseCreators.withSuccess;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.social.yammer.api.SearchResults; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class SearchTemplateTest extends AbstractYammerApiTest {
@Test
public void testSearchWithSearchStringOnly(){
mockServer.expect(requestTo("https://www.yammer.com/api/v1/search.json?search=foo&page=1&number_per_page=20")).andExpect(method(GET))
.andRespond(withSuccess(jsonResource("testdata/yammer-search-results"), APPLICATION_JSON)); | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/SearchResults.java
// public class SearchResults {
//
// private MessageInfo messages;
// private List<YammerProfile> users;
// private List<Group> groups;
// private SearchStats stats;
// private List<Topic> topics;
//
// public SearchResults(MessageInfo messages, List<YammerProfile> users, List<Group> groups, SearchStats searchStats, List<Topic> topics) {
// this.messages = messages;
// this.users = users;
// this.groups = groups;
// this.stats=searchStats;
// this.topics=topics;
// }
//
// public MessageInfo getMessages() {
// return messages;
// }
//
// public List<YammerProfile> getUsers() {
// return users;
// }
//
// public List<Group> getGroups() {
// return groups;
// }
//
// public List<Topic> getTopics() {
// return topics;
// }
//
// public int getUserCount(){
// return stats.userCount;
// }
// public int getGroupCount(){
// return stats.groupCount;
// }
// public int getMessageCount(){
// return stats.messageCount;
// }
// public int getTopicCount(){
// return stats.topicCount;
// }
//
//
//
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("SearchResults [messages=").append(messages).append(", users=").append(users)
// .append(", groups=").append(groups).append(", stats=").append(stats).append(", topics=").append(topics)
// .append("]");
// return builder.toString();
// }
//
//
//
// public static class SearchStats{
// private int groupCount;
// private int messageCount;
// private int topicCount;
// private int userCount;
// public SearchStats(int groupCount, int messageCount, int topicCount, int userCount) {
// this.groupCount = groupCount;
// this.messageCount = messageCount;
// this.topicCount = topicCount;
// this.userCount = userCount;
// }
// @Override
// public String toString() {
// StringBuilder builder = new StringBuilder();
// builder.append("SearchStats [groupCount=").append(groupCount).append(", messageCount=")
// .append(messageCount).append(", topicCount=").append(topicCount).append(", userCount=")
// .append(userCount).append("]");
// return builder.toString();
// }
//
// }
//
//
// }
// Path: spring-social-yammer/src/test/java/org/springframework/social/yammer/api/impl/SearchTemplateTest.java
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.client.match.RequestMatchers.method;
import static org.springframework.test.web.client.match.RequestMatchers.requestTo;
import static org.springframework.test.web.client.response.ResponseCreators.withResponse;
import static org.springframework.test.web.client.response.ResponseCreators.withSuccess;
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.social.yammer.api.SearchResults;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class SearchTemplateTest extends AbstractYammerApiTest {
@Test
public void testSearchWithSearchStringOnly(){
mockServer.expect(requestTo("https://www.yammer.com/api/v1/search.json?search=foo&page=1&number_per_page=20")).andExpect(method(GET))
.andRespond(withSuccess(jsonResource("testdata/yammer-search-results"), APPLICATION_JSON)); | SearchResults searchResults = yammerTemplate.searchOperations().search("foo"); |
magott/spring-social-yammer | spring-social-yammer/src/test/java/org/springframework/social/yammer/api/impl/ThreadTemplateTest.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public class YammerThread {
//
// private ThreadStats stats;
// private String type;
// private String privacy;
// private long threadStarterId;
// private boolean hasAttachements;
// private String webUrl;
// private long id;
// private boolean directMessage;
// private List<Topic> topics;
//
// public YammerThread(
// ThreadStats stats, String type, String privacy, long threadStarterId, boolean hasAttachements,
// String webUrl, long id, boolean directMessage, List<Topic> topics) {
// this.stats = stats;
// this.type = type;
// this.privacy = privacy;
// this.threadStarterId = threadStarterId;
// this.hasAttachements = hasAttachements;
// this.webUrl = webUrl;
// this.id = id;
// this.directMessage = directMessage;
// this.topics = topics;
// }
//
//
// public long getFirstReplyId(){
// return stats.firstReplyId;
// }
//
// public Date getFirstReplyDate(){
// return stats.firstReplyAt;
// }
//
// public long getLatestReplyId(){
// return stats.latestReplyId;
// }
//
// public Date getLatestReplyDate(){
// return stats.latestReplyAt;
// }
//
// public int getMessageCount(){
// return stats.messageCount;
// }
//
// public String getType() {
// return type;
// }
//
// public String getPrivacy() {
// return privacy;
// }
//
// public long getThreadStarterId() {
// return threadStarterId;
// }
//
// public boolean hasAttachements() {
// return hasAttachements;
// }
//
//
// public String getWebUrl() {
// return webUrl;
// }
//
//
// public long getId() {
// return id;
// }
//
//
// public boolean isDirectMessage() {
// return directMessage;
// }
//
// public List<Topic> getTopics() {
// return topics;
// }
//
//
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
//
// }
| import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.social.yammer.api.YammerThread;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.test.web.client.match.RequestMatchers.method;
import static org.springframework.test.web.client.match.RequestMatchers.requestTo;
import static org.springframework.test.web.client.response.ResponseCreators.withSuccess; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class ThreadTemplateTest extends AbstractYammerApiTest {
@Test
public void testGetThread(){
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
mockServer.expect(requestTo("https://www.yammer.com/api/v1/threads/123.json")).andExpect(method(GET))
.andRespond(withSuccess(jsonResource("testdata/yammer-thread"), MediaType.APPLICATION_JSON)); | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public class YammerThread {
//
// private ThreadStats stats;
// private String type;
// private String privacy;
// private long threadStarterId;
// private boolean hasAttachements;
// private String webUrl;
// private long id;
// private boolean directMessage;
// private List<Topic> topics;
//
// public YammerThread(
// ThreadStats stats, String type, String privacy, long threadStarterId, boolean hasAttachements,
// String webUrl, long id, boolean directMessage, List<Topic> topics) {
// this.stats = stats;
// this.type = type;
// this.privacy = privacy;
// this.threadStarterId = threadStarterId;
// this.hasAttachements = hasAttachements;
// this.webUrl = webUrl;
// this.id = id;
// this.directMessage = directMessage;
// this.topics = topics;
// }
//
//
// public long getFirstReplyId(){
// return stats.firstReplyId;
// }
//
// public Date getFirstReplyDate(){
// return stats.firstReplyAt;
// }
//
// public long getLatestReplyId(){
// return stats.latestReplyId;
// }
//
// public Date getLatestReplyDate(){
// return stats.latestReplyAt;
// }
//
// public int getMessageCount(){
// return stats.messageCount;
// }
//
// public String getType() {
// return type;
// }
//
// public String getPrivacy() {
// return privacy;
// }
//
// public long getThreadStarterId() {
// return threadStarterId;
// }
//
// public boolean hasAttachements() {
// return hasAttachements;
// }
//
//
// public String getWebUrl() {
// return webUrl;
// }
//
//
// public long getId() {
// return id;
// }
//
//
// public boolean isDirectMessage() {
// return directMessage;
// }
//
// public List<Topic> getTopics() {
// return topics;
// }
//
//
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
//
// }
// Path: spring-social-yammer/src/test/java/org/springframework/social/yammer/api/impl/ThreadTemplateTest.java
import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.social.yammer.api.YammerThread;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.test.web.client.match.RequestMatchers.method;
import static org.springframework.test.web.client.match.RequestMatchers.requestTo;
import static org.springframework.test.web.client.response.ResponseCreators.withSuccess;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class ThreadTemplateTest extends AbstractYammerApiTest {
@Test
public void testGetThread(){
responseHeaders.setContentType(MediaType.APPLICATION_JSON);
mockServer.expect(requestTo("https://www.yammer.com/api/v1/threads/123.json")).andExpect(method(GET))
.andRespond(withSuccess(jsonResource("testdata/yammer-thread"), MediaType.APPLICATION_JSON)); | YammerThread thread = yammerTemplate.threadOperations().getThread(123L); |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/connect/YammerServiceProvider.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Yammer.java
// public interface Yammer{
//
// /**
// * Returns the portion of the API containing the Thread operations
// */
// ThreadOperations threadOperations();
//
// /**
// * Returns the portion of the API containing the Subscription (follow) operations
// */
// SubscriptionOperations subscriptionOperations();
//
// /**
// * Returns the portion of the API containing the Topic (tags) operations
// */
// TopicOperations topicOperations();
//
// /**
// * Returns the portion of the API containing the Search operations
// */
// SearchOperations searchOperations();
//
// /**
// * Returns the portion of the API containing the Group operations
// */
// GroupOperations groupOperations();
//
// /**
// * Returns the portion of the API containing the Message operations
// */
// MessageOperations messageOperations();
//
// /**
// * Returns the portion of the API containing the User operations
// */
// UserOperations userOperations();
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerTemplate.java
// public class YammerTemplate extends AbstractOAuth2ApiBinding implements Yammer{
//
// private UserOperations userOperations;
// private MessageOperations messageOperations;
// private GroupOperations groupOperations;
// private SearchOperations searchOperations;
// private TopicOperations topicOperations;
// private SubscriptionOperations subscriptionOperations;
// private ThreadOperations threadOperations;
//
// public YammerTemplate(String accessToken) {
// super(accessToken);
// initSubApis();
// registerYammerJsonModule();
// }
//
// public UserOperations userOperations(){
// return userOperations;
// }
//
// public MessageOperations messageOperations(){
// return messageOperations;
// }
//
// public GroupOperations groupOperations(){
// return groupOperations;
// }
//
// public SearchOperations searchOperations(){
// return searchOperations;
// }
//
// public TopicOperations topicOperations(){
// return topicOperations;
// }
//
// public SubscriptionOperations subscriptionOperations(){
// return subscriptionOperations;
// }
//
// public ThreadOperations threadOperations(){
// return threadOperations;
// }
//
// @Override
// protected void configureRestTemplate(RestTemplate restTemplate) {
// restTemplate.setErrorHandler(new YammerErrorHandler());
// }
//
// private void initSubApis() {
// userOperations = new UserTemplate(getRestTemplate());
// messageOperations = new MessageTemplate(getRestTemplate());
// groupOperations = new GroupTemplate(getRestTemplate());
// searchOperations = new SearchTemplate(getRestTemplate());
// topicOperations = new TopicTemplate(getRestTemplate());
// subscriptionOperations = new SubscriptionTemplate(getRestTemplate());
// threadOperations = new ThreadTemplate(getRestTemplate());
// }
//
// private void registerYammerJsonModule() {
// List<HttpMessageConverter<?>> converters = getRestTemplate().getMessageConverters();
// for (HttpMessageConverter<?> converter : converters) {
// if(converter instanceof MappingJacksonHttpMessageConverter) {
// MappingJacksonHttpMessageConverter jsonConverter = (MappingJacksonHttpMessageConverter) converter;
// ObjectMapper objectMapper = new ObjectMapper();
// objectMapper.registerModule(new YammerModule());
// jsonConverter.setObjectMapper(objectMapper);
// }
// }
// }
// }
| import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;
import org.springframework.social.yammer.api.Yammer;
import org.springframework.social.yammer.api.impl.YammerTemplate; | /*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.connect;
public class YammerServiceProvider extends AbstractOAuth2ServiceProvider<Yammer> {
public YammerServiceProvider(String clientId, String clientSecret) {
super(new YammerOAuth2Template(clientId, clientSecret));
}
public Yammer getApi(String accessToken) { | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Yammer.java
// public interface Yammer{
//
// /**
// * Returns the portion of the API containing the Thread operations
// */
// ThreadOperations threadOperations();
//
// /**
// * Returns the portion of the API containing the Subscription (follow) operations
// */
// SubscriptionOperations subscriptionOperations();
//
// /**
// * Returns the portion of the API containing the Topic (tags) operations
// */
// TopicOperations topicOperations();
//
// /**
// * Returns the portion of the API containing the Search operations
// */
// SearchOperations searchOperations();
//
// /**
// * Returns the portion of the API containing the Group operations
// */
// GroupOperations groupOperations();
//
// /**
// * Returns the portion of the API containing the Message operations
// */
// MessageOperations messageOperations();
//
// /**
// * Returns the portion of the API containing the User operations
// */
// UserOperations userOperations();
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/YammerTemplate.java
// public class YammerTemplate extends AbstractOAuth2ApiBinding implements Yammer{
//
// private UserOperations userOperations;
// private MessageOperations messageOperations;
// private GroupOperations groupOperations;
// private SearchOperations searchOperations;
// private TopicOperations topicOperations;
// private SubscriptionOperations subscriptionOperations;
// private ThreadOperations threadOperations;
//
// public YammerTemplate(String accessToken) {
// super(accessToken);
// initSubApis();
// registerYammerJsonModule();
// }
//
// public UserOperations userOperations(){
// return userOperations;
// }
//
// public MessageOperations messageOperations(){
// return messageOperations;
// }
//
// public GroupOperations groupOperations(){
// return groupOperations;
// }
//
// public SearchOperations searchOperations(){
// return searchOperations;
// }
//
// public TopicOperations topicOperations(){
// return topicOperations;
// }
//
// public SubscriptionOperations subscriptionOperations(){
// return subscriptionOperations;
// }
//
// public ThreadOperations threadOperations(){
// return threadOperations;
// }
//
// @Override
// protected void configureRestTemplate(RestTemplate restTemplate) {
// restTemplate.setErrorHandler(new YammerErrorHandler());
// }
//
// private void initSubApis() {
// userOperations = new UserTemplate(getRestTemplate());
// messageOperations = new MessageTemplate(getRestTemplate());
// groupOperations = new GroupTemplate(getRestTemplate());
// searchOperations = new SearchTemplate(getRestTemplate());
// topicOperations = new TopicTemplate(getRestTemplate());
// subscriptionOperations = new SubscriptionTemplate(getRestTemplate());
// threadOperations = new ThreadTemplate(getRestTemplate());
// }
//
// private void registerYammerJsonModule() {
// List<HttpMessageConverter<?>> converters = getRestTemplate().getMessageConverters();
// for (HttpMessageConverter<?> converter : converters) {
// if(converter instanceof MappingJacksonHttpMessageConverter) {
// MappingJacksonHttpMessageConverter jsonConverter = (MappingJacksonHttpMessageConverter) converter;
// ObjectMapper objectMapper = new ObjectMapper();
// objectMapper.registerModule(new YammerModule());
// jsonConverter.setObjectMapper(objectMapper);
// }
// }
// }
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/connect/YammerServiceProvider.java
import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;
import org.springframework.social.yammer.api.Yammer;
import org.springframework.social.yammer.api.impl.YammerTemplate;
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.connect;
public class YammerServiceProvider extends AbstractOAuth2ServiceProvider<Yammer> {
public YammerServiceProvider(String clientId, String clientSecret) {
super(new YammerOAuth2Template(clientId, clientSecret));
}
public Yammer getApi(String accessToken) { | return new YammerTemplate(accessToken); |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/ThreadReference.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
| import org.springframework.social.yammer.api.YammerThread.ThreadStats; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api;
public class ThreadReference extends YammerReference{
private long threadStarterId; | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/ThreadReference.java
import org.springframework.social.yammer.api.YammerThread.ThreadStats;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api;
public class ThreadReference extends YammerReference{
private long threadStarterId; | private ThreadStats stats; |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/ThreadReferenceMixin.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
| import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.social.yammer.api.YammerThread.ThreadStats; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class ThreadReferenceMixin {
@JsonCreator
public ThreadReferenceMixin(
@JsonProperty("id") long id,
@JsonProperty("url")String url,
@JsonProperty("web_url")String webUrl
) { }
@JsonProperty("thread_starter_id")
long threadStarterId;
@JsonProperty("stats") | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/json/ThreadReferenceMixin.java
import org.codehaus.jackson.annotate.JsonCreator;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import org.springframework.social.yammer.api.YammerThread.ThreadStats;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl.json;
@JsonIgnoreProperties(ignoreUnknown=true)
abstract class ThreadReferenceMixin {
@JsonCreator
public ThreadReferenceMixin(
@JsonProperty("id") long id,
@JsonProperty("url")String url,
@JsonProperty("web_url")String webUrl
) { }
@JsonProperty("thread_starter_id")
long threadStarterId;
@JsonProperty("stats") | ThreadStats stats; |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/ThreadTemplate.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/ThreadOperations.java
// public interface ThreadOperations {
//
// /**
// * Get information about a thread
// * @param id the thread id
// * @return {@link YammerThread}
// */
// YammerThread getThread(long id);
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public class YammerThread {
//
// private ThreadStats stats;
// private String type;
// private String privacy;
// private long threadStarterId;
// private boolean hasAttachements;
// private String webUrl;
// private long id;
// private boolean directMessage;
// private List<Topic> topics;
//
// public YammerThread(
// ThreadStats stats, String type, String privacy, long threadStarterId, boolean hasAttachements,
// String webUrl, long id, boolean directMessage, List<Topic> topics) {
// this.stats = stats;
// this.type = type;
// this.privacy = privacy;
// this.threadStarterId = threadStarterId;
// this.hasAttachements = hasAttachements;
// this.webUrl = webUrl;
// this.id = id;
// this.directMessage = directMessage;
// this.topics = topics;
// }
//
//
// public long getFirstReplyId(){
// return stats.firstReplyId;
// }
//
// public Date getFirstReplyDate(){
// return stats.firstReplyAt;
// }
//
// public long getLatestReplyId(){
// return stats.latestReplyId;
// }
//
// public Date getLatestReplyDate(){
// return stats.latestReplyAt;
// }
//
// public int getMessageCount(){
// return stats.messageCount;
// }
//
// public String getType() {
// return type;
// }
//
// public String getPrivacy() {
// return privacy;
// }
//
// public long getThreadStarterId() {
// return threadStarterId;
// }
//
// public boolean hasAttachements() {
// return hasAttachements;
// }
//
//
// public String getWebUrl() {
// return webUrl;
// }
//
//
// public long getId() {
// return id;
// }
//
//
// public boolean isDirectMessage() {
// return directMessage;
// }
//
// public List<Topic> getTopics() {
// return topics;
// }
//
//
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
//
// }
| import org.springframework.social.yammer.api.ThreadOperations;
import org.springframework.social.yammer.api.YammerThread;
import org.springframework.web.client.RestTemplate; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class ThreadTemplate extends AbstractYammerOperations implements ThreadOperations {
private RestTemplate restTemplate;
public ThreadTemplate(RestTemplate restTemplate){
this.restTemplate = restTemplate;
}
| // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/ThreadOperations.java
// public interface ThreadOperations {
//
// /**
// * Get information about a thread
// * @param id the thread id
// * @return {@link YammerThread}
// */
// YammerThread getThread(long id);
//
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/YammerThread.java
// public class YammerThread {
//
// private ThreadStats stats;
// private String type;
// private String privacy;
// private long threadStarterId;
// private boolean hasAttachements;
// private String webUrl;
// private long id;
// private boolean directMessage;
// private List<Topic> topics;
//
// public YammerThread(
// ThreadStats stats, String type, String privacy, long threadStarterId, boolean hasAttachements,
// String webUrl, long id, boolean directMessage, List<Topic> topics) {
// this.stats = stats;
// this.type = type;
// this.privacy = privacy;
// this.threadStarterId = threadStarterId;
// this.hasAttachements = hasAttachements;
// this.webUrl = webUrl;
// this.id = id;
// this.directMessage = directMessage;
// this.topics = topics;
// }
//
//
// public long getFirstReplyId(){
// return stats.firstReplyId;
// }
//
// public Date getFirstReplyDate(){
// return stats.firstReplyAt;
// }
//
// public long getLatestReplyId(){
// return stats.latestReplyId;
// }
//
// public Date getLatestReplyDate(){
// return stats.latestReplyAt;
// }
//
// public int getMessageCount(){
// return stats.messageCount;
// }
//
// public String getType() {
// return type;
// }
//
// public String getPrivacy() {
// return privacy;
// }
//
// public long getThreadStarterId() {
// return threadStarterId;
// }
//
// public boolean hasAttachements() {
// return hasAttachements;
// }
//
//
// public String getWebUrl() {
// return webUrl;
// }
//
//
// public long getId() {
// return id;
// }
//
//
// public boolean isDirectMessage() {
// return directMessage;
// }
//
// public List<Topic> getTopics() {
// return topics;
// }
//
//
// public static class ThreadStats{
// private Date firstReplyAt;
// private Date latestReplyAt;
// private long firstReplyId;
// private long latestReplyId;
// private int messageCount;
// private int shares;
//
//
// public ThreadStats(Date firstReplyAt, Date latestReplyAt, long firstReplyId, long latestReplyId,
// int messageCount, int shares) {
// this.firstReplyAt = firstReplyAt;
// this.latestReplyAt = latestReplyAt;
// this.firstReplyId = firstReplyId;
// this.latestReplyId = latestReplyId;
// this.messageCount = messageCount;
// this.shares=shares;
// }
//
//
// @Override
// public String toString() {
// return "ThreadStats [firstReplyAt=" + firstReplyAt + ", latestReplyAt=" + latestReplyAt + ", firstReplyId=" + firstReplyId
// + ", latestReplyId=" + latestReplyId + ", messageCount=" + messageCount + ", shares=" + shares + "]";
// }
//
//
//
// }
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/ThreadTemplate.java
import org.springframework.social.yammer.api.ThreadOperations;
import org.springframework.social.yammer.api.YammerThread;
import org.springframework.web.client.RestTemplate;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class ThreadTemplate extends AbstractYammerOperations implements ThreadOperations {
private RestTemplate restTemplate;
public ThreadTemplate(RestTemplate restTemplate){
this.restTemplate = restTemplate;
}
| public YammerThread getThread(long id) { |
magott/spring-social-yammer | spring-social-yammer/src/test/java/org/springframework/social/yammer/api/impl/TopicTemplateTest.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public class Topic {
//
// private String type;
// private String webUrl;
// private String normalizedName;
// private List<TopicExpert> experts;
// private String name;
// private long id;
//
// public Topic(String type, String webUrl, String normalizedName, List<TopicExpert> experts, String name, long id) {
// this.type = type;
// this.webUrl = webUrl;
// this.normalizedName = normalizedName;
// this.experts = experts;
// this.name = name;
// this.id = id;
// }
//
// public String getType() {
// return type;
// }
//
// public String getWebUrl() {
// return webUrl;
// }
//
// public String getNormalizedName() {
// return normalizedName;
// }
//
// public List<TopicExpert> getExperts() {
// return experts;
// }
//
// public String getName() {
// return name;
// }
//
// public long getId() {
// return id;
// }
//
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// }
| import org.junit.Test;
import org.springframework.social.yammer.api.Topic;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.client.match.RequestMatchers.method;
import static org.springframework.test.web.client.match.RequestMatchers.requestTo;
import static org.springframework.test.web.client.response.ResponseCreators.withSuccess; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class TopicTemplateTest extends AbstractYammerApiTest{
@Test
public void testGetTopic(){
mockServer.expect(requestTo("https://www.yammer.com/api/v1/topics/123.json")).andExpect(method(GET))
.andRespond(withSuccess(jsonResource("testdata/yammer-topic"), APPLICATION_JSON));
| // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public class Topic {
//
// private String type;
// private String webUrl;
// private String normalizedName;
// private List<TopicExpert> experts;
// private String name;
// private long id;
//
// public Topic(String type, String webUrl, String normalizedName, List<TopicExpert> experts, String name, long id) {
// this.type = type;
// this.webUrl = webUrl;
// this.normalizedName = normalizedName;
// this.experts = experts;
// this.name = name;
// this.id = id;
// }
//
// public String getType() {
// return type;
// }
//
// public String getWebUrl() {
// return webUrl;
// }
//
// public String getNormalizedName() {
// return normalizedName;
// }
//
// public List<TopicExpert> getExperts() {
// return experts;
// }
//
// public String getName() {
// return name;
// }
//
// public long getId() {
// return id;
// }
//
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// }
// Path: spring-social-yammer/src/test/java/org/springframework/social/yammer/api/impl/TopicTemplateTest.java
import org.junit.Test;
import org.springframework.social.yammer.api.Topic;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.client.match.RequestMatchers.method;
import static org.springframework.test.web.client.match.RequestMatchers.requestTo;
import static org.springframework.test.web.client.response.ResponseCreators.withSuccess;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class TopicTemplateTest extends AbstractYammerApiTest{
@Test
public void testGetTopic(){
mockServer.expect(requestTo("https://www.yammer.com/api/v1/topics/123.json")).andExpect(method(GET))
.andRespond(withSuccess(jsonResource("testdata/yammer-topic"), APPLICATION_JSON));
| Topic topic = yammerTemplate.topicOperations().getTopic(123L); |
magott/spring-social-yammer | spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/TopicTemplate.java | // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public class Topic {
//
// private String type;
// private String webUrl;
// private String normalizedName;
// private List<TopicExpert> experts;
// private String name;
// private long id;
//
// public Topic(String type, String webUrl, String normalizedName, List<TopicExpert> experts, String name, long id) {
// this.type = type;
// this.webUrl = webUrl;
// this.normalizedName = normalizedName;
// this.experts = experts;
// this.name = name;
// this.id = id;
// }
//
// public String getType() {
// return type;
// }
//
// public String getWebUrl() {
// return webUrl;
// }
//
// public String getNormalizedName() {
// return normalizedName;
// }
//
// public List<TopicExpert> getExperts() {
// return experts;
// }
//
// public String getName() {
// return name;
// }
//
// public long getId() {
// return id;
// }
//
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/TopicOperations.java
// public interface TopicOperations {
//
// /**
// * Get information about a topic
// * @param id topic id
// * @return {@link Topic}
// */
// Topic getTopic(long id);
//
// }
| import org.springframework.social.yammer.api.Topic;
import org.springframework.social.yammer.api.TopicOperations;
import org.springframework.web.client.RestTemplate; | /*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class TopicTemplate extends AbstractYammerOperations implements TopicOperations {
private RestTemplate restTemplate;
public TopicTemplate(RestTemplate restTemplate){
this.restTemplate = restTemplate;
}
| // Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/Topic.java
// public class Topic {
//
// private String type;
// private String webUrl;
// private String normalizedName;
// private List<TopicExpert> experts;
// private String name;
// private long id;
//
// public Topic(String type, String webUrl, String normalizedName, List<TopicExpert> experts, String name, long id) {
// this.type = type;
// this.webUrl = webUrl;
// this.normalizedName = normalizedName;
// this.experts = experts;
// this.name = name;
// this.id = id;
// }
//
// public String getType() {
// return type;
// }
//
// public String getWebUrl() {
// return webUrl;
// }
//
// public String getNormalizedName() {
// return normalizedName;
// }
//
// public List<TopicExpert> getExperts() {
// return experts;
// }
//
// public String getName() {
// return name;
// }
//
// public long getId() {
// return id;
// }
//
// public static class TopicExpert {
// private String type;
// private long id;
//
// public TopicExpert(String type, long id) {
// this.type = type;
// this.id = id;
// }
// public String getType() {
// return type;
// }
// public long getId() {
// return id;
// }
//
// }
// }
//
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/TopicOperations.java
// public interface TopicOperations {
//
// /**
// * Get information about a topic
// * @param id topic id
// * @return {@link Topic}
// */
// Topic getTopic(long id);
//
// }
// Path: spring-social-yammer/src/main/java/org/springframework/social/yammer/api/impl/TopicTemplate.java
import org.springframework.social.yammer.api.Topic;
import org.springframework.social.yammer.api.TopicOperations;
import org.springframework.web.client.RestTemplate;
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.yammer.api.impl;
/**
* @author Morten Andersen-Gott
*
*/
public class TopicTemplate extends AbstractYammerOperations implements TopicOperations {
private RestTemplate restTemplate;
public TopicTemplate(RestTemplate restTemplate){
this.restTemplate = restTemplate;
}
| public Topic getTopic(long id) { |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/ClientLibraryDecoderTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
| import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import com.google.cloud.ByteArray;
import com.google.cloud.Date;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.Struct;
import com.google.cloud.spanner.Type;
import com.google.cloud.spanner.Value;
import com.google.cloud.spanner.r2dbc.ConversionFailureException;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
/**
* Test for {@link ClientLibraryDecoder}.
*/
class ClientLibraryDecoderTest {
/**
* Prepare parameters for parametrized test.
*/
static Stream<Arguments> decodingWithConversion() {
return Stream.of(
arguments(Integer.class, 12345L, (Function<Object, Value>) (o) -> Value.int64((Long) o),
12345, null),
arguments(Integer.class, Integer.MAX_VALUE + 1L,
(Function<Object, Value>) (o) -> Value.int64((Long) o), null, | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/ClientLibraryDecoderTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import com.google.cloud.ByteArray;
import com.google.cloud.Date;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.Struct;
import com.google.cloud.spanner.Type;
import com.google.cloud.spanner.Value;
import com.google.cloud.spanner.r2dbc.ConversionFailureException;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
/**
* Test for {@link ClientLibraryDecoder}.
*/
class ClientLibraryDecoderTest {
/**
* Prepare parameters for parametrized test.
*/
static Stream<Arguments> decodingWithConversion() {
return Stream.of(
arguments(Integer.class, 12345L, (Function<Object, Value>) (o) -> Value.int64((Long) o),
12345, null),
arguments(Integer.class, Integer.MAX_VALUE + 1L,
(Function<Object, Value>) (o) -> Value.int64((Long) o), null, | new ConversionFailureException("2147483648 is out of range for Integer")), |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerClientLibraryTestKit.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import static io.r2dbc.spi.test.TestKit.TestStatement.INSERT_TWO_COLUMNS;
import static io.r2dbc.spi.test.TestKit.TestStatement.SELECT_VALUE_TWO_COLUMNS;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.DatabaseAdminClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Statement;
import io.r2dbc.spi.test.TestKit;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcOperations;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
/**
* R2DBC TCK test implementation.
*/
@Disabled ("Until missing SPI v0.9 functionality is implemented")
public class SpannerClientLibraryTestKit implements TestKit<String> {
private static final String DISABLE_UNSUPPORTED_FUNCTIONALITY =
"Functionality not supported in Cloud Spanner";
private static final ConnectionFactory connectionFactory =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId()) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerClientLibraryTestKit.java
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import static io.r2dbc.spi.test.TestKit.TestStatement.INSERT_TWO_COLUMNS;
import static io.r2dbc.spi.test.TestKit.TestStatement.SELECT_VALUE_TWO_COLUMNS;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.DatabaseAdminClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Statement;
import io.r2dbc.spi.test.TestKit;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcOperations;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
/**
* R2DBC TCK test implementation.
*/
@Disabled ("Until missing SPI v0.9 functionality is implemented")
public class SpannerClientLibraryTestKit implements TestKit<String> {
private static final String DISABLE_UNSUPPORTED_FUNCTIONALITY =
"Functionality not supported in Cloud Spanner";
private static final ConnectionFactory connectionFactory =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId()) | .option(DRIVER, DRIVER_NAME) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerClientLibraryTestKit.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import static io.r2dbc.spi.test.TestKit.TestStatement.INSERT_TWO_COLUMNS;
import static io.r2dbc.spi.test.TestKit.TestStatement.SELECT_VALUE_TWO_COLUMNS;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.DatabaseAdminClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Statement;
import io.r2dbc.spi.test.TestKit;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcOperations;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
/**
* R2DBC TCK test implementation.
*/
@Disabled ("Until missing SPI v0.9 functionality is implemented")
public class SpannerClientLibraryTestKit implements TestKit<String> {
private static final String DISABLE_UNSUPPORTED_FUNCTIONALITY =
"Functionality not supported in Cloud Spanner";
private static final ConnectionFactory connectionFactory =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerClientLibraryTestKit.java
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import static io.r2dbc.spi.test.TestKit.TestStatement.INSERT_TWO_COLUMNS;
import static io.r2dbc.spi.test.TestKit.TestStatement.SELECT_VALUE_TWO_COLUMNS;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.DatabaseAdminClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.Spanner;
import com.google.cloud.spanner.SpannerOptions;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Statement;
import io.r2dbc.spi.test.TestKit;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcOperations;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
/**
* R2DBC TCK test implementation.
*/
@Disabled ("Until missing SPI v0.9 functionality is implemented")
public class SpannerClientLibraryTestKit implements TestKit<String> {
private static final String DISABLE_UNSUPPORTED_FUNCTIONALITY =
"Functionality not supported in Cloud Spanner";
private static final ConnectionFactory connectionFactory =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | .option(INSTANCE, DatabaseProperties.INSTANCE) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-spring-data-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/springdata/SpannerR2dbcDialectProvider.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryMetadata.java
// public class SpannerConnectionFactoryMetadata implements ConnectionFactoryMetadata {
//
// /**
// * The name of Cloud Spanner database product.
// */
// public static final String NAME = "Cloud Spanner";
//
// public static final SpannerConnectionFactoryMetadata INSTANCE
// = new SpannerConnectionFactoryMetadata();
//
// private SpannerConnectionFactoryMetadata() {
// }
//
// @Override
// public String getName() {
// return NAME;
// }
//
// }
| import com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryMetadata;
import io.r2dbc.spi.ConnectionFactory;
import java.util.Optional;
import org.springframework.data.r2dbc.dialect.DialectResolver.R2dbcDialectProvider;
import org.springframework.data.r2dbc.dialect.R2dbcDialect; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.springdata;
/**
* Provides the {@link SpannerR2dbcDialect} for Spring Data.
*/
public class SpannerR2dbcDialectProvider implements R2dbcDialectProvider {
@Override
public Optional<R2dbcDialect> getDialect(ConnectionFactory connectionFactory) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryMetadata.java
// public class SpannerConnectionFactoryMetadata implements ConnectionFactoryMetadata {
//
// /**
// * The name of Cloud Spanner database product.
// */
// public static final String NAME = "Cloud Spanner";
//
// public static final SpannerConnectionFactoryMetadata INSTANCE
// = new SpannerConnectionFactoryMetadata();
//
// private SpannerConnectionFactoryMetadata() {
// }
//
// @Override
// public String getName() {
// return NAME;
// }
//
// }
// Path: cloud-spanner-spring-data-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/springdata/SpannerR2dbcDialectProvider.java
import com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryMetadata;
import io.r2dbc.spi.ConnectionFactory;
import java.util.Optional;
import org.springframework.data.r2dbc.dialect.DialectResolver.R2dbcDialectProvider;
import org.springframework.data.r2dbc.dialect.R2dbcDialect;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.springdata;
/**
* Provides the {@link SpannerR2dbcDialect} for Spring Data.
*/
public class SpannerR2dbcDialectProvider implements R2dbcDialectProvider {
@Override
public Optional<R2dbcDialect> getDialect(ConnectionFactory connectionFactory) { | if (connectionFactory.getMetadata().getName().equals(SpannerConnectionFactoryMetadata.NAME)) { |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/util/SpannerExceptionUtilTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/SpannerExceptionUtil.java
// public static R2dbcException createR2dbcException(int errorCode, String message) {
// return createR2dbcException(errorCode, message, null);
// }
| import io.r2dbc.spi.R2dbcTransientResourceException;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import static com.google.cloud.spanner.r2dbc.util.SpannerExceptionUtil.createR2dbcException;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.protobuf.Duration;
import com.google.rpc.Code;
import com.google.rpc.RetryInfo;
import io.grpc.Metadata;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.protobuf.ProtoUtils;
import io.r2dbc.spi.R2dbcDataIntegrityViolationException;
import io.r2dbc.spi.R2dbcException;
import io.r2dbc.spi.R2dbcNonTransientResourceException;
import io.r2dbc.spi.R2dbcPermissionDeniedException; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.util;
class SpannerExceptionUtilTest {
@Test
void testCreateR2dbcException() { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/SpannerExceptionUtil.java
// public static R2dbcException createR2dbcException(int errorCode, String message) {
// return createR2dbcException(errorCode, message, null);
// }
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/util/SpannerExceptionUtilTest.java
import io.r2dbc.spi.R2dbcTransientResourceException;
import java.io.IOException;
import org.junit.jupiter.api.Test;
import static com.google.cloud.spanner.r2dbc.util.SpannerExceptionUtil.createR2dbcException;
import static org.assertj.core.api.Assertions.assertThat;
import com.google.protobuf.Duration;
import com.google.rpc.Code;
import com.google.rpc.RetryInfo;
import io.grpc.Metadata;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.protobuf.ProtoUtils;
import io.r2dbc.spi.R2dbcDataIntegrityViolationException;
import io.r2dbc.spi.R2dbcException;
import io.r2dbc.spi.R2dbcNonTransientResourceException;
import io.r2dbc.spi.R2dbcPermissionDeniedException;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.util;
class SpannerExceptionUtilTest {
@Test
void testCreateR2dbcException() { | R2dbcException exception = SpannerExceptionUtil.createR2dbcException( |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryResult.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
| import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerClientLibraryResult implements Result {
private final Flux<SpannerClientLibraryRow> resultRows;
private final int numRowsUpdated;
private RowMetadata rowMetadata;
public SpannerClientLibraryResult(
Flux<SpannerClientLibraryRow> resultRows, int numRowsUpdated) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryResult.java
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerClientLibraryResult implements Result {
private final Flux<SpannerClientLibraryRow> resultRows;
private final int numRowsUpdated;
private RowMetadata rowMetadata;
public SpannerClientLibraryResult(
Flux<SpannerClientLibraryRow> resultRows, int numRowsUpdated) { | this.resultRows = Assert.requireNonNull(resultRows, "A non-null flux of rows is required."); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/IterableBinder.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/BindingFailureException.java
// public class BindingFailureException extends R2dbcNonTransientException {
//
// public BindingFailureException(String message) {
// super(message);
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerType.java
// public abstract class SpannerType implements io.r2dbc.spi.Type {
//
// private Type type;
//
// private static final Map<Code, Class<?>> SPANNER_TO_JAVA_TYPES = buildTypeMap();
// private static final Map<Code, IterableStatementBinder> ARRAY_BINDERS = buildArrayBinderMap();
//
// private SpannerType(Type type) {
// this.type = type;
// }
//
// public abstract boolean isArray();
//
// /**
// * Adds type-specific binding of provided value to statement.
// * Fails if the value or type are not compatiblie with Spanner arrays.
// *
// * @param binder a {@link ValueBinder} from a call to {@code Statement.Builder.bind(String)}
// * @param value {@link Iterable} value to bind
// */
// public void bindIterable(ValueBinder<Statement.Builder> binder, Iterable<?> value) {
// if (!this.isArray()) {
// throw new BindingFailureException("Iterable cannot be bound to a non-array Spanner type.");
// }
//
// IterableStatementBinder typedBinder =
// ARRAY_BINDERS.get(this.type.getArrayElementType().getCode());
// if (typedBinder == null) {
// throw new BindingFailureException("Array binder not found for type " + this.type);
// }
// typedBinder.bind(binder, value);
//
// }
//
// /**
// * Returns a `{@link SpannerType} corresponding to the provided Spanner client library type.
// *
// * @param type client library {@link Type}
// * @return `{@link SpannerType} wrapper for the provided client library type
// */
// public static SpannerType of(Type type) {
// return new SpannerType(type) {
// @Override
// public Class<?> getJavaType() {
// return SPANNER_TO_JAVA_TYPES.get(type.getCode());
// }
//
// @Override
// public String getName() {
// return type.toString();
// }
//
// @Override
// public boolean isArray() {
// return type.getCode() == Code.ARRAY;
// }
// };
// }
//
// private static Map<Code, Class<?>> buildTypeMap() {
// Map<Code, Class<?>> map = new EnumMap<>(Code.class);
// map.put(Code.BOOL, Boolean.class);
// map.put(Code.BYTES, ByteArray.class);
// map.put(Code.DATE, Date.class);
// map.put(Code.FLOAT64, Double.class);
// map.put(Code.NUMERIC, BigDecimal.class);
// map.put(Code.INT64, Long.class);
// map.put(Code.STRING, String.class);
// map.put(Code.STRUCT, Struct.class);
// map.put(Code.TIMESTAMP, Timestamp.class);
// map.put(Code.ARRAY, Iterable.class);
//
// return map;
// }
//
// private static Map<Code, IterableStatementBinder> buildArrayBinderMap() {
// Map<Code, IterableStatementBinder> map = new EnumMap<>(Code.class);
// map.put(Code.BOOL, (b, i) -> b.toBoolArray((Iterable<Boolean>) i));
// map.put(Code.INT64, (b, i) -> b.toInt64Array((Iterable<Long>) i));
// map.put(Code.NUMERIC, (b, i) -> b.toNumericArray((Iterable<BigDecimal>) i));
// map.put(Code.FLOAT64, (b, i) -> b.toFloat64Array((Iterable<Double>) i));
// map.put(Code.STRING, (b, i) -> b.toStringArray((Iterable<String>) i));
// map.put(Code.BYTES, (b, i) -> b.toBytesArray((Iterable<ByteArray>) i));
// map.put(Code.TIMESTAMP, (b, i) -> b.toTimestampArray((Iterable<Timestamp>) i));
// map.put(Code.DATE, (b, i) -> b.toDateArray((Iterable<Date>) i));
// // no JSON, ARRAY, STRUCT for now
//
// return map;
// }
//
// // More readable equivalent to BiConsumer<ValueBinder<Statement.Builder>, Iterable<?>>
// @FunctionalInterface
// private interface IterableStatementBinder {
// void bind(ValueBinder<Statement.Builder> binder, Iterable<?> value);
// }
// }
| import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.r2dbc.BindingFailureException;
import com.google.cloud.spanner.r2dbc.SpannerType; | /*
* Copyright 2022-2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
/**
* Binds {@link Iterable} values to statement parameters, using Spanner type information as a hint.
*/
class IterableBinder implements ClientLibraryTypeBinder {
@Override | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/BindingFailureException.java
// public class BindingFailureException extends R2dbcNonTransientException {
//
// public BindingFailureException(String message) {
// super(message);
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerType.java
// public abstract class SpannerType implements io.r2dbc.spi.Type {
//
// private Type type;
//
// private static final Map<Code, Class<?>> SPANNER_TO_JAVA_TYPES = buildTypeMap();
// private static final Map<Code, IterableStatementBinder> ARRAY_BINDERS = buildArrayBinderMap();
//
// private SpannerType(Type type) {
// this.type = type;
// }
//
// public abstract boolean isArray();
//
// /**
// * Adds type-specific binding of provided value to statement.
// * Fails if the value or type are not compatiblie with Spanner arrays.
// *
// * @param binder a {@link ValueBinder} from a call to {@code Statement.Builder.bind(String)}
// * @param value {@link Iterable} value to bind
// */
// public void bindIterable(ValueBinder<Statement.Builder> binder, Iterable<?> value) {
// if (!this.isArray()) {
// throw new BindingFailureException("Iterable cannot be bound to a non-array Spanner type.");
// }
//
// IterableStatementBinder typedBinder =
// ARRAY_BINDERS.get(this.type.getArrayElementType().getCode());
// if (typedBinder == null) {
// throw new BindingFailureException("Array binder not found for type " + this.type);
// }
// typedBinder.bind(binder, value);
//
// }
//
// /**
// * Returns a `{@link SpannerType} corresponding to the provided Spanner client library type.
// *
// * @param type client library {@link Type}
// * @return `{@link SpannerType} wrapper for the provided client library type
// */
// public static SpannerType of(Type type) {
// return new SpannerType(type) {
// @Override
// public Class<?> getJavaType() {
// return SPANNER_TO_JAVA_TYPES.get(type.getCode());
// }
//
// @Override
// public String getName() {
// return type.toString();
// }
//
// @Override
// public boolean isArray() {
// return type.getCode() == Code.ARRAY;
// }
// };
// }
//
// private static Map<Code, Class<?>> buildTypeMap() {
// Map<Code, Class<?>> map = new EnumMap<>(Code.class);
// map.put(Code.BOOL, Boolean.class);
// map.put(Code.BYTES, ByteArray.class);
// map.put(Code.DATE, Date.class);
// map.put(Code.FLOAT64, Double.class);
// map.put(Code.NUMERIC, BigDecimal.class);
// map.put(Code.INT64, Long.class);
// map.put(Code.STRING, String.class);
// map.put(Code.STRUCT, Struct.class);
// map.put(Code.TIMESTAMP, Timestamp.class);
// map.put(Code.ARRAY, Iterable.class);
//
// return map;
// }
//
// private static Map<Code, IterableStatementBinder> buildArrayBinderMap() {
// Map<Code, IterableStatementBinder> map = new EnumMap<>(Code.class);
// map.put(Code.BOOL, (b, i) -> b.toBoolArray((Iterable<Boolean>) i));
// map.put(Code.INT64, (b, i) -> b.toInt64Array((Iterable<Long>) i));
// map.put(Code.NUMERIC, (b, i) -> b.toNumericArray((Iterable<BigDecimal>) i));
// map.put(Code.FLOAT64, (b, i) -> b.toFloat64Array((Iterable<Double>) i));
// map.put(Code.STRING, (b, i) -> b.toStringArray((Iterable<String>) i));
// map.put(Code.BYTES, (b, i) -> b.toBytesArray((Iterable<ByteArray>) i));
// map.put(Code.TIMESTAMP, (b, i) -> b.toTimestampArray((Iterable<Timestamp>) i));
// map.put(Code.DATE, (b, i) -> b.toDateArray((Iterable<Date>) i));
// // no JSON, ARRAY, STRUCT for now
//
// return map;
// }
//
// // More readable equivalent to BiConsumer<ValueBinder<Statement.Builder>, Iterable<?>>
// @FunctionalInterface
// private interface IterableStatementBinder {
// void bind(ValueBinder<Statement.Builder> binder, Iterable<?> value);
// }
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/IterableBinder.java
import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.r2dbc.BindingFailureException;
import com.google.cloud.spanner.r2dbc.SpannerType;
/*
* Copyright 2022-2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
/**
* Binds {@link Iterable} values to statement parameters, using Spanner type information as a hint.
*/
class IterableBinder implements ClientLibraryTypeBinder {
@Override | public boolean canBind(Class<?> type, SpannerType spannerType) { |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/IterableBinder.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/BindingFailureException.java
// public class BindingFailureException extends R2dbcNonTransientException {
//
// public BindingFailureException(String message) {
// super(message);
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerType.java
// public abstract class SpannerType implements io.r2dbc.spi.Type {
//
// private Type type;
//
// private static final Map<Code, Class<?>> SPANNER_TO_JAVA_TYPES = buildTypeMap();
// private static final Map<Code, IterableStatementBinder> ARRAY_BINDERS = buildArrayBinderMap();
//
// private SpannerType(Type type) {
// this.type = type;
// }
//
// public abstract boolean isArray();
//
// /**
// * Adds type-specific binding of provided value to statement.
// * Fails if the value or type are not compatiblie with Spanner arrays.
// *
// * @param binder a {@link ValueBinder} from a call to {@code Statement.Builder.bind(String)}
// * @param value {@link Iterable} value to bind
// */
// public void bindIterable(ValueBinder<Statement.Builder> binder, Iterable<?> value) {
// if (!this.isArray()) {
// throw new BindingFailureException("Iterable cannot be bound to a non-array Spanner type.");
// }
//
// IterableStatementBinder typedBinder =
// ARRAY_BINDERS.get(this.type.getArrayElementType().getCode());
// if (typedBinder == null) {
// throw new BindingFailureException("Array binder not found for type " + this.type);
// }
// typedBinder.bind(binder, value);
//
// }
//
// /**
// * Returns a `{@link SpannerType} corresponding to the provided Spanner client library type.
// *
// * @param type client library {@link Type}
// * @return `{@link SpannerType} wrapper for the provided client library type
// */
// public static SpannerType of(Type type) {
// return new SpannerType(type) {
// @Override
// public Class<?> getJavaType() {
// return SPANNER_TO_JAVA_TYPES.get(type.getCode());
// }
//
// @Override
// public String getName() {
// return type.toString();
// }
//
// @Override
// public boolean isArray() {
// return type.getCode() == Code.ARRAY;
// }
// };
// }
//
// private static Map<Code, Class<?>> buildTypeMap() {
// Map<Code, Class<?>> map = new EnumMap<>(Code.class);
// map.put(Code.BOOL, Boolean.class);
// map.put(Code.BYTES, ByteArray.class);
// map.put(Code.DATE, Date.class);
// map.put(Code.FLOAT64, Double.class);
// map.put(Code.NUMERIC, BigDecimal.class);
// map.put(Code.INT64, Long.class);
// map.put(Code.STRING, String.class);
// map.put(Code.STRUCT, Struct.class);
// map.put(Code.TIMESTAMP, Timestamp.class);
// map.put(Code.ARRAY, Iterable.class);
//
// return map;
// }
//
// private static Map<Code, IterableStatementBinder> buildArrayBinderMap() {
// Map<Code, IterableStatementBinder> map = new EnumMap<>(Code.class);
// map.put(Code.BOOL, (b, i) -> b.toBoolArray((Iterable<Boolean>) i));
// map.put(Code.INT64, (b, i) -> b.toInt64Array((Iterable<Long>) i));
// map.put(Code.NUMERIC, (b, i) -> b.toNumericArray((Iterable<BigDecimal>) i));
// map.put(Code.FLOAT64, (b, i) -> b.toFloat64Array((Iterable<Double>) i));
// map.put(Code.STRING, (b, i) -> b.toStringArray((Iterable<String>) i));
// map.put(Code.BYTES, (b, i) -> b.toBytesArray((Iterable<ByteArray>) i));
// map.put(Code.TIMESTAMP, (b, i) -> b.toTimestampArray((Iterable<Timestamp>) i));
// map.put(Code.DATE, (b, i) -> b.toDateArray((Iterable<Date>) i));
// // no JSON, ARRAY, STRUCT for now
//
// return map;
// }
//
// // More readable equivalent to BiConsumer<ValueBinder<Statement.Builder>, Iterable<?>>
// @FunctionalInterface
// private interface IterableStatementBinder {
// void bind(ValueBinder<Statement.Builder> binder, Iterable<?> value);
// }
// }
| import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.r2dbc.BindingFailureException;
import com.google.cloud.spanner.r2dbc.SpannerType; | /*
* Copyright 2022-2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
/**
* Binds {@link Iterable} values to statement parameters, using Spanner type information as a hint.
*/
class IterableBinder implements ClientLibraryTypeBinder {
@Override
public boolean canBind(Class<?> type, SpannerType spannerType) {
// Handling all iterables regardless of SpannerType will allow more useful error messages.
return Iterable.class.isAssignableFrom(type);
}
@Override
public void bind(
Statement.Builder builder, String name, Object value, SpannerType spannerType) {
if (spannerType == null) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/BindingFailureException.java
// public class BindingFailureException extends R2dbcNonTransientException {
//
// public BindingFailureException(String message) {
// super(message);
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerType.java
// public abstract class SpannerType implements io.r2dbc.spi.Type {
//
// private Type type;
//
// private static final Map<Code, Class<?>> SPANNER_TO_JAVA_TYPES = buildTypeMap();
// private static final Map<Code, IterableStatementBinder> ARRAY_BINDERS = buildArrayBinderMap();
//
// private SpannerType(Type type) {
// this.type = type;
// }
//
// public abstract boolean isArray();
//
// /**
// * Adds type-specific binding of provided value to statement.
// * Fails if the value or type are not compatiblie with Spanner arrays.
// *
// * @param binder a {@link ValueBinder} from a call to {@code Statement.Builder.bind(String)}
// * @param value {@link Iterable} value to bind
// */
// public void bindIterable(ValueBinder<Statement.Builder> binder, Iterable<?> value) {
// if (!this.isArray()) {
// throw new BindingFailureException("Iterable cannot be bound to a non-array Spanner type.");
// }
//
// IterableStatementBinder typedBinder =
// ARRAY_BINDERS.get(this.type.getArrayElementType().getCode());
// if (typedBinder == null) {
// throw new BindingFailureException("Array binder not found for type " + this.type);
// }
// typedBinder.bind(binder, value);
//
// }
//
// /**
// * Returns a `{@link SpannerType} corresponding to the provided Spanner client library type.
// *
// * @param type client library {@link Type}
// * @return `{@link SpannerType} wrapper for the provided client library type
// */
// public static SpannerType of(Type type) {
// return new SpannerType(type) {
// @Override
// public Class<?> getJavaType() {
// return SPANNER_TO_JAVA_TYPES.get(type.getCode());
// }
//
// @Override
// public String getName() {
// return type.toString();
// }
//
// @Override
// public boolean isArray() {
// return type.getCode() == Code.ARRAY;
// }
// };
// }
//
// private static Map<Code, Class<?>> buildTypeMap() {
// Map<Code, Class<?>> map = new EnumMap<>(Code.class);
// map.put(Code.BOOL, Boolean.class);
// map.put(Code.BYTES, ByteArray.class);
// map.put(Code.DATE, Date.class);
// map.put(Code.FLOAT64, Double.class);
// map.put(Code.NUMERIC, BigDecimal.class);
// map.put(Code.INT64, Long.class);
// map.put(Code.STRING, String.class);
// map.put(Code.STRUCT, Struct.class);
// map.put(Code.TIMESTAMP, Timestamp.class);
// map.put(Code.ARRAY, Iterable.class);
//
// return map;
// }
//
// private static Map<Code, IterableStatementBinder> buildArrayBinderMap() {
// Map<Code, IterableStatementBinder> map = new EnumMap<>(Code.class);
// map.put(Code.BOOL, (b, i) -> b.toBoolArray((Iterable<Boolean>) i));
// map.put(Code.INT64, (b, i) -> b.toInt64Array((Iterable<Long>) i));
// map.put(Code.NUMERIC, (b, i) -> b.toNumericArray((Iterable<BigDecimal>) i));
// map.put(Code.FLOAT64, (b, i) -> b.toFloat64Array((Iterable<Double>) i));
// map.put(Code.STRING, (b, i) -> b.toStringArray((Iterable<String>) i));
// map.put(Code.BYTES, (b, i) -> b.toBytesArray((Iterable<ByteArray>) i));
// map.put(Code.TIMESTAMP, (b, i) -> b.toTimestampArray((Iterable<Timestamp>) i));
// map.put(Code.DATE, (b, i) -> b.toDateArray((Iterable<Date>) i));
// // no JSON, ARRAY, STRUCT for now
//
// return map;
// }
//
// // More readable equivalent to BiConsumer<ValueBinder<Statement.Builder>, Iterable<?>>
// @FunctionalInterface
// private interface IterableStatementBinder {
// void bind(ValueBinder<Statement.Builder> binder, Iterable<?> value);
// }
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/IterableBinder.java
import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.r2dbc.BindingFailureException;
import com.google.cloud.spanner.r2dbc.SpannerType;
/*
* Copyright 2022-2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
/**
* Binds {@link Iterable} values to statement parameters, using Spanner type information as a hint.
*/
class IterableBinder implements ClientLibraryTypeBinder {
@Override
public boolean canBind(Class<?> type, SpannerType spannerType) {
// Handling all iterables regardless of SpannerType will allow more useful error messages.
return Iterable.class.isAssignableFrom(type);
}
@Override
public void bind(
Statement.Builder builder, String name, Object value, SpannerType spannerType) {
if (spannerType == null) { | throw new BindingFailureException( |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/StringToJsonConverter.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
| import com.google.cloud.spanner.r2dbc.ConversionFailureException; | /*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class StringToJsonConverter implements SpannerClientLibrariesConverter<JsonWrapper> {
@Override
public boolean canConvert(Class<?> inputClass, Class<?> resultClass) {
return inputClass == String.class && resultClass == JsonWrapper.class;
}
@Override
public JsonWrapper convert(Object input) {
if (!canConvert(input.getClass(), JsonWrapper.class)) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/StringToJsonConverter.java
import com.google.cloud.spanner.r2dbc.ConversionFailureException;
/*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class StringToJsonConverter implements SpannerClientLibrariesConverter<JsonWrapper> {
@Override
public boolean canConvert(Class<?> inputClass, Class<?> resultClass) {
return inputClass == String.class && resultClass == JsonWrapper.class;
}
@Override
public JsonWrapper convert(Object input) {
if (!canConvert(input.getClass(), JsonWrapper.class)) { | throw new ConversionFailureException( |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryRow.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
| import com.google.cloud.spanner.Struct;
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerClientLibraryRow implements Row {
private Struct rowFields;
public SpannerClientLibraryRow(Struct rowFields) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryRow.java
import com.google.cloud.spanner.Struct;
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerClientLibraryRow implements Row {
private Struct rowFields;
public SpannerClientLibraryRow(Struct rowFields) { | Assert.requireNonNull(rowFields, "rowFields must not be null"); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-spring-data-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/springdata/SpannerR2dbcDialect.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
| import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import com.google.gson.Gson;
import java.util.Arrays;
import java.util.Collection;
import org.springframework.data.r2dbc.dialect.R2dbcDialect;
import org.springframework.data.relational.core.dialect.AbstractDialect;
import org.springframework.data.relational.core.dialect.ArrayColumns;
import org.springframework.data.relational.core.dialect.LimitClause;
import org.springframework.data.relational.core.dialect.LockClause;
import org.springframework.data.relational.core.sql.LockOptions;
import org.springframework.r2dbc.core.binding.BindMarkersFactory; | private static final LockClause LOCK_CLAUSE = new LockClause() {
@Override
public String getLock(LockOptions lockOptions) {
return "";
}
@Override
public Position getClausePosition() {
// It does not matter where to append an empty string.
return Position.AFTER_FROM_TABLE;
}
};
@Override
public BindMarkersFactory getBindMarkersFactory() {
return NAMED;
}
@Override
public LimitClause limit() {
return LIMIT_CLAUSE;
}
@Override
public LockClause lock() {
return LOCK_CLAUSE;
}
@Override
public Collection<? extends Class<?>> getSimpleTypes() { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
// Path: cloud-spanner-spring-data-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/springdata/SpannerR2dbcDialect.java
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import com.google.gson.Gson;
import java.util.Arrays;
import java.util.Collection;
import org.springframework.data.r2dbc.dialect.R2dbcDialect;
import org.springframework.data.relational.core.dialect.AbstractDialect;
import org.springframework.data.relational.core.dialect.ArrayColumns;
import org.springframework.data.relational.core.dialect.LimitClause;
import org.springframework.data.relational.core.dialect.LockClause;
import org.springframework.data.relational.core.sql.LockOptions;
import org.springframework.r2dbc.core.binding.BindMarkersFactory;
private static final LockClause LOCK_CLAUSE = new LockClause() {
@Override
public String getLock(LockOptions lockOptions) {
return "";
}
@Override
public Position getClausePosition() {
// It does not matter where to append an empty string.
return Position.AFTER_FROM_TABLE;
}
};
@Override
public BindMarkersFactory getBindMarkersFactory() {
return NAMED;
}
@Override
public LimitClause limit() {
return LIMIT_CLAUSE;
}
@Override
public LockClause lock() {
return LOCK_CLAUSE;
}
@Override
public Collection<? extends Class<?>> getSimpleTypes() { | return Arrays.asList(JsonWrapper.class); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SessionCleanupUtils.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/ObservableReactiveUtil.java
// public class ObservableReactiveUtil {
//
// /**
// * Invokes a lambda that in turn issues a remote call, directing the response to a {@link Mono}
// * stream.
// *
// * @param remoteCall lambda capable of invoking the correct remote call, making use of the
// * {@link Mono}-converting {@link StreamObserver} implementation.
// * @param <ResponseT> type of remote call response
// *
// * @return {@link Mono} containing the response of the unary call.
// */
// public static <ResponseT> Mono<ResponseT> unaryCall(
// Consumer<StreamObserver<ResponseT>> remoteCall) {
// return Mono.create(sink -> remoteCall.accept(new UnaryStreamObserver<>(sink)));
// }
//
// /**
// * Invokes a lambda that issues a streaming call and directs the response to a {@link Flux}
// * stream.
// *
// * @param remoteCall call to make
// * @param <RequestT> request type
// * @param <ResponseT> response type
// *
// * @return {@link Flux} of response objects resulting from the streaming call.
// */
// public static <RequestT, ResponseT> Flux<ResponseT> streamingCall(
// Consumer<StreamObserver<ResponseT>> remoteCall) {
//
// return Flux.create(sink -> {
// StreamingObserver<RequestT, ResponseT> observer = new StreamingObserver<>(sink);
// remoteCall.accept(observer);
// sink.onRequest(demand -> observer.request(demand));
// });
// }
//
// static class StreamingObserver<RequestT, ResponseT>
// implements ClientResponseObserver<RequestT, ResponseT> {
// ClientCallStreamObserver<RequestT> rsObserver;
// FluxSink<ResponseT> sink;
//
// public StreamingObserver(FluxSink<ResponseT> sink) {
// this.sink = sink;
// }
//
// @Override
// public void onNext(ResponseT value) {
// this.sink.next(value);
// }
//
// @Override
// public void onError(Throwable throwable) {
// this.sink.error(SpannerExceptionUtil.createR2dbcException(throwable));
// }
//
// @Override
// public void onCompleted() {
// this.sink.complete();
// }
//
// @Override
// public void beforeStart(ClientCallStreamObserver<RequestT> requestStream) {
// this.rsObserver = requestStream;
// requestStream.disableAutoInboundFlowControl();
// this.sink.onCancel(() -> requestStream.cancel("Flux requested cancel.", null));
// }
//
// public void request(long n) {
// this.rsObserver.request(n > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) n);
// }
// }
//
// /**
// * Forwards the result of a unary gRPC call to a {@link MonoSink}.
// *
// * <p>Unary gRPC calls expect a single response or an error, so completion of the call without an
// * emitted value is an error condition.
// *
// * @param <ResponseT> type of expected gRPC call response value.
// */
// private static class UnaryStreamObserver<ResponseT> implements StreamObserver<ResponseT> {
//
// private boolean terminalEventReceived;
//
// private final MonoSink<ResponseT> sink;
//
// public UnaryStreamObserver(MonoSink<ResponseT> sink) {
// this.sink = sink;
// }
//
// @Override
// public void onNext(ResponseT response) {
// this.terminalEventReceived = true;
// this.sink.success(response);
// }
//
// @Override
// public void onError(Throwable throwable) {
// this.terminalEventReceived = true;
// this.sink.error(SpannerExceptionUtil.createR2dbcException(throwable));
// }
//
// @Override
// public void onCompleted() {
// if (!this.terminalEventReceived) {
// this.sink.error(
// new RuntimeException("Unary gRPC call completed without yielding a value or an error"));
// }
// }
// }
// }
| import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil;
import com.google.protobuf.Empty;
import com.google.spanner.v1.DatabaseName;
import com.google.spanner.v1.DeleteSessionRequest;
import com.google.spanner.v1.ListSessionsRequest;
import com.google.spanner.v1.ListSessionsResponse;
import com.google.spanner.v1.Session;
import com.google.spanner.v1.SpannerGrpc;
import com.google.spanner.v1.SpannerGrpc.SpannerStub;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.auth.MoreCallCredentials; | * Exceptions:
* - you are running in a CI environment and there are other tests running.
* - you want to verify session state after a test. In this case, make another method
* verifying the correct number of sessions (exactly 1, greater than 10 etc.)
*/
static void verifyNoLeftoverSessions() throws Exception {
List<String> activeSessions = getSessionNames();
if (activeSessions.isEmpty()) {
System.out.println("No leftover sessions, yay!");
} else {
throw new IllegalStateException("Expected no sessions, but found " + activeSessions.size());
}
}
private static List<String> getSessionNames() throws Exception {
String databaseName = DatabaseName.format(ServiceOptions.getDefaultProjectId(),
DatabaseProperties.INSTANCE, DatabaseProperties.DATABASE);
String nextPageToken = null;
List<String> sessionNames = new ArrayList<>();
do {
ListSessionsRequest.Builder requestBuilder =
ListSessionsRequest.newBuilder().setDatabase(databaseName);
if (nextPageToken != null) {
requestBuilder.setPageToken(nextPageToken);
}
ListSessionsResponse listSessionsResponse = | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/ObservableReactiveUtil.java
// public class ObservableReactiveUtil {
//
// /**
// * Invokes a lambda that in turn issues a remote call, directing the response to a {@link Mono}
// * stream.
// *
// * @param remoteCall lambda capable of invoking the correct remote call, making use of the
// * {@link Mono}-converting {@link StreamObserver} implementation.
// * @param <ResponseT> type of remote call response
// *
// * @return {@link Mono} containing the response of the unary call.
// */
// public static <ResponseT> Mono<ResponseT> unaryCall(
// Consumer<StreamObserver<ResponseT>> remoteCall) {
// return Mono.create(sink -> remoteCall.accept(new UnaryStreamObserver<>(sink)));
// }
//
// /**
// * Invokes a lambda that issues a streaming call and directs the response to a {@link Flux}
// * stream.
// *
// * @param remoteCall call to make
// * @param <RequestT> request type
// * @param <ResponseT> response type
// *
// * @return {@link Flux} of response objects resulting from the streaming call.
// */
// public static <RequestT, ResponseT> Flux<ResponseT> streamingCall(
// Consumer<StreamObserver<ResponseT>> remoteCall) {
//
// return Flux.create(sink -> {
// StreamingObserver<RequestT, ResponseT> observer = new StreamingObserver<>(sink);
// remoteCall.accept(observer);
// sink.onRequest(demand -> observer.request(demand));
// });
// }
//
// static class StreamingObserver<RequestT, ResponseT>
// implements ClientResponseObserver<RequestT, ResponseT> {
// ClientCallStreamObserver<RequestT> rsObserver;
// FluxSink<ResponseT> sink;
//
// public StreamingObserver(FluxSink<ResponseT> sink) {
// this.sink = sink;
// }
//
// @Override
// public void onNext(ResponseT value) {
// this.sink.next(value);
// }
//
// @Override
// public void onError(Throwable throwable) {
// this.sink.error(SpannerExceptionUtil.createR2dbcException(throwable));
// }
//
// @Override
// public void onCompleted() {
// this.sink.complete();
// }
//
// @Override
// public void beforeStart(ClientCallStreamObserver<RequestT> requestStream) {
// this.rsObserver = requestStream;
// requestStream.disableAutoInboundFlowControl();
// this.sink.onCancel(() -> requestStream.cancel("Flux requested cancel.", null));
// }
//
// public void request(long n) {
// this.rsObserver.request(n > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) n);
// }
// }
//
// /**
// * Forwards the result of a unary gRPC call to a {@link MonoSink}.
// *
// * <p>Unary gRPC calls expect a single response or an error, so completion of the call without an
// * emitted value is an error condition.
// *
// * @param <ResponseT> type of expected gRPC call response value.
// */
// private static class UnaryStreamObserver<ResponseT> implements StreamObserver<ResponseT> {
//
// private boolean terminalEventReceived;
//
// private final MonoSink<ResponseT> sink;
//
// public UnaryStreamObserver(MonoSink<ResponseT> sink) {
// this.sink = sink;
// }
//
// @Override
// public void onNext(ResponseT response) {
// this.terminalEventReceived = true;
// this.sink.success(response);
// }
//
// @Override
// public void onError(Throwable throwable) {
// this.terminalEventReceived = true;
// this.sink.error(SpannerExceptionUtil.createR2dbcException(throwable));
// }
//
// @Override
// public void onCompleted() {
// if (!this.terminalEventReceived) {
// this.sink.error(
// new RuntimeException("Unary gRPC call completed without yielding a value or an error"));
// }
// }
// }
// }
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SessionCleanupUtils.java
import io.grpc.stub.StreamObserver;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil;
import com.google.protobuf.Empty;
import com.google.spanner.v1.DatabaseName;
import com.google.spanner.v1.DeleteSessionRequest;
import com.google.spanner.v1.ListSessionsRequest;
import com.google.spanner.v1.ListSessionsResponse;
import com.google.spanner.v1.Session;
import com.google.spanner.v1.SpannerGrpc;
import com.google.spanner.v1.SpannerGrpc.SpannerStub;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.auth.MoreCallCredentials;
* Exceptions:
* - you are running in a CI environment and there are other tests running.
* - you want to verify session state after a test. In this case, make another method
* verifying the correct number of sessions (exactly 1, greater than 10 etc.)
*/
static void verifyNoLeftoverSessions() throws Exception {
List<String> activeSessions = getSessionNames();
if (activeSessions.isEmpty()) {
System.out.println("No leftover sessions, yay!");
} else {
throw new IllegalStateException("Expected no sessions, but found " + activeSessions.size());
}
}
private static List<String> getSessionNames() throws Exception {
String databaseName = DatabaseName.format(ServiceOptions.getDefaultProjectId(),
DatabaseProperties.INSTANCE, DatabaseProperties.DATABASE);
String nextPageToken = null;
List<String> sessionNames = new ArrayList<>();
do {
ListSessionsRequest.Builder requestBuilder =
ListSessionsRequest.newBuilder().setDatabase(databaseName);
if (nextPageToken != null) {
requestBuilder.setPageToken(nextPageToken);
}
ListSessionsResponse listSessionsResponse = | ObservableReactiveUtil.<ListSessionsResponse>unaryCall( |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/LongIntegerConverter.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
| import com.google.cloud.spanner.r2dbc.ConversionFailureException; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class LongIntegerConverter implements SpannerClientLibrariesConverter<Integer> {
@Override
public boolean canConvert(Class<?> inputClass, Class<?> resultClass) {
return inputClass == Long.class && resultClass == Integer.class;
}
@Override
public Integer convert(Object input) {
if (!canConvert(input.getClass(), Integer.class)) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/LongIntegerConverter.java
import com.google.cloud.spanner.r2dbc.ConversionFailureException;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class LongIntegerConverter implements SpannerClientLibrariesConverter<Integer> {
@Override
public boolean canConvert(Class<?> inputClass, Class<?> resultClass) {
return inputClass == Long.class && resultClass == Integer.class;
}
@Override
public Integer convert(Object input) {
if (!canConvert(input.getClass(), Integer.class)) { | throw new ConversionFailureException( |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/AbstractSpannerClientLibraryStatement.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/TypedNull.java
// public class TypedNull {
//
// private final Class<?> type;
//
// public TypedNull(Class<?> type) {
// this.type = type;
// }
//
// public Class<?> getType() {
// return this.type;
// }
// }
| import com.google.cloud.spanner.r2dbc.statement.TypedNull;
import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Statement;
import java.util.ArrayList;
import java.util.List;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; | return executeMultiple(this.statements);
}
return executeSingle(this.currentStatementBuilder.build());
}
protected abstract Mono<SpannerClientLibraryResult> executeSingle(
com.google.cloud.spanner.Statement statement);
protected abstract Flux<SpannerClientLibraryResult> executeMultiple(
List<com.google.cloud.spanner.Statement> statements);
@Override
public Statement bind(int index, Object value) {
throw new UnsupportedOperationException();
}
@Override
public Statement bind(String name, Object value) {
ClientLibraryBinder.bind(this.currentStatementBuilder, name, value);
this.startedBinding = true;
return this;
}
@Override
public Statement bindNull(int index, Class<?> type) {
throw new UnsupportedOperationException();
}
@Override
public Statement bindNull(String name, Class<?> type) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/TypedNull.java
// public class TypedNull {
//
// private final Class<?> type;
//
// public TypedNull(Class<?> type) {
// this.type = type;
// }
//
// public Class<?> getType() {
// return this.type;
// }
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/AbstractSpannerClientLibraryStatement.java
import com.google.cloud.spanner.r2dbc.statement.TypedNull;
import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Statement;
import java.util.ArrayList;
import java.util.List;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
return executeMultiple(this.statements);
}
return executeSingle(this.currentStatementBuilder.build());
}
protected abstract Mono<SpannerClientLibraryResult> executeSingle(
com.google.cloud.spanner.Statement statement);
protected abstract Flux<SpannerClientLibraryResult> executeMultiple(
List<com.google.cloud.spanner.Statement> statements);
@Override
public Statement bind(int index, Object value) {
throw new UnsupportedOperationException();
}
@Override
public Statement bind(String name, Object value) {
ClientLibraryBinder.bind(this.currentStatementBuilder, name, value);
this.startedBinding = true;
return this;
}
@Override
public Statement bindNull(int index, Class<?> type) {
throw new UnsupportedOperationException();
}
@Override
public Statement bindNull(String name, Class<?> type) { | ClientLibraryBinder.bind(this.currentStatementBuilder, name, new TypedNull(type)); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConverters.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
| import com.google.cloud.spanner.r2dbc.ConversionFailureException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerClientLibraryConverters {
private static final List<SpannerClientLibrariesConverter<?>> converters = createConverters();
private static List<SpannerClientLibrariesConverter<?>> createConverters() {
ArrayList<SpannerClientLibrariesConverter<?>> converters = new ArrayList<>();
converters.add(new LongIntegerConverter());
converters.add(new StringToJsonConverter());
return converters;
}
static <T> T convert(Object value, Class<T> type) {
Optional<SpannerClientLibrariesConverter<?>> converter = converters.stream()
.filter(candidate -> candidate.canConvert(value.getClass(), type))
.findFirst();
if (!converter.isPresent()) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConverters.java
import com.google.cloud.spanner.r2dbc.ConversionFailureException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerClientLibraryConverters {
private static final List<SpannerClientLibrariesConverter<?>> converters = createConverters();
private static List<SpannerClientLibrariesConverter<?>> createConverters() {
ArrayList<SpannerClientLibrariesConverter<?>> converters = new ArrayList<>();
converters.add(new LongIntegerConverter());
converters.add(new StringToJsonConverter());
return converters;
}
static <T> T convert(Object value, Class<T> type) {
Optional<SpannerClientLibrariesConverter<?>> converter = converters.stream()
.filter(candidate -> candidate.canConvert(value.getClass(), type))
.findFirst();
if (!converter.isPresent()) { | throw new ConversionFailureException( |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-spring-data-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/springdata/it/SpannerR2dbcDialectIntegrationTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
//
// Path: cloud-spanner-spring-data-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/springdata/it/entities/President.java
// public class President {
//
// @Column("NAME")
// private String name;
//
// @Column("START_YEAR")
// private long startYear;
//
// public President(String name, long startYear) {
// this.name = name;
// this.startYear = startYear;
// }
//
// public String getName() {
// return this.name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public long getStartYear() {
// return this.startYear;
// }
//
// public void setStartYear(long startYear) {
// this.startYear = startYear;
// }
//
// @Override
// public String toString() {
// return "President{"
// + "name='"
// + this.name + '\''
// + ", startYear="
// + this.startYear + '}';
// }
// }
| import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.r2dbc.springdata.it.entities.President;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.relational.core.query.Query;
import org.springframework.r2dbc.core.DatabaseClient;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.springdata.it;
/**
* Integration tests for the Spring Data R2DBC dialect.
*
* <p>By default, the test is configured to run tests in the `reactivetest` instance on the
* `testdb` database. This can be configured by overriding the `spanner.instance` and
* `spanner.database` system properties.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SpannerR2dbcDialectIntegrationTest {
private static final Logger logger =
LoggerFactory.getLogger(SpannerR2dbcDialectIntegrationTest.class);
private static final String DRIVER_NAME = "spanner";
private static final String TEST_INSTANCE =
System.getProperty("spanner.instance", "reactivetest");
private static final String TEST_DATABASE =
System.getProperty("spanner.database", "testdb");
private static final ConnectionFactory connectionFactory =
ConnectionFactories.get(ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
//
// Path: cloud-spanner-spring-data-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/springdata/it/entities/President.java
// public class President {
//
// @Column("NAME")
// private String name;
//
// @Column("START_YEAR")
// private long startYear;
//
// public President(String name, long startYear) {
// this.name = name;
// this.startYear = startYear;
// }
//
// public String getName() {
// return this.name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public long getStartYear() {
// return this.startYear;
// }
//
// public void setStartYear(long startYear) {
// this.startYear = startYear;
// }
//
// @Override
// public String toString() {
// return "President{"
// + "name='"
// + this.name + '\''
// + ", startYear="
// + this.startYear + '}';
// }
// }
// Path: cloud-spanner-spring-data-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/springdata/it/SpannerR2dbcDialectIntegrationTest.java
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.r2dbc.springdata.it.entities.President;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.relational.core.query.Query;
import org.springframework.r2dbc.core.DatabaseClient;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.springdata.it;
/**
* Integration tests for the Spring Data R2DBC dialect.
*
* <p>By default, the test is configured to run tests in the `reactivetest` instance on the
* `testdb` database. This can be configured by overriding the `spanner.instance` and
* `spanner.database` system properties.
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SpannerR2dbcDialectIntegrationTest {
private static final Logger logger =
LoggerFactory.getLogger(SpannerR2dbcDialectIntegrationTest.class);
private static final String DRIVER_NAME = "spanner";
private static final String TEST_INSTANCE =
System.getProperty("spanner.instance", "reactivetest");
private static final String TEST_DATABASE =
System.getProperty("spanner.database", "testdb");
private static final ConnectionFactory connectionFactory =
ConnectionFactories.get(ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | .option(INSTANCE, TEST_INSTANCE) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-spring-data-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/springdata/it/SpannerR2dbcDialectIntegrationTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
//
// Path: cloud-spanner-spring-data-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/springdata/it/entities/President.java
// public class President {
//
// @Column("NAME")
// private String name;
//
// @Column("START_YEAR")
// private long startYear;
//
// public President(String name, long startYear) {
// this.name = name;
// this.startYear = startYear;
// }
//
// public String getName() {
// return this.name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public long getStartYear() {
// return this.startYear;
// }
//
// public void setStartYear(long startYear) {
// this.startYear = startYear;
// }
//
// @Override
// public String toString() {
// return "President{"
// + "name='"
// + this.name + '\''
// + ", startYear="
// + this.startYear + '}';
// }
// }
| import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.r2dbc.springdata.it.entities.President;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.relational.core.query.Query;
import org.springframework.r2dbc.core.DatabaseClient;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; | this.databaseClient = this.r2dbcEntityTemplate.getDatabaseClient();
if (SpannerTestUtils.tableExists(connection, "PRESIDENT")) {
this.databaseClient.sql("DROP TABLE PRESIDENT")
.fetch()
.rowsUpdated()
.block();
}
this.databaseClient.sql(
"CREATE TABLE PRESIDENT ("
+ " NAME STRING(256) NOT NULL,"
+ " START_YEAR INT64 NOT NULL"
+ ") PRIMARY KEY (NAME)")
.fetch()
.rowsUpdated()
.block();
}
@AfterEach
public void cleanupTableAfterTest() {
this.databaseClient
.sql("DELETE FROM PRESIDENT where NAME is not null")
.fetch()
.rowsUpdated()
.block();
}
@Test
void testReadWrite() { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
//
// Path: cloud-spanner-spring-data-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/springdata/it/entities/President.java
// public class President {
//
// @Column("NAME")
// private String name;
//
// @Column("START_YEAR")
// private long startYear;
//
// public President(String name, long startYear) {
// this.name = name;
// this.startYear = startYear;
// }
//
// public String getName() {
// return this.name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public long getStartYear() {
// return this.startYear;
// }
//
// public void setStartYear(long startYear) {
// this.startYear = startYear;
// }
//
// @Override
// public String toString() {
// return "President{"
// + "name='"
// + this.name + '\''
// + ", startYear="
// + this.startYear + '}';
// }
// }
// Path: cloud-spanner-spring-data-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/springdata/it/SpannerR2dbcDialectIntegrationTest.java
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import com.google.cloud.spanner.r2dbc.springdata.it.entities.President;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.relational.core.query.Query;
import org.springframework.r2dbc.core.DatabaseClient;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
this.databaseClient = this.r2dbcEntityTemplate.getDatabaseClient();
if (SpannerTestUtils.tableExists(connection, "PRESIDENT")) {
this.databaseClient.sql("DROP TABLE PRESIDENT")
.fetch()
.rowsUpdated()
.block();
}
this.databaseClient.sql(
"CREATE TABLE PRESIDENT ("
+ " NAME STRING(256) NOT NULL,"
+ " START_YEAR INT64 NOT NULL"
+ ") PRIMARY KEY (NAME)")
.fetch()
.rowsUpdated()
.block();
}
@AfterEach
public void cleanupTableAfterTest() {
this.databaseClient
.sql("DELETE FROM PRESIDENT where NAME is not null")
.fetch()
.rowsUpdated()
.block();
}
@Test
void testReadWrite() { | insertPresident(new President("Bill Clinton", 1992)); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerBatch.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementParser.java
// public class StatementParser {
//
// private static com.google.cloud.spanner.connection.AbstractStatementParser clientLibraryParser =
// com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(
// Dialect.GOOGLE_STANDARD_SQL);
//
// private StatementParser() {
// // Prevent instantiation.
// }
//
// /**
// * Returns the statement type of a given SQL string.
// *
// * @param sql the input SQL string.
// *
// * @return the type of statement of the SQL string.
// */
// public static StatementType getStatementType(String sql) {
// if (clientLibraryParser.isQuery(sql)) {
// return StatementType.SELECT;
// } else if (clientLibraryParser.isDdlStatement(sql)) {
// return StatementType.DDL;
// } else if (clientLibraryParser.isUpdateStatement(sql)) {
// return StatementType.DML;
// } else {
// return StatementType.UNKNOWN;
// }
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementType.java
// public enum StatementType {
// SELECT,
// DDL,
// DML,
// UNKNOWN;
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
| import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.r2dbc.statement.StatementParser;
import com.google.cloud.spanner.r2dbc.statement.StatementType;
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Result;
import java.util.ArrayList;
import java.util.List;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerBatch implements Batch {
private DatabaseClientReactiveAdapter clientLibraryAdapter;
private List<Statement> statements = new ArrayList<>();
SpannerBatch(DatabaseClientReactiveAdapter clientLibraryAdapter) {
this.clientLibraryAdapter = clientLibraryAdapter;
}
@Override
public Batch add(String sql) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementParser.java
// public class StatementParser {
//
// private static com.google.cloud.spanner.connection.AbstractStatementParser clientLibraryParser =
// com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(
// Dialect.GOOGLE_STANDARD_SQL);
//
// private StatementParser() {
// // Prevent instantiation.
// }
//
// /**
// * Returns the statement type of a given SQL string.
// *
// * @param sql the input SQL string.
// *
// * @return the type of statement of the SQL string.
// */
// public static StatementType getStatementType(String sql) {
// if (clientLibraryParser.isQuery(sql)) {
// return StatementType.SELECT;
// } else if (clientLibraryParser.isDdlStatement(sql)) {
// return StatementType.DDL;
// } else if (clientLibraryParser.isUpdateStatement(sql)) {
// return StatementType.DML;
// } else {
// return StatementType.UNKNOWN;
// }
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementType.java
// public enum StatementType {
// SELECT,
// DDL,
// DML,
// UNKNOWN;
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerBatch.java
import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.r2dbc.statement.StatementParser;
import com.google.cloud.spanner.r2dbc.statement.StatementType;
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Result;
import java.util.ArrayList;
import java.util.List;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerBatch implements Batch {
private DatabaseClientReactiveAdapter clientLibraryAdapter;
private List<Statement> statements = new ArrayList<>();
SpannerBatch(DatabaseClientReactiveAdapter clientLibraryAdapter) {
this.clientLibraryAdapter = clientLibraryAdapter;
}
@Override
public Batch add(String sql) { | Assert.requireNonNull(sql, "SQL must not be null."); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerBatch.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementParser.java
// public class StatementParser {
//
// private static com.google.cloud.spanner.connection.AbstractStatementParser clientLibraryParser =
// com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(
// Dialect.GOOGLE_STANDARD_SQL);
//
// private StatementParser() {
// // Prevent instantiation.
// }
//
// /**
// * Returns the statement type of a given SQL string.
// *
// * @param sql the input SQL string.
// *
// * @return the type of statement of the SQL string.
// */
// public static StatementType getStatementType(String sql) {
// if (clientLibraryParser.isQuery(sql)) {
// return StatementType.SELECT;
// } else if (clientLibraryParser.isDdlStatement(sql)) {
// return StatementType.DDL;
// } else if (clientLibraryParser.isUpdateStatement(sql)) {
// return StatementType.DML;
// } else {
// return StatementType.UNKNOWN;
// }
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementType.java
// public enum StatementType {
// SELECT,
// DDL,
// DML,
// UNKNOWN;
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
| import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.r2dbc.statement.StatementParser;
import com.google.cloud.spanner.r2dbc.statement.StatementType;
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Result;
import java.util.ArrayList;
import java.util.List;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerBatch implements Batch {
private DatabaseClientReactiveAdapter clientLibraryAdapter;
private List<Statement> statements = new ArrayList<>();
SpannerBatch(DatabaseClientReactiveAdapter clientLibraryAdapter) {
this.clientLibraryAdapter = clientLibraryAdapter;
}
@Override
public Batch add(String sql) {
Assert.requireNonNull(sql, "SQL must not be null."); | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementParser.java
// public class StatementParser {
//
// private static com.google.cloud.spanner.connection.AbstractStatementParser clientLibraryParser =
// com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(
// Dialect.GOOGLE_STANDARD_SQL);
//
// private StatementParser() {
// // Prevent instantiation.
// }
//
// /**
// * Returns the statement type of a given SQL string.
// *
// * @param sql the input SQL string.
// *
// * @return the type of statement of the SQL string.
// */
// public static StatementType getStatementType(String sql) {
// if (clientLibraryParser.isQuery(sql)) {
// return StatementType.SELECT;
// } else if (clientLibraryParser.isDdlStatement(sql)) {
// return StatementType.DDL;
// } else if (clientLibraryParser.isUpdateStatement(sql)) {
// return StatementType.DML;
// } else {
// return StatementType.UNKNOWN;
// }
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementType.java
// public enum StatementType {
// SELECT,
// DDL,
// DML,
// UNKNOWN;
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerBatch.java
import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.r2dbc.statement.StatementParser;
import com.google.cloud.spanner.r2dbc.statement.StatementType;
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Result;
import java.util.ArrayList;
import java.util.List;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerBatch implements Batch {
private DatabaseClientReactiveAdapter clientLibraryAdapter;
private List<Statement> statements = new ArrayList<>();
SpannerBatch(DatabaseClientReactiveAdapter clientLibraryAdapter) {
this.clientLibraryAdapter = clientLibraryAdapter;
}
@Override
public Batch add(String sql) {
Assert.requireNonNull(sql, "SQL must not be null."); | if (StatementParser.getStatementType(sql) != StatementType.DML) { |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerBatch.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementParser.java
// public class StatementParser {
//
// private static com.google.cloud.spanner.connection.AbstractStatementParser clientLibraryParser =
// com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(
// Dialect.GOOGLE_STANDARD_SQL);
//
// private StatementParser() {
// // Prevent instantiation.
// }
//
// /**
// * Returns the statement type of a given SQL string.
// *
// * @param sql the input SQL string.
// *
// * @return the type of statement of the SQL string.
// */
// public static StatementType getStatementType(String sql) {
// if (clientLibraryParser.isQuery(sql)) {
// return StatementType.SELECT;
// } else if (clientLibraryParser.isDdlStatement(sql)) {
// return StatementType.DDL;
// } else if (clientLibraryParser.isUpdateStatement(sql)) {
// return StatementType.DML;
// } else {
// return StatementType.UNKNOWN;
// }
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementType.java
// public enum StatementType {
// SELECT,
// DDL,
// DML,
// UNKNOWN;
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
| import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.r2dbc.statement.StatementParser;
import com.google.cloud.spanner.r2dbc.statement.StatementType;
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Result;
import java.util.ArrayList;
import java.util.List;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerBatch implements Batch {
private DatabaseClientReactiveAdapter clientLibraryAdapter;
private List<Statement> statements = new ArrayList<>();
SpannerBatch(DatabaseClientReactiveAdapter clientLibraryAdapter) {
this.clientLibraryAdapter = clientLibraryAdapter;
}
@Override
public Batch add(String sql) {
Assert.requireNonNull(sql, "SQL must not be null."); | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementParser.java
// public class StatementParser {
//
// private static com.google.cloud.spanner.connection.AbstractStatementParser clientLibraryParser =
// com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(
// Dialect.GOOGLE_STANDARD_SQL);
//
// private StatementParser() {
// // Prevent instantiation.
// }
//
// /**
// * Returns the statement type of a given SQL string.
// *
// * @param sql the input SQL string.
// *
// * @return the type of statement of the SQL string.
// */
// public static StatementType getStatementType(String sql) {
// if (clientLibraryParser.isQuery(sql)) {
// return StatementType.SELECT;
// } else if (clientLibraryParser.isDdlStatement(sql)) {
// return StatementType.DDL;
// } else if (clientLibraryParser.isUpdateStatement(sql)) {
// return StatementType.DML;
// } else {
// return StatementType.UNKNOWN;
// }
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementType.java
// public enum StatementType {
// SELECT,
// DDL,
// DML,
// UNKNOWN;
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerBatch.java
import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.r2dbc.statement.StatementParser;
import com.google.cloud.spanner.r2dbc.statement.StatementType;
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Result;
import java.util.ArrayList;
import java.util.List;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerBatch implements Batch {
private DatabaseClientReactiveAdapter clientLibraryAdapter;
private List<Statement> statements = new ArrayList<>();
SpannerBatch(DatabaseClientReactiveAdapter clientLibraryAdapter) {
this.clientLibraryAdapter = clientLibraryAdapter;
}
@Override
public Batch add(String sql) {
Assert.requireNonNull(sql, "SQL must not be null."); | if (StatementParser.getStatementType(sql) != StatementType.DML) { |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerDmlReactiveStreamVerification.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import org.reactivestreams.Publisher;
import org.reactivestreams.tck.PublisherVerification;
import org.reactivestreams.tck.TestEnvironment; | /*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class SpannerDmlReactiveStreamVerification extends
PublisherVerification<Integer> {
private static ConnectionFactory connectionFactory;
private static TestDatabaseHelper dbHelper;
@BeforeSuite
static void createConnectionFactory() {
connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId()) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerDmlReactiveStreamVerification.java
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import org.reactivestreams.Publisher;
import org.reactivestreams.tck.PublisherVerification;
import org.reactivestreams.tck.TestEnvironment;
/*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class SpannerDmlReactiveStreamVerification extends
PublisherVerification<Integer> {
private static ConnectionFactory connectionFactory;
private static TestDatabaseHelper dbHelper;
@BeforeSuite
static void createConnectionFactory() {
connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId()) | .option(DRIVER, DRIVER_NAME) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerDmlReactiveStreamVerification.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import org.reactivestreams.Publisher;
import org.reactivestreams.tck.PublisherVerification;
import org.reactivestreams.tck.TestEnvironment; | /*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class SpannerDmlReactiveStreamVerification extends
PublisherVerification<Integer> {
private static ConnectionFactory connectionFactory;
private static TestDatabaseHelper dbHelper;
@BeforeSuite
static void createConnectionFactory() {
connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerDmlReactiveStreamVerification.java
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import org.reactivestreams.Publisher;
import org.reactivestreams.tck.PublisherVerification;
import org.reactivestreams.tck.TestEnvironment;
/*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class SpannerDmlReactiveStreamVerification extends
PublisherVerification<Integer> {
private static ConnectionFactory connectionFactory;
private static TestDatabaseHelper dbHelper;
@BeforeSuite
static void createConnectionFactory() {
connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | .option(INSTANCE, DatabaseProperties.INSTANCE) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerSelectReactiveStreamVerification.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import org.reactivestreams.tck.TestEnvironment;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Row;
import org.reactivestreams.Publisher;
import org.reactivestreams.tck.PublisherVerification; | /*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class SpannerSelectReactiveStreamVerification extends
PublisherVerification<Row> {
private static ConnectionFactory connectionFactory;
private static TestDatabaseHelper dbHelper;
@BeforeSuite
static void createConnectionFactory() {
connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId()) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerSelectReactiveStreamVerification.java
import org.reactivestreams.tck.TestEnvironment;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Row;
import org.reactivestreams.Publisher;
import org.reactivestreams.tck.PublisherVerification;
/*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class SpannerSelectReactiveStreamVerification extends
PublisherVerification<Row> {
private static ConnectionFactory connectionFactory;
private static TestDatabaseHelper dbHelper;
@BeforeSuite
static void createConnectionFactory() {
connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId()) | .option(DRIVER, DRIVER_NAME) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerSelectReactiveStreamVerification.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import org.reactivestreams.tck.TestEnvironment;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Row;
import org.reactivestreams.Publisher;
import org.reactivestreams.tck.PublisherVerification; | /*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class SpannerSelectReactiveStreamVerification extends
PublisherVerification<Row> {
private static ConnectionFactory connectionFactory;
private static TestDatabaseHelper dbHelper;
@BeforeSuite
static void createConnectionFactory() {
connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/SpannerSelectReactiveStreamVerification.java
import org.reactivestreams.tck.TestEnvironment;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Row;
import org.reactivestreams.Publisher;
import org.reactivestreams.tck.PublisherVerification;
/*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class SpannerSelectReactiveStreamVerification extends
PublisherVerification<Row> {
private static ConnectionFactory connectionFactory;
private static TestDatabaseHelper dbHelper;
@BeforeSuite
static void createConnectionFactory() {
connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | .option(INSTANCE, DatabaseProperties.INSTANCE) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/ClientLibraryTypeBindersTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/BindingFailureException.java
// public class BindingFailureException extends R2dbcNonTransientException {
//
// public BindingFailureException(String message) {
// super(message);
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/TypedNull.java
// public class TypedNull {
//
// private final Class<?> type;
//
// public TypedNull(Class<?> type) {
// this.type = type;
// }
//
// public Class<?> getType() {
// return this.type;
// }
// }
| import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.withPrecision;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import com.google.cloud.ByteArray;
import com.google.cloud.Date;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.Statement.Builder;
import com.google.cloud.spanner.Value;
import com.google.cloud.spanner.ValueBinder;
import com.google.cloud.spanner.r2dbc.BindingFailureException;
import com.google.cloud.spanner.r2dbc.statement.TypedNull;
import io.r2dbc.spi.Parameters;
import io.r2dbc.spi.R2dbcType;
import java.math.BigDecimal;
import java.util.Random;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class ClientLibraryTypeBindersTest {
ValueBinder valueBinder;
ValueBinder nullBinder;
Builder statementBuilder;
@BeforeEach
public void setUp() {
this.valueBinder = Mockito.mock(ValueBinder.class);
this.nullBinder = Mockito.mock(ValueBinder.class);
this.statementBuilder = Mockito.mock(Builder.class);
when(this.statementBuilder.bind("valueColumn")).thenReturn(this.valueBinder);
when(this.statementBuilder.bind("nullColumn")).thenReturn(this.nullBinder);
}
@Test
void unsupportedTypeThrowsException() {
Random rand = new Random();
assertThatThrownBy(() -> ClientLibraryBinder.bind(this.statementBuilder, "valueColumn", rand)) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/BindingFailureException.java
// public class BindingFailureException extends R2dbcNonTransientException {
//
// public BindingFailureException(String message) {
// super(message);
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/TypedNull.java
// public class TypedNull {
//
// private final Class<?> type;
//
// public TypedNull(Class<?> type) {
// this.type = type;
// }
//
// public Class<?> getType() {
// return this.type;
// }
// }
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/ClientLibraryTypeBindersTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.withPrecision;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import com.google.cloud.ByteArray;
import com.google.cloud.Date;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.Statement.Builder;
import com.google.cloud.spanner.Value;
import com.google.cloud.spanner.ValueBinder;
import com.google.cloud.spanner.r2dbc.BindingFailureException;
import com.google.cloud.spanner.r2dbc.statement.TypedNull;
import io.r2dbc.spi.Parameters;
import io.r2dbc.spi.R2dbcType;
import java.math.BigDecimal;
import java.util.Random;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class ClientLibraryTypeBindersTest {
ValueBinder valueBinder;
ValueBinder nullBinder;
Builder statementBuilder;
@BeforeEach
public void setUp() {
this.valueBinder = Mockito.mock(ValueBinder.class);
this.nullBinder = Mockito.mock(ValueBinder.class);
this.statementBuilder = Mockito.mock(Builder.class);
when(this.statementBuilder.bind("valueColumn")).thenReturn(this.valueBinder);
when(this.statementBuilder.bind("nullColumn")).thenReturn(this.nullBinder);
}
@Test
void unsupportedTypeThrowsException() {
Random rand = new Random();
assertThatThrownBy(() -> ClientLibraryBinder.bind(this.statementBuilder, "valueColumn", rand)) | .isInstanceOf(BindingFailureException.class) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/ClientLibraryTypeBindersTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/BindingFailureException.java
// public class BindingFailureException extends R2dbcNonTransientException {
//
// public BindingFailureException(String message) {
// super(message);
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/TypedNull.java
// public class TypedNull {
//
// private final Class<?> type;
//
// public TypedNull(Class<?> type) {
// this.type = type;
// }
//
// public Class<?> getType() {
// return this.type;
// }
// }
| import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.withPrecision;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import com.google.cloud.ByteArray;
import com.google.cloud.Date;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.Statement.Builder;
import com.google.cloud.spanner.Value;
import com.google.cloud.spanner.ValueBinder;
import com.google.cloud.spanner.r2dbc.BindingFailureException;
import com.google.cloud.spanner.r2dbc.statement.TypedNull;
import io.r2dbc.spi.Parameters;
import io.r2dbc.spi.R2dbcType;
import java.math.BigDecimal;
import java.util.Random;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class ClientLibraryTypeBindersTest {
ValueBinder valueBinder;
ValueBinder nullBinder;
Builder statementBuilder;
@BeforeEach
public void setUp() {
this.valueBinder = Mockito.mock(ValueBinder.class);
this.nullBinder = Mockito.mock(ValueBinder.class);
this.statementBuilder = Mockito.mock(Builder.class);
when(this.statementBuilder.bind("valueColumn")).thenReturn(this.valueBinder);
when(this.statementBuilder.bind("nullColumn")).thenReturn(this.nullBinder);
}
@Test
void unsupportedTypeThrowsException() {
Random rand = new Random();
assertThatThrownBy(() -> ClientLibraryBinder.bind(this.statementBuilder, "valueColumn", rand))
.isInstanceOf(BindingFailureException.class)
.hasMessageContaining("Can't find a binder for type: class java.util.Random");
| // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/BindingFailureException.java
// public class BindingFailureException extends R2dbcNonTransientException {
//
// public BindingFailureException(String message) {
// super(message);
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/TypedNull.java
// public class TypedNull {
//
// private final Class<?> type;
//
// public TypedNull(Class<?> type) {
// this.type = type;
// }
//
// public Class<?> getType() {
// return this.type;
// }
// }
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/ClientLibraryTypeBindersTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.withPrecision;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import com.google.cloud.ByteArray;
import com.google.cloud.Date;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.Statement.Builder;
import com.google.cloud.spanner.Value;
import com.google.cloud.spanner.ValueBinder;
import com.google.cloud.spanner.r2dbc.BindingFailureException;
import com.google.cloud.spanner.r2dbc.statement.TypedNull;
import io.r2dbc.spi.Parameters;
import io.r2dbc.spi.R2dbcType;
import java.math.BigDecimal;
import java.util.Random;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class ClientLibraryTypeBindersTest {
ValueBinder valueBinder;
ValueBinder nullBinder;
Builder statementBuilder;
@BeforeEach
public void setUp() {
this.valueBinder = Mockito.mock(ValueBinder.class);
this.nullBinder = Mockito.mock(ValueBinder.class);
this.statementBuilder = Mockito.mock(Builder.class);
when(this.statementBuilder.bind("valueColumn")).thenReturn(this.valueBinder);
when(this.statementBuilder.bind("nullColumn")).thenReturn(this.nullBinder);
}
@Test
void unsupportedTypeThrowsException() {
Random rand = new Random();
assertThatThrownBy(() -> ClientLibraryBinder.bind(this.statementBuilder, "valueColumn", rand))
.isInstanceOf(BindingFailureException.class)
.hasMessageContaining("Can't find a binder for type: class java.util.Random");
| TypedNull randNull = new TypedNull(Random.class); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-spring-data-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/springdata/SpannerR2dbcDialectTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
| import org.springframework.data.relational.core.sql.Table;
import org.springframework.r2dbc.core.binding.BindMarkers;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import java.util.Collection;
import org.junit.jupiter.api.Test;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.relational.core.dialect.LimitClause;
import org.springframework.data.relational.core.dialect.LockClause;
import org.springframework.data.relational.core.sql.LockMode;
import org.springframework.data.relational.core.sql.LockOptions;
import org.springframework.data.relational.core.sql.SQL;
import org.springframework.data.relational.core.sql.Select; |
@Test
void testBindMarkersFactory() {
SpannerR2dbcDialect dialect = new SpannerR2dbcDialect();
BindMarkers bindMarkers = dialect.getBindMarkersFactory().create();
assertThat(bindMarkers).isNotNull();
assertThat(bindMarkers.next().getPlaceholder()).isEqualTo("@val0");
assertThat(bindMarkers.next().getPlaceholder()).isEqualTo("@val1");
}
@Test
void lockStringAlwaysEmpty() {
SpannerR2dbcDialect dialect = new SpannerR2dbcDialect();
Table table = SQL.table("aTable");
Select sql = Select.builder().select(table.column("aColumn"))
.from(table)
.build();
LockOptions lockOptions = new LockOptions(LockMode.PESSIMISTIC_READ, sql.getFrom());
LockClause lock = dialect.lock();
assertNotNull(lock);
assertThat(lock.getLock(lockOptions)).isEmpty();
assertThat(lock.getClausePosition()).isSameAs(LockClause.Position.AFTER_FROM_TABLE);
}
@Test
void testSimpleType() {
SpannerR2dbcDialect dialect = new SpannerR2dbcDialect();
SimpleTypeHolder simpleTypeHolder = dialect.getSimpleTypeHolder(); | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
// Path: cloud-spanner-spring-data-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/springdata/SpannerR2dbcDialectTest.java
import org.springframework.data.relational.core.sql.Table;
import org.springframework.r2dbc.core.binding.BindMarkers;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import java.util.Collection;
import org.junit.jupiter.api.Test;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.relational.core.dialect.LimitClause;
import org.springframework.data.relational.core.dialect.LockClause;
import org.springframework.data.relational.core.sql.LockMode;
import org.springframework.data.relational.core.sql.LockOptions;
import org.springframework.data.relational.core.sql.SQL;
import org.springframework.data.relational.core.sql.Select;
@Test
void testBindMarkersFactory() {
SpannerR2dbcDialect dialect = new SpannerR2dbcDialect();
BindMarkers bindMarkers = dialect.getBindMarkersFactory().create();
assertThat(bindMarkers).isNotNull();
assertThat(bindMarkers.next().getPlaceholder()).isEqualTo("@val0");
assertThat(bindMarkers.next().getPlaceholder()).isEqualTo("@val1");
}
@Test
void lockStringAlwaysEmpty() {
SpannerR2dbcDialect dialect = new SpannerR2dbcDialect();
Table table = SQL.table("aTable");
Select sql = Select.builder().select(table.column("aColumn"))
.from(table)
.build();
LockOptions lockOptions = new LockOptions(LockMode.PESSIMISTIC_READ, sql.getFrom());
LockClause lock = dialect.lock();
assertNotNull(lock);
assertThat(lock.getLock(lockOptions)).isEmpty();
assertThat(lock.getClausePosition()).isSameAs(LockClause.Position.AFTER_FROM_TABLE);
}
@Test
void testSimpleType() {
SpannerR2dbcDialect dialect = new SpannerR2dbcDialect();
SimpleTypeHolder simpleTypeHolder = dialect.getSimpleTypeHolder(); | assertThat(simpleTypeHolder.isSimpleType(JsonWrapper.class)).isTrue(); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConvertersTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import com.google.cloud.spanner.r2dbc.ConversionFailureException;
import org.junit.jupiter.api.Test; | /*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerClientLibraryConvertersTest {
@Test
void convertTest() {
assertThat(
SpannerClientLibraryConverters.convert(
"{\"rating\":9,\"open\":true}", JsonWrapper.class))
.isInstanceOf(JsonWrapper.class)
.isEqualTo(JsonWrapper.of("{\"rating\":9,\"open\":true}"));
assertThatThrownBy(() -> SpannerClientLibraryConverters.convert(1234L, JsonWrapper.class)) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConvertersTest.java
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import com.google.cloud.spanner.r2dbc.ConversionFailureException;
import org.junit.jupiter.api.Test;
/*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class SpannerClientLibraryConvertersTest {
@Test
void convertTest() {
assertThat(
SpannerClientLibraryConverters.convert(
"{\"rating\":9,\"open\":true}", JsonWrapper.class))
.isInstanceOf(JsonWrapper.class)
.isEqualTo(JsonWrapper.of("{\"rating\":9,\"open\":true}"));
assertThatThrownBy(() -> SpannerClientLibraryConverters.convert(1234L, JsonWrapper.class)) | .isInstanceOf(ConversionFailureException.class) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/StringToJsonConverterTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
| import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import com.google.cloud.spanner.r2dbc.ConversionFailureException;
import org.assertj.core.api.AssertionsForClassTypes;
import org.junit.jupiter.api.Test; | /*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class StringToJsonConverterTest {
@Test
void canConvert() {
StringToJsonConverter converter = new StringToJsonConverter();
assertThat(converter.canConvert(Long.class, JsonWrapper.class)).isFalse();
assertThat(converter.canConvert(String.class, Long.class)).isFalse();
assertThat(converter.canConvert(String.class, JsonWrapper.class)).isTrue();
}
@Test
void convert() {
StringToJsonConverter converter = new StringToJsonConverter();
AssertionsForClassTypes.assertThat(
converter.convert(
"{\"rating\":9,\"open\":true}"))
.isInstanceOf(JsonWrapper.class)
.isEqualTo(JsonWrapper.of("{\"rating\":9,\"open\":true}"));
assertThatThrownBy(() -> converter.convert(1234L)) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/ConversionFailureException.java
// public class ConversionFailureException extends R2dbcNonTransientException {
//
// public ConversionFailureException(String message) {
// super(message);
// }
// }
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/StringToJsonConverterTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
import com.google.cloud.spanner.r2dbc.ConversionFailureException;
import org.assertj.core.api.AssertionsForClassTypes;
import org.junit.jupiter.api.Test;
/*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class StringToJsonConverterTest {
@Test
void canConvert() {
StringToJsonConverter converter = new StringToJsonConverter();
assertThat(converter.canConvert(Long.class, JsonWrapper.class)).isFalse();
assertThat(converter.canConvert(String.class, Long.class)).isFalse();
assertThat(converter.canConvert(String.class, JsonWrapper.class)).isTrue();
}
@Test
void convert() {
StringToJsonConverter converter = new StringToJsonConverter();
AssertionsForClassTypes.assertThat(
converter.convert(
"{\"rating\":9,\"open\":true}"))
.isInstanceOf(JsonWrapper.class)
.isEqualTo(JsonWrapper.of("{\"rating\":9,\"open\":true}"));
assertThatThrownBy(() -> converter.convert(1234L)) | .isInstanceOf(ConversionFailureException.class) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionConfiguration.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
| import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.OAuth2Credentials;
import com.google.cloud.spanner.SpannerOptions;
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.R2dbcNonTransientResourceException;
import java.io.IOException;
import java.time.Duration;
import java.util.Collections;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc;
/**
* Configurable properties for Cloud Spanner.
*/
public class SpannerConnectionConfiguration {
public static final String FQDN_PATTERN_GENERATE =
"projects/%s/instances/%s/databases/%s";
/** Pattern used to validate that the user input database string is in the right format. */
public static final Pattern FQDN_PATTERN_PARSE = Pattern.compile(
"projects\\/([\\w\\-]+)\\/instances\\/([\\w\\-]+)\\/databases\\/([\\w\\-]+)$");
private static final String USER_AGENT_LIBRARY_NAME = "cloud-spanner-r2dbc";
private static final String PACKAGE_VERSION =
SpannerConnectionConfiguration.class.getPackage().getImplementationVersion();
private static final String USER_AGENT_KEY = "user-agent";
// TODO: check how to handle full URL (it gets parsed by SPI, we only get pieces)
private final String fullyQualifiedDbName;
private String projectId;
private String instanceName;
private String databaseName;
private final OAuth2Credentials credentials;
private int partialResultSetFetchSize;
private Duration ddlOperationTimeout;
private Duration ddlOperationPollInterval;
private boolean usePlainText;
private String optimizerVersion;
private boolean readonly;
private boolean autocommit;
/**
* Basic property initializing constructor.
*
* @param projectId GCP project that contains the database.
* @param instanceName instance to connect to
* @param databaseName database to connect to.
* @param credentials GCP credentials to authenticate service calls with.
*/
private SpannerConnectionConfiguration(
String projectId,
String instanceName,
String databaseName,
OAuth2Credentials credentials) {
| // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/util/Assert.java
// public class Assert {
//
// private Assert() {
// // Prevent instantiation.
// }
//
// /**
// * Checks that a specified object reference is not {@code null} and throws a customized
// * {@link IllegalArgumentException} if it is.
// *
// * @param t the object reference to check for nullity
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// * @param <T> the type of object reference
// *
// * @return the original object {@code t}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static <T> T requireNonNull(@Nullable T t, String message) {
// if (t == null) {
// throw new IllegalArgumentException(message);
// }
//
// return t;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static ByteString requireNonEmpty(@Nullable ByteString s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// /**
// * Checks that a specified object reference is not {@code null} or an empty string, and throws a
// * customized {@link IllegalArgumentException} if it is.
// *
// * @param s string to check
// * @param message informative message to be used in the event that an
// * {@link IllegalArgumentException} is thrown
// *
// * @return the original string {@code s}
// *
// * @throws IllegalArgumentException if {@code o} is {@code null}
// */
// public static String requireNonEmpty(@Nullable String s, String message) {
// if (s == null || s.isEmpty()) {
// throw new IllegalArgumentException(message);
// }
//
// return s;
// }
//
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionConfiguration.java
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auth.oauth2.OAuth2Credentials;
import com.google.cloud.spanner.SpannerOptions;
import com.google.cloud.spanner.r2dbc.util.Assert;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.R2dbcNonTransientResourceException;
import java.io.IOException;
import java.time.Duration;
import java.util.Collections;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc;
/**
* Configurable properties for Cloud Spanner.
*/
public class SpannerConnectionConfiguration {
public static final String FQDN_PATTERN_GENERATE =
"projects/%s/instances/%s/databases/%s";
/** Pattern used to validate that the user input database string is in the right format. */
public static final Pattern FQDN_PATTERN_PARSE = Pattern.compile(
"projects\\/([\\w\\-]+)\\/instances\\/([\\w\\-]+)\\/databases\\/([\\w\\-]+)$");
private static final String USER_AGENT_LIBRARY_NAME = "cloud-spanner-r2dbc";
private static final String PACKAGE_VERSION =
SpannerConnectionConfiguration.class.getPackage().getImplementationVersion();
private static final String USER_AGENT_KEY = "user-agent";
// TODO: check how to handle full URL (it gets parsed by SPI, we only get pieces)
private final String fullyQualifiedDbName;
private String projectId;
private String instanceName;
private String databaseName;
private final OAuth2Credentials credentials;
private int partialResultSetFetchSize;
private Duration ddlOperationTimeout;
private Duration ddlOperationPollInterval;
private boolean usePlainText;
private String optimizerVersion;
private boolean readonly;
private boolean autocommit;
/**
* Basic property initializing constructor.
*
* @param projectId GCP project that contains the database.
* @param instanceName instance to connect to
* @param databaseName database to connect to.
* @param credentials GCP credentials to authenticate service calls with.
*/
private SpannerConnectionConfiguration(
String projectId,
String instanceName,
String databaseName,
OAuth2Credentials credentials) {
| Assert.requireNonNull(projectId, "projectId must not be null"); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc-samples/cloud-spanner-spring-data-r2dbc-sample/src/main/java/com/example/SpringDataR2dbcApp.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import java.net.URI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.util.Assert;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Hooks; | /*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example;
/**
* Driver application showing Cloud Spanner R2DBC use with Spring Data.
*/
@SpringBootApplication
@EnableR2dbcRepositories
public class SpringDataR2dbcApp {
private static final Logger LOGGER = LoggerFactory.getLogger(SpringDataR2dbcApp.class);
private static final String SPANNER_INSTANCE = System.getProperty("spanner.instance");
private static final String SPANNER_DATABASE = System.getProperty("spanner.database");
private static final String GCP_PROJECT = System.getProperty("gcp.project");
@Autowired
private DatabaseClient r2dbcClient;
public static void main(String[] args) {
Hooks.onOperatorDebug(); | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc-samples/cloud-spanner-spring-data-r2dbc-sample/src/main/java/com/example/SpringDataR2dbcApp.java
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import java.net.URI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.util.Assert;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Hooks;
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example;
/**
* Driver application showing Cloud Spanner R2DBC use with Spring Data.
*/
@SpringBootApplication
@EnableR2dbcRepositories
public class SpringDataR2dbcApp {
private static final Logger LOGGER = LoggerFactory.getLogger(SpringDataR2dbcApp.class);
private static final String SPANNER_INSTANCE = System.getProperty("spanner.instance");
private static final String SPANNER_DATABASE = System.getProperty("spanner.database");
private static final String GCP_PROJECT = System.getProperty("gcp.project");
@Autowired
private DatabaseClient r2dbcClient;
public static void main(String[] args) {
Hooks.onOperatorDebug(); | Assert.notNull(INSTANCE, "Please provide spanner.instance property"); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-spring-data-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/springdata/SpannerBindMarkerFactoryProvider.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryMetadata.java
// public class SpannerConnectionFactoryMetadata implements ConnectionFactoryMetadata {
//
// /**
// * The name of Cloud Spanner database product.
// */
// public static final String NAME = "Cloud Spanner";
//
// public static final SpannerConnectionFactoryMetadata INSTANCE
// = new SpannerConnectionFactoryMetadata();
//
// private SpannerConnectionFactoryMetadata() {
// }
//
// @Override
// public String getName() {
// return NAME;
// }
//
// }
| import com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryMetadata;
import io.r2dbc.spi.ConnectionFactory;
import org.springframework.r2dbc.core.binding.BindMarkersFactory;
import org.springframework.r2dbc.core.binding.BindMarkersFactoryResolver.BindMarkerFactoryProvider; | /*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.springdata;
/**
* Provides the named bind marker strategy for Cloud Spanner.
*/
public class SpannerBindMarkerFactoryProvider implements BindMarkerFactoryProvider {
@Override
public BindMarkersFactory getBindMarkers(ConnectionFactory connectionFactory) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryMetadata.java
// public class SpannerConnectionFactoryMetadata implements ConnectionFactoryMetadata {
//
// /**
// * The name of Cloud Spanner database product.
// */
// public static final String NAME = "Cloud Spanner";
//
// public static final SpannerConnectionFactoryMetadata INSTANCE
// = new SpannerConnectionFactoryMetadata();
//
// private SpannerConnectionFactoryMetadata() {
// }
//
// @Override
// public String getName() {
// return NAME;
// }
//
// }
// Path: cloud-spanner-spring-data-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/springdata/SpannerBindMarkerFactoryProvider.java
import com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryMetadata;
import io.r2dbc.spi.ConnectionFactory;
import org.springframework.r2dbc.core.binding.BindMarkersFactory;
import org.springframework.r2dbc.core.binding.BindMarkersFactoryResolver.BindMarkerFactoryProvider;
/*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.springdata;
/**
* Provides the named bind marker strategy for Cloud Spanner.
*/
public class SpannerBindMarkerFactoryProvider implements BindMarkerFactoryProvider {
@Override
public BindMarkersFactory getBindMarkers(ConnectionFactory connectionFactory) { | if (SpannerConnectionFactoryMetadata.INSTANCE.equals(connectionFactory.getMetadata())) { |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc-samples/cloud-spanner-spring-data-r2dbc-sample/src/main/java/com/example/CustomConfiguration.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
| import java.util.ArrayList;
import java.util.List;
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import io.r2dbc.spi.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
import org.springframework.data.r2dbc.convert.R2dbcCustomConversions;
import org.springframework.stereotype.Component; | /*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example;
@Configuration
public class CustomConfiguration extends AbstractR2dbcConfiguration {
@Autowired
ApplicationContext applicationContext;
@Override
public ConnectionFactory connectionFactory() {
return null;
}
@Bean
@Override
public R2dbcCustomConversions r2dbcCustomConversions() {
List<Converter<?, ?>> converters = new ArrayList<>();
converters.add(this.applicationContext.getBean(JsonToReviewsConverter.class));
converters.add(this.applicationContext.getBean(ReviewsToJsonConverter.class));
return new R2dbcCustomConversions(getStoreConversions(), converters);
}
@Component
@ReadingConverter | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
// Path: cloud-spanner-r2dbc-samples/cloud-spanner-spring-data-r2dbc-sample/src/main/java/com/example/CustomConfiguration.java
import java.util.ArrayList;
import java.util.List;
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import io.r2dbc.spi.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
import org.springframework.data.r2dbc.convert.R2dbcCustomConversions;
import org.springframework.stereotype.Component;
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example;
@Configuration
public class CustomConfiguration extends AbstractR2dbcConfiguration {
@Autowired
ApplicationContext applicationContext;
@Override
public ConnectionFactory connectionFactory() {
return null;
}
@Bean
@Override
public R2dbcCustomConversions r2dbcCustomConversions() {
List<Converter<?, ?>> converters = new ArrayList<>();
converters.add(this.applicationContext.getBean(JsonToReviewsConverter.class));
converters.add(this.applicationContext.getBean(ReviewsToJsonConverter.class));
return new R2dbcCustomConversions(getStoreConversions(), converters);
}
@Component
@ReadingConverter | public class JsonToReviewsConverter implements Converter<JsonWrapper, Review> { |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/api/SpannerConnection.java
// public interface SpannerConnection {
// /**
// * Allows starting a readonly Cloud Spanner transaction with given staleness settings.
// *
// * @param timestampBound staleness settings
// *
// * @return {@link Mono} signaling readonly transaction is ready for use
// */
// Mono<Void> beginReadonlyTransaction(TimestampBound timestampBound);
//
// /**
// * Allows starting a readonly Cloud Spanner transaction with strong consistency.
// *
// * @return {@link Mono} signaling readonly transaction is ready for use
// */
// Mono<Void> beginReadonlyTransaction();
//
// boolean isInReadonlyTransaction();
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementParser.java
// public class StatementParser {
//
// private static com.google.cloud.spanner.connection.AbstractStatementParser clientLibraryParser =
// com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(
// Dialect.GOOGLE_STANDARD_SQL);
//
// private StatementParser() {
// // Prevent instantiation.
// }
//
// /**
// * Returns the statement type of a given SQL string.
// *
// * @param sql the input SQL string.
// *
// * @return the type of statement of the SQL string.
// */
// public static StatementType getStatementType(String sql) {
// if (clientLibraryParser.isQuery(sql)) {
// return StatementType.SELECT;
// } else if (clientLibraryParser.isDdlStatement(sql)) {
// return StatementType.DDL;
// } else if (clientLibraryParser.isUpdateStatement(sql)) {
// return StatementType.DML;
// } else {
// return StatementType.UNKNOWN;
// }
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementType.java
// public enum StatementType {
// SELECT,
// DDL,
// DML,
// UNKNOWN;
// }
| import com.google.cloud.spanner.TimestampBound;
import com.google.cloud.spanner.r2dbc.api.SpannerConnection;
import com.google.cloud.spanner.r2dbc.statement.StatementParser;
import com.google.cloud.spanner.r2dbc.statement.StatementType;
import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionMetadata;
import io.r2dbc.spi.IsolationLevel;
import io.r2dbc.spi.Statement;
import io.r2dbc.spi.TransactionDefinition;
import io.r2dbc.spi.ValidationDepth;
import java.time.Duration;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono; | @Override
public Mono<Void> beginReadonlyTransaction(TimestampBound timestampBound) {
return this.clientLibraryAdapter.beginReadonlyTransaction(timestampBound);
}
@Override
public Mono<Void> beginReadonlyTransaction() {
return this.clientLibraryAdapter.beginReadonlyTransaction(TimestampBound.strong());
}
@Override
public Publisher<Void> commitTransaction() {
return this.clientLibraryAdapter.commitTransaction();
}
@Override
public Batch createBatch() {
return new SpannerBatch(this.clientLibraryAdapter);
}
@Override
public Publisher<Void> createSavepoint(String name) {
throw new UnsupportedOperationException();
}
@Override
public Statement createStatement(String query) {
if (query == null) {
throw new IllegalArgumentException("Invalid null query.");
} | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/api/SpannerConnection.java
// public interface SpannerConnection {
// /**
// * Allows starting a readonly Cloud Spanner transaction with given staleness settings.
// *
// * @param timestampBound staleness settings
// *
// * @return {@link Mono} signaling readonly transaction is ready for use
// */
// Mono<Void> beginReadonlyTransaction(TimestampBound timestampBound);
//
// /**
// * Allows starting a readonly Cloud Spanner transaction with strong consistency.
// *
// * @return {@link Mono} signaling readonly transaction is ready for use
// */
// Mono<Void> beginReadonlyTransaction();
//
// boolean isInReadonlyTransaction();
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementParser.java
// public class StatementParser {
//
// private static com.google.cloud.spanner.connection.AbstractStatementParser clientLibraryParser =
// com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(
// Dialect.GOOGLE_STANDARD_SQL);
//
// private StatementParser() {
// // Prevent instantiation.
// }
//
// /**
// * Returns the statement type of a given SQL string.
// *
// * @param sql the input SQL string.
// *
// * @return the type of statement of the SQL string.
// */
// public static StatementType getStatementType(String sql) {
// if (clientLibraryParser.isQuery(sql)) {
// return StatementType.SELECT;
// } else if (clientLibraryParser.isDdlStatement(sql)) {
// return StatementType.DDL;
// } else if (clientLibraryParser.isUpdateStatement(sql)) {
// return StatementType.DML;
// } else {
// return StatementType.UNKNOWN;
// }
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementType.java
// public enum StatementType {
// SELECT,
// DDL,
// DML,
// UNKNOWN;
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java
import com.google.cloud.spanner.TimestampBound;
import com.google.cloud.spanner.r2dbc.api.SpannerConnection;
import com.google.cloud.spanner.r2dbc.statement.StatementParser;
import com.google.cloud.spanner.r2dbc.statement.StatementType;
import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionMetadata;
import io.r2dbc.spi.IsolationLevel;
import io.r2dbc.spi.Statement;
import io.r2dbc.spi.TransactionDefinition;
import io.r2dbc.spi.ValidationDepth;
import java.time.Duration;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
@Override
public Mono<Void> beginReadonlyTransaction(TimestampBound timestampBound) {
return this.clientLibraryAdapter.beginReadonlyTransaction(timestampBound);
}
@Override
public Mono<Void> beginReadonlyTransaction() {
return this.clientLibraryAdapter.beginReadonlyTransaction(TimestampBound.strong());
}
@Override
public Publisher<Void> commitTransaction() {
return this.clientLibraryAdapter.commitTransaction();
}
@Override
public Batch createBatch() {
return new SpannerBatch(this.clientLibraryAdapter);
}
@Override
public Publisher<Void> createSavepoint(String name) {
throw new UnsupportedOperationException();
}
@Override
public Statement createStatement(String query) {
if (query == null) {
throw new IllegalArgumentException("Invalid null query.");
} | StatementType type = StatementParser.getStatementType(query); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/api/SpannerConnection.java
// public interface SpannerConnection {
// /**
// * Allows starting a readonly Cloud Spanner transaction with given staleness settings.
// *
// * @param timestampBound staleness settings
// *
// * @return {@link Mono} signaling readonly transaction is ready for use
// */
// Mono<Void> beginReadonlyTransaction(TimestampBound timestampBound);
//
// /**
// * Allows starting a readonly Cloud Spanner transaction with strong consistency.
// *
// * @return {@link Mono} signaling readonly transaction is ready for use
// */
// Mono<Void> beginReadonlyTransaction();
//
// boolean isInReadonlyTransaction();
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementParser.java
// public class StatementParser {
//
// private static com.google.cloud.spanner.connection.AbstractStatementParser clientLibraryParser =
// com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(
// Dialect.GOOGLE_STANDARD_SQL);
//
// private StatementParser() {
// // Prevent instantiation.
// }
//
// /**
// * Returns the statement type of a given SQL string.
// *
// * @param sql the input SQL string.
// *
// * @return the type of statement of the SQL string.
// */
// public static StatementType getStatementType(String sql) {
// if (clientLibraryParser.isQuery(sql)) {
// return StatementType.SELECT;
// } else if (clientLibraryParser.isDdlStatement(sql)) {
// return StatementType.DDL;
// } else if (clientLibraryParser.isUpdateStatement(sql)) {
// return StatementType.DML;
// } else {
// return StatementType.UNKNOWN;
// }
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementType.java
// public enum StatementType {
// SELECT,
// DDL,
// DML,
// UNKNOWN;
// }
| import com.google.cloud.spanner.TimestampBound;
import com.google.cloud.spanner.r2dbc.api.SpannerConnection;
import com.google.cloud.spanner.r2dbc.statement.StatementParser;
import com.google.cloud.spanner.r2dbc.statement.StatementType;
import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionMetadata;
import io.r2dbc.spi.IsolationLevel;
import io.r2dbc.spi.Statement;
import io.r2dbc.spi.TransactionDefinition;
import io.r2dbc.spi.ValidationDepth;
import java.time.Duration;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono; | @Override
public Mono<Void> beginReadonlyTransaction(TimestampBound timestampBound) {
return this.clientLibraryAdapter.beginReadonlyTransaction(timestampBound);
}
@Override
public Mono<Void> beginReadonlyTransaction() {
return this.clientLibraryAdapter.beginReadonlyTransaction(TimestampBound.strong());
}
@Override
public Publisher<Void> commitTransaction() {
return this.clientLibraryAdapter.commitTransaction();
}
@Override
public Batch createBatch() {
return new SpannerBatch(this.clientLibraryAdapter);
}
@Override
public Publisher<Void> createSavepoint(String name) {
throw new UnsupportedOperationException();
}
@Override
public Statement createStatement(String query) {
if (query == null) {
throw new IllegalArgumentException("Invalid null query.");
} | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/api/SpannerConnection.java
// public interface SpannerConnection {
// /**
// * Allows starting a readonly Cloud Spanner transaction with given staleness settings.
// *
// * @param timestampBound staleness settings
// *
// * @return {@link Mono} signaling readonly transaction is ready for use
// */
// Mono<Void> beginReadonlyTransaction(TimestampBound timestampBound);
//
// /**
// * Allows starting a readonly Cloud Spanner transaction with strong consistency.
// *
// * @return {@link Mono} signaling readonly transaction is ready for use
// */
// Mono<Void> beginReadonlyTransaction();
//
// boolean isInReadonlyTransaction();
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementParser.java
// public class StatementParser {
//
// private static com.google.cloud.spanner.connection.AbstractStatementParser clientLibraryParser =
// com.google.cloud.spanner.connection.AbstractStatementParser.getInstance(
// Dialect.GOOGLE_STANDARD_SQL);
//
// private StatementParser() {
// // Prevent instantiation.
// }
//
// /**
// * Returns the statement type of a given SQL string.
// *
// * @param sql the input SQL string.
// *
// * @return the type of statement of the SQL string.
// */
// public static StatementType getStatementType(String sql) {
// if (clientLibraryParser.isQuery(sql)) {
// return StatementType.SELECT;
// } else if (clientLibraryParser.isDdlStatement(sql)) {
// return StatementType.DDL;
// } else if (clientLibraryParser.isUpdateStatement(sql)) {
// return StatementType.DML;
// } else {
// return StatementType.UNKNOWN;
// }
// }
// }
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/statement/StatementType.java
// public enum StatementType {
// SELECT,
// DDL,
// DML,
// UNKNOWN;
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java
import com.google.cloud.spanner.TimestampBound;
import com.google.cloud.spanner.r2dbc.api.SpannerConnection;
import com.google.cloud.spanner.r2dbc.statement.StatementParser;
import com.google.cloud.spanner.r2dbc.statement.StatementType;
import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionMetadata;
import io.r2dbc.spi.IsolationLevel;
import io.r2dbc.spi.Statement;
import io.r2dbc.spi.TransactionDefinition;
import io.r2dbc.spi.ValidationDepth;
import java.time.Duration;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
@Override
public Mono<Void> beginReadonlyTransaction(TimestampBound timestampBound) {
return this.clientLibraryAdapter.beginReadonlyTransaction(timestampBound);
}
@Override
public Mono<Void> beginReadonlyTransaction() {
return this.clientLibraryAdapter.beginReadonlyTransaction(TimestampBound.strong());
}
@Override
public Publisher<Void> commitTransaction() {
return this.clientLibraryAdapter.commitTransaction();
}
@Override
public Batch createBatch() {
return new SpannerBatch(this.clientLibraryAdapter);
}
@Override
public Publisher<Void> createSavepoint(String name) {
throw new UnsupportedOperationException();
}
@Override
public Statement createStatement(String query) {
if (query == null) {
throw new IllegalArgumentException("Invalid null query.");
} | StatementType type = StatementParser.getStatementType(query); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/DatabaseClientTransactionManager.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/DatabaseClientReactiveAdapter.java
// public static final Executor REACTOR_EXECUTOR =
// runnable -> Schedulers.parallel().schedule(runnable);
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/TransactionInProgressException.java
// public class TransactionInProgressException extends R2dbcNonTransientException {
//
// public static final String MSG_READONLY =
// "Cannot begin a new transaction because a readonly transaction is already in progress.";
// public static final String MSG_READWRITE =
// "Cannot begin a new transaction because a read/write transaction is already in progress.";
//
// public TransactionInProgressException(boolean isReadwrite) {
// super(isReadwrite ? MSG_READWRITE : MSG_READONLY);
// }
//
// }
| import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.cloud.spanner.r2dbc.v2.DatabaseClientReactiveAdapter.REACTOR_EXECUTOR;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.AsyncTransactionManager;
import com.google.cloud.spanner.AsyncTransactionManager.AsyncTransactionStep;
import com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture;
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.ReadContext;
import com.google.cloud.spanner.ReadOnlyTransaction;
import com.google.cloud.spanner.TimestampBound;
import com.google.cloud.spanner.TransactionContext;
import com.google.cloud.spanner.r2dbc.TransactionInProgressException; | /*
* Copyright 2020-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
/**
* Helper class encapsulating read/write and readonly transaction management for client library
* based interaction with Cloud Spanner.
* Partitioned DML is out of scope for transaction handling, as they are not atomic.
*/
class DatabaseClientTransactionManager {
private static final Logger LOGGER =
LoggerFactory.getLogger(DatabaseClientTransactionManager.class);
private final DatabaseClient dbClient;
private AsyncTransactionManager transactionManager;
private TransactionContextFuture txnContextFuture;
private ReadOnlyTransaction readOnlyTransaction;
private AsyncTransactionStep<?, ? extends Object> lastStep;
public DatabaseClientTransactionManager(DatabaseClient dbClient) {
this.dbClient = dbClient;
}
boolean isInReadWriteTransaction() {
return this.txnContextFuture != null;
}
boolean isInReadonlyTransaction() {
return this.readOnlyTransaction != null;
}
boolean isInTransaction() {
return isInReadWriteTransaction() || isInReadonlyTransaction();
}
/**
* Starts a Cloud Spanner Read/Write transaction.
*
* @return chainable {@link TransactionContextFuture} for the current transaction.
*/
TransactionContextFuture beginTransaction() {
if (this.isInTransaction()) { | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/DatabaseClientReactiveAdapter.java
// public static final Executor REACTOR_EXECUTOR =
// runnable -> Schedulers.parallel().schedule(runnable);
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/TransactionInProgressException.java
// public class TransactionInProgressException extends R2dbcNonTransientException {
//
// public static final String MSG_READONLY =
// "Cannot begin a new transaction because a readonly transaction is already in progress.";
// public static final String MSG_READWRITE =
// "Cannot begin a new transaction because a read/write transaction is already in progress.";
//
// public TransactionInProgressException(boolean isReadwrite) {
// super(isReadwrite ? MSG_READWRITE : MSG_READONLY);
// }
//
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/DatabaseClientTransactionManager.java
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.cloud.spanner.r2dbc.v2.DatabaseClientReactiveAdapter.REACTOR_EXECUTOR;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.AsyncTransactionManager;
import com.google.cloud.spanner.AsyncTransactionManager.AsyncTransactionStep;
import com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture;
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.ReadContext;
import com.google.cloud.spanner.ReadOnlyTransaction;
import com.google.cloud.spanner.TimestampBound;
import com.google.cloud.spanner.TransactionContext;
import com.google.cloud.spanner.r2dbc.TransactionInProgressException;
/*
* Copyright 2020-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
/**
* Helper class encapsulating read/write and readonly transaction management for client library
* based interaction with Cloud Spanner.
* Partitioned DML is out of scope for transaction handling, as they are not atomic.
*/
class DatabaseClientTransactionManager {
private static final Logger LOGGER =
LoggerFactory.getLogger(DatabaseClientTransactionManager.class);
private final DatabaseClient dbClient;
private AsyncTransactionManager transactionManager;
private TransactionContextFuture txnContextFuture;
private ReadOnlyTransaction readOnlyTransaction;
private AsyncTransactionStep<?, ? extends Object> lastStep;
public DatabaseClientTransactionManager(DatabaseClient dbClient) {
this.dbClient = dbClient;
}
boolean isInReadWriteTransaction() {
return this.txnContextFuture != null;
}
boolean isInReadonlyTransaction() {
return this.readOnlyTransaction != null;
}
boolean isInTransaction() {
return isInReadWriteTransaction() || isInReadonlyTransaction();
}
/**
* Starts a Cloud Spanner Read/Write transaction.
*
* @return chainable {@link TransactionContextFuture} for the current transaction.
*/
TransactionContextFuture beginTransaction() {
if (this.isInTransaction()) { | throw new TransactionInProgressException(this.isInReadWriteTransaction()); |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/DatabaseClientTransactionManager.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/DatabaseClientReactiveAdapter.java
// public static final Executor REACTOR_EXECUTOR =
// runnable -> Schedulers.parallel().schedule(runnable);
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/TransactionInProgressException.java
// public class TransactionInProgressException extends R2dbcNonTransientException {
//
// public static final String MSG_READONLY =
// "Cannot begin a new transaction because a readonly transaction is already in progress.";
// public static final String MSG_READWRITE =
// "Cannot begin a new transaction because a read/write transaction is already in progress.";
//
// public TransactionInProgressException(boolean isReadwrite) {
// super(isReadwrite ? MSG_READWRITE : MSG_READONLY);
// }
//
// }
| import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.cloud.spanner.r2dbc.v2.DatabaseClientReactiveAdapter.REACTOR_EXECUTOR;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.AsyncTransactionManager;
import com.google.cloud.spanner.AsyncTransactionManager.AsyncTransactionStep;
import com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture;
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.ReadContext;
import com.google.cloud.spanner.ReadOnlyTransaction;
import com.google.cloud.spanner.TimestampBound;
import com.google.cloud.spanner.TransactionContext;
import com.google.cloud.spanner.r2dbc.TransactionInProgressException; | */
ApiFuture<Void> rollbackTransaction() {
if (isInReadWriteTransaction()) {
if (this.lastStep == null) {
LOGGER.warn("Read/Write transaction rolling back without any statements.");
}
return this.transactionManager.rollbackAsync();
}
LOGGER.warn("Rollback called outside of an active read/write transaction.");
return ApiFutures.immediateFuture(null);
}
/**
* Runs provided operation, managing the client library transactional future chaining.
*
* @param operation a function executing either streaming SQL or DML.
* The function accepts ReadContext for SELECT queries, and TransactionContext for DML.
* @param <T> Type of object wrapped by the {@link ApiFuture} returned by the operation
*
* @return {@link ApiFuture} result of the provided operation
*/
<T> ApiFuture<T> runInTransaction(Function<? super TransactionContext, ApiFuture<T>> operation) {
// The first statement in a transaction has no input, hence Void input type.
// The subsequent statements take the previous statements' return (affected row count)
// as input.
AsyncTransactionStep<? extends Object, T> updateStatementFuture =
this.lastStep == null
? this.txnContextFuture.then( | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/DatabaseClientReactiveAdapter.java
// public static final Executor REACTOR_EXECUTOR =
// runnable -> Schedulers.parallel().schedule(runnable);
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/TransactionInProgressException.java
// public class TransactionInProgressException extends R2dbcNonTransientException {
//
// public static final String MSG_READONLY =
// "Cannot begin a new transaction because a readonly transaction is already in progress.";
// public static final String MSG_READWRITE =
// "Cannot begin a new transaction because a read/write transaction is already in progress.";
//
// public TransactionInProgressException(boolean isReadwrite) {
// super(isReadwrite ? MSG_READWRITE : MSG_READONLY);
// }
//
// }
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/DatabaseClientTransactionManager.java
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.cloud.spanner.r2dbc.v2.DatabaseClientReactiveAdapter.REACTOR_EXECUTOR;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
import com.google.cloud.Timestamp;
import com.google.cloud.spanner.AsyncTransactionManager;
import com.google.cloud.spanner.AsyncTransactionManager.AsyncTransactionStep;
import com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture;
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.ReadContext;
import com.google.cloud.spanner.ReadOnlyTransaction;
import com.google.cloud.spanner.TimestampBound;
import com.google.cloud.spanner.TransactionContext;
import com.google.cloud.spanner.r2dbc.TransactionInProgressException;
*/
ApiFuture<Void> rollbackTransaction() {
if (isInReadWriteTransaction()) {
if (this.lastStep == null) {
LOGGER.warn("Read/Write transaction rolling back without any statements.");
}
return this.transactionManager.rollbackAsync();
}
LOGGER.warn("Rollback called outside of an active read/write transaction.");
return ApiFutures.immediateFuture(null);
}
/**
* Runs provided operation, managing the client library transactional future chaining.
*
* @param operation a function executing either streaming SQL or DML.
* The function accepts ReadContext for SELECT queries, and TransactionContext for DML.
* @param <T> Type of object wrapped by the {@link ApiFuture} returned by the operation
*
* @return {@link ApiFuture} result of the provided operation
*/
<T> ApiFuture<T> runInTransaction(Function<? super TransactionContext, ApiFuture<T>> operation) {
// The first statement in a transaction has no input, hence Void input type.
// The subsequent statements take the previous statements' return (affected row count)
// as input.
AsyncTransactionStep<? extends Object, T> updateStatementFuture =
this.lastStep == null
? this.txnContextFuture.then( | (ctx, unusedVoid) -> operation.apply(ctx), REACTOR_EXECUTOR) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/ClientLibraryDdlIntegrationTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Result;
import java.util.Random;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Hooks;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; | /*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class ClientLibraryDdlIntegrationTest {
private static final ConnectionFactory connectionFactory =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId()) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/ClientLibraryDdlIntegrationTest.java
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Result;
import java.util.Random;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Hooks;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
/*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class ClientLibraryDdlIntegrationTest {
private static final ConnectionFactory connectionFactory =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId()) | .option(DRIVER, DRIVER_NAME) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/ClientLibraryDdlIntegrationTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Result;
import java.util.Random;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Hooks;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier; | /*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class ClientLibraryDdlIntegrationTest {
private static final ConnectionFactory connectionFactory =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/ClientLibraryDdlIntegrationTest.java
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Closeable;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Result;
import java.util.Random;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Hooks;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
/*
* Copyright 2021-2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.it;
class ClientLibraryDdlIntegrationTest {
private static final ConnectionFactory connectionFactory =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | .option(INSTANCE, DatabaseProperties.INSTANCE) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/TestDatabaseHelper.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | public void addTestData(String title, int category) {
int suffix = Math.abs(this.random.nextInt());
Mono.from(
this.connection
.createStatement(INSERT_DATA_QUERY)
.bind("uuid", "autoinserted-" + suffix)
.bind("title", title)
.bind("category", category)
.execute())
.flatMapMany(rs -> rs.getRowsUpdated())
.blockLast();
}
public void clearTestData() {
Mono.from(
this.connection.createStatement("DELETE FROM BOOKS WHERE true").execute())
.flatMap(rs -> Mono.from(rs.getRowsUpdated()))
.block();
}
public void close() {
Mono.from(this.connection.close()).block();
}
public static void main(String[] args) {
ConnectionFactory cf =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId()) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/TestDatabaseHelper.java
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public void addTestData(String title, int category) {
int suffix = Math.abs(this.random.nextInt());
Mono.from(
this.connection
.createStatement(INSERT_DATA_QUERY)
.bind("uuid", "autoinserted-" + suffix)
.bind("title", title)
.bind("category", category)
.execute())
.flatMapMany(rs -> rs.getRowsUpdated())
.blockLast();
}
public void clearTestData() {
Mono.from(
this.connection.createStatement("DELETE FROM BOOKS WHERE true").execute())
.flatMap(rs -> Mono.from(rs.getRowsUpdated()))
.block();
}
public void close() {
Mono.from(this.connection.close()).block();
}
public static void main(String[] args) {
ConnectionFactory cf =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId()) | .option(DRIVER, DRIVER_NAME) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/TestDatabaseHelper.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
| import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | int suffix = Math.abs(this.random.nextInt());
Mono.from(
this.connection
.createStatement(INSERT_DATA_QUERY)
.bind("uuid", "autoinserted-" + suffix)
.bind("title", title)
.bind("category", category)
.execute())
.flatMapMany(rs -> rs.getRowsUpdated())
.blockLast();
}
public void clearTestData() {
Mono.from(
this.connection.createStatement("DELETE FROM BOOKS WHERE true").execute())
.flatMap(rs -> Mono.from(rs.getRowsUpdated()))
.block();
}
public void close() {
Mono.from(this.connection.close()).block();
}
public static void main(String[] args) {
ConnectionFactory cf =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/it/TestDatabaseHelper.java
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.ServiceOptions;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
int suffix = Math.abs(this.random.nextInt());
Mono.from(
this.connection
.createStatement(INSERT_DATA_QUERY)
.bind("uuid", "autoinserted-" + suffix)
.bind("title", title)
.bind("category", category)
.execute())
.flatMapMany(rs -> rs.getRowsUpdated())
.blockLast();
}
public void clearTestData() {
Mono.from(
this.connection.createStatement("DELETE FROM BOOKS WHERE true").execute())
.flatMap(rs -> Mono.from(rs.getRowsUpdated()))
.block();
}
public void close() {
Mono.from(this.connection.close()).block();
}
public static void main(String[] args) {
ConnectionFactory cf =
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), ServiceOptions.getDefaultProjectId())
.option(DRIVER, DRIVER_NAME) | .option(INSTANCE, DatabaseProperties.INSTANCE) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/DatabaseClientTransactionManagerTest.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/TransactionInProgressException.java
// public class TransactionInProgressException extends R2dbcNonTransientException {
//
// public static final String MSG_READONLY =
// "Cannot begin a new transaction because a readonly transaction is already in progress.";
// public static final String MSG_READWRITE =
// "Cannot begin a new transaction because a read/write transaction is already in progress.";
//
// public TransactionInProgressException(boolean isReadwrite) {
// super(isReadwrite ? MSG_READWRITE : MSG_READONLY);
// }
//
// }
| import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import com.google.api.core.ApiFutures;
import com.google.cloud.spanner.AsyncTransactionManager;
import com.google.cloud.spanner.AsyncTransactionManager.AsyncTransactionFunction;
import com.google.cloud.spanner.AsyncTransactionManager.AsyncTransactionStep;
import com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture;
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.ReadOnlyTransaction;
import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.TimestampBound;
import com.google.cloud.spanner.TransactionContext;
import com.google.cloud.spanner.r2dbc.TransactionInProgressException;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; | /*
* Copyright 2020-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class DatabaseClientTransactionManagerTest {
DatabaseClientTransactionManager transactionManager;
DatabaseClient mockDbClient;
AsyncTransactionManager mockClientLibraryTransactionManager;
TransactionContextFuture mockTransactionFuture;
TransactionContext mockTransactionContext;
ReadOnlyTransaction mockReadOnlyTransaction;
AsyncTransactionStep mockAsyncTransactionStep;
private static PrintStream systemErr;
private static ByteArrayOutputStream redirectedOutput = new ByteArrayOutputStream();
@BeforeAll
public static void redirectOutput() {
systemErr = System.out;
System.setErr(new PrintStream(redirectedOutput));
}
@AfterAll
public static void restoreOutput() {
System.setErr(systemErr);
}
/** Sets up mocks. */
@BeforeEach
public void setUp() {
this.mockDbClient = mock(DatabaseClient.class);
this.mockClientLibraryTransactionManager = mock(AsyncTransactionManager.class);
this.mockTransactionFuture = mock(TransactionContextFuture.class);
this.mockTransactionContext = mock(TransactionContext.class);
this.mockReadOnlyTransaction = mock(ReadOnlyTransaction.class);
this.mockAsyncTransactionStep = mock(AsyncTransactionStep.class);
when(this.mockDbClient.transactionManagerAsync())
.thenReturn(this.mockClientLibraryTransactionManager);
when(this.mockClientLibraryTransactionManager.beginAsync())
.thenReturn(this.mockTransactionFuture);
when(this.mockTransactionFuture.then(any(), any())).thenAnswer(invocation -> {
((AsyncTransactionFunction) invocation.getArgument(0))
.apply(this.mockTransactionContext, null);
return this.mockAsyncTransactionStep;
});
when(this.mockTransactionContext.executeUpdateAsync(any()))
.thenReturn(ApiFutures.immediateFuture(42L));
when(this.mockClientLibraryTransactionManager.closeAsync())
.thenReturn(ApiFutures.immediateFuture(null));
when(this.mockDbClient.readOnlyTransaction(TimestampBound.strong()))
.thenReturn(this.mockReadOnlyTransaction);
this.transactionManager = new DatabaseClientTransactionManager(this.mockDbClient);
}
@Test
void testReadonlyTransactionStartedWhileReadWriteInProgressFails() {
this.transactionManager.beginTransaction();
TimestampBound strongBound = TimestampBound.strong();
assertThatThrownBy(() ->
this.transactionManager.beginReadonlyTransaction(strongBound) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/TransactionInProgressException.java
// public class TransactionInProgressException extends R2dbcNonTransientException {
//
// public static final String MSG_READONLY =
// "Cannot begin a new transaction because a readonly transaction is already in progress.";
// public static final String MSG_READWRITE =
// "Cannot begin a new transaction because a read/write transaction is already in progress.";
//
// public TransactionInProgressException(boolean isReadwrite) {
// super(isReadwrite ? MSG_READWRITE : MSG_READONLY);
// }
//
// }
// Path: cloud-spanner-r2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/DatabaseClientTransactionManagerTest.java
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
import com.google.api.core.ApiFutures;
import com.google.cloud.spanner.AsyncTransactionManager;
import com.google.cloud.spanner.AsyncTransactionManager.AsyncTransactionFunction;
import com.google.cloud.spanner.AsyncTransactionManager.AsyncTransactionStep;
import com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture;
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.ReadOnlyTransaction;
import com.google.cloud.spanner.Statement;
import com.google.cloud.spanner.TimestampBound;
import com.google.cloud.spanner.TransactionContext;
import com.google.cloud.spanner.r2dbc.TransactionInProgressException;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/*
* Copyright 2020-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.spanner.r2dbc.v2;
class DatabaseClientTransactionManagerTest {
DatabaseClientTransactionManager transactionManager;
DatabaseClient mockDbClient;
AsyncTransactionManager mockClientLibraryTransactionManager;
TransactionContextFuture mockTransactionFuture;
TransactionContext mockTransactionContext;
ReadOnlyTransaction mockReadOnlyTransaction;
AsyncTransactionStep mockAsyncTransactionStep;
private static PrintStream systemErr;
private static ByteArrayOutputStream redirectedOutput = new ByteArrayOutputStream();
@BeforeAll
public static void redirectOutput() {
systemErr = System.out;
System.setErr(new PrintStream(redirectedOutput));
}
@AfterAll
public static void restoreOutput() {
System.setErr(systemErr);
}
/** Sets up mocks. */
@BeforeEach
public void setUp() {
this.mockDbClient = mock(DatabaseClient.class);
this.mockClientLibraryTransactionManager = mock(AsyncTransactionManager.class);
this.mockTransactionFuture = mock(TransactionContextFuture.class);
this.mockTransactionContext = mock(TransactionContext.class);
this.mockReadOnlyTransaction = mock(ReadOnlyTransaction.class);
this.mockAsyncTransactionStep = mock(AsyncTransactionStep.class);
when(this.mockDbClient.transactionManagerAsync())
.thenReturn(this.mockClientLibraryTransactionManager);
when(this.mockClientLibraryTransactionManager.beginAsync())
.thenReturn(this.mockTransactionFuture);
when(this.mockTransactionFuture.then(any(), any())).thenAnswer(invocation -> {
((AsyncTransactionFunction) invocation.getArgument(0))
.apply(this.mockTransactionContext, null);
return this.mockAsyncTransactionStep;
});
when(this.mockTransactionContext.executeUpdateAsync(any()))
.thenReturn(ApiFutures.immediateFuture(42L));
when(this.mockClientLibraryTransactionManager.closeAsync())
.thenReturn(ApiFutures.immediateFuture(null));
when(this.mockDbClient.readOnlyTransaction(TimestampBound.strong()))
.thenReturn(this.mockReadOnlyTransaction);
this.transactionManager = new DatabaseClientTransactionManager(this.mockDbClient);
}
@Test
void testReadonlyTransactionStartedWhileReadWriteInProgressFails() {
this.transactionManager.beginTransaction();
TimestampBound strongBound = TimestampBound.strong();
assertThatThrownBy(() ->
this.transactionManager.beginReadonlyTransaction(strongBound) | ).isInstanceOf(TransactionInProgressException.class) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc-samples/cloud-spanner-r2dbc-sample/src/main/java/com/example/BookExampleApp.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
| import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;
import io.r2dbc.spi.Statement; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example;
/**
* The main class for the functions of the sample application.
*/
public class BookExampleApp {
private final ConnectionFactory connectionFactory;
private final Connection connection;
/**
* Constructor.
*
* @param sampleInstance the sample instance to use.
* @param sampleDatabase the sample database to use.
* @param sampleProjectId the sample project to use.
*/
public BookExampleApp(String sampleInstance, String sampleDatabase,
String sampleProjectId) {
this.connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), sampleProjectId) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
// Path: cloud-spanner-r2dbc-samples/cloud-spanner-r2dbc-sample/src/main/java/com/example/BookExampleApp.java
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;
import io.r2dbc.spi.Statement;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example;
/**
* The main class for the functions of the sample application.
*/
public class BookExampleApp {
private final ConnectionFactory connectionFactory;
private final Connection connection;
/**
* Constructor.
*
* @param sampleInstance the sample instance to use.
* @param sampleDatabase the sample database to use.
* @param sampleProjectId the sample project to use.
*/
public BookExampleApp(String sampleInstance, String sampleDatabase,
String sampleProjectId) {
this.connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), sampleProjectId) | .option(DRIVER, DRIVER_NAME) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc-samples/cloud-spanner-r2dbc-sample/src/main/java/com/example/BookExampleApp.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
| import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;
import io.r2dbc.spi.Statement; | /*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example;
/**
* The main class for the functions of the sample application.
*/
public class BookExampleApp {
private final ConnectionFactory connectionFactory;
private final Connection connection;
/**
* Constructor.
*
* @param sampleInstance the sample instance to use.
* @param sampleDatabase the sample database to use.
* @param sampleProjectId the sample project to use.
*/
public BookExampleApp(String sampleInstance, String sampleDatabase,
String sampleProjectId) {
this.connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), sampleProjectId)
.option(DRIVER, DRIVER_NAME) | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
// Path: cloud-spanner-r2dbc-samples/cloud-spanner-r2dbc-sample/src/main/java/com/example/BookExampleApp.java
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;
import io.r2dbc.spi.Statement;
/*
* Copyright 2019-2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example;
/**
* The main class for the functions of the sample application.
*/
public class BookExampleApp {
private final ConnectionFactory connectionFactory;
private final Connection connection;
/**
* Constructor.
*
* @param sampleInstance the sample instance to use.
* @param sampleDatabase the sample database to use.
* @param sampleProjectId the sample project to use.
*/
public BookExampleApp(String sampleInstance, String sampleDatabase,
String sampleProjectId) {
this.connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
.option(Option.valueOf("project"), sampleProjectId)
.option(DRIVER, DRIVER_NAME) | .option(INSTANCE, sampleInstance) |
GoogleCloudPlatform/cloud-spanner-r2dbc | cloud-spanner-r2dbc-samples/cloud-spanner-r2dbc-sample/src/main/java/com/example/BookExampleApp.java | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
| import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;
import io.r2dbc.spi.Statement; | + " TITLE STRING(MAX) NOT NULL,"
+ " EXTRADETAILS JSON"
+ ") PRIMARY KEY (ID)").execute())
.doOnSuccess(x -> System.out.println("Table creation completed."))
.block();
}
/**
* Saves two books.
*/
public void saveBooks() {
Statement statement = this.connection.createStatement(
"INSERT BOOKS "
+ "(ID, TITLE)"
+ " VALUES "
+ "(@id, @title)")
.bind("id", "book1")
.bind("title", "Book One")
.add()
.bind("id", "book2")
.bind("title", "Book Two");
Statement statement2 = this.connection.createStatement(
"INSERT BOOKS "
+ "(ID, TITLE, EXTRADETAILS)"
+ " VALUES "
+ "(@id, @title, @extradetails)")
.bind("id", "book3")
.bind("title", "Book Three") | // Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final String DRIVER_NAME = "cloudspanner";
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java
// public static final Option<String> INSTANCE = Option.valueOf("instance");
//
// Path: cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/JsonWrapper.java
// public class JsonWrapper {
// private String jsonString;
//
// public JsonWrapper(String jsonString) {
// this.jsonString = jsonString;
// }
//
// protected Value getJsonVal() {
// return Value.json(this.jsonString);
// }
//
// public static JsonWrapper of(String jsonString) {
// return new JsonWrapper(jsonString);
// }
//
// @Override
// public String toString() {
// return this.jsonString;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (o == null || getClass() != o.getClass()) {
// return false;
// }
// JsonWrapper that = (JsonWrapper) o;
// return Objects.equal(this.jsonString, that.jsonString);
// }
//
// @Override
// public int hashCode() {
// return Objects.hashCode(this.jsonString);
// }
// }
// Path: cloud-spanner-r2dbc-samples/cloud-spanner-r2dbc-sample/src/main/java/com/example/BookExampleApp.java
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.DRIVER_NAME;
import static com.google.cloud.spanner.r2dbc.SpannerConnectionFactoryProvider.INSTANCE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import com.google.cloud.spanner.r2dbc.v2.JsonWrapper;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import io.r2dbc.spi.Option;
import io.r2dbc.spi.Row;
import io.r2dbc.spi.RowMetadata;
import io.r2dbc.spi.Statement;
+ " TITLE STRING(MAX) NOT NULL,"
+ " EXTRADETAILS JSON"
+ ") PRIMARY KEY (ID)").execute())
.doOnSuccess(x -> System.out.println("Table creation completed."))
.block();
}
/**
* Saves two books.
*/
public void saveBooks() {
Statement statement = this.connection.createStatement(
"INSERT BOOKS "
+ "(ID, TITLE)"
+ " VALUES "
+ "(@id, @title)")
.bind("id", "book1")
.bind("title", "Book One")
.add()
.bind("id", "book2")
.bind("title", "Book Two");
Statement statement2 = this.connection.createStatement(
"INSERT BOOKS "
+ "(ID, TITLE, EXTRADETAILS)"
+ " VALUES "
+ "(@id, @title, @extradetails)")
.bind("id", "book3")
.bind("title", "Book Three") | .bind("extradetails", new JsonWrapper("{\"rating\":9,\"series\":true}")); |
Jarlakxen/eclipse-sbt-plugin | com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/action/MigrateAction.java | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/wizard/migrate/MigrationWizard.java
// public class MigrationWizard extends Wizard {
//
// private MigrateToSbtProjectConfiguration configuration = MigrateToSbtProjectConfiguration.getDefault();
//
// public MigrationWizard(IProject project){
// configuration.setProject(project);
// setWindowTitle("Add SBT Nature");
// setNeedsProgressMonitor(true);
// }
//
// @Override
// public void addPages() {
// addPage(new MigrationWizardPage(configuration));
// }
//
// @Override
// public boolean performFinish() {
//
// try {
// MigrateToSbtProjectJob job = new MigrateToSbtProjectJob(configuration);
// job.schedule();
// return true;
// } catch (Exception e) {
// UIUtil.showErrorDialog(e.toString());
// SbtPlugin.logException(e);
// return false;
// }
// }
// }
| import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import com.github.jarlakxen.scala.sbt.wizard.migrate.MigrationWizard;
| package com.github.jarlakxen.scala.sbt.action;
/**
* Migrates the selected SBT project to ScalaIDE.
*
* @author Naoki Takezoe
*/
public class MigrateAction implements IObjectActionDelegate {
private IProject project;
private IWorkbenchPart targetPart;
@Override
public void run(IAction action) {
| // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/wizard/migrate/MigrationWizard.java
// public class MigrationWizard extends Wizard {
//
// private MigrateToSbtProjectConfiguration configuration = MigrateToSbtProjectConfiguration.getDefault();
//
// public MigrationWizard(IProject project){
// configuration.setProject(project);
// setWindowTitle("Add SBT Nature");
// setNeedsProgressMonitor(true);
// }
//
// @Override
// public void addPages() {
// addPage(new MigrationWizardPage(configuration));
// }
//
// @Override
// public boolean performFinish() {
//
// try {
// MigrateToSbtProjectJob job = new MigrateToSbtProjectJob(configuration);
// job.schedule();
// return true;
// } catch (Exception e) {
// UIUtil.showErrorDialog(e.toString());
// SbtPlugin.logException(e);
// return false;
// }
// }
// }
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/action/MigrateAction.java
import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import com.github.jarlakxen.scala.sbt.wizard.migrate.MigrationWizard;
package com.github.jarlakxen.scala.sbt.action;
/**
* Migrates the selected SBT project to ScalaIDE.
*
* @author Naoki Takezoe
*/
public class MigrateAction implements IObjectActionDelegate {
private IProject project;
private IWorkbenchPart targetPart;
@Override
public void run(IAction action) {
| WizardDialog dialog = new WizardDialog(targetPart.getSite().getShell(), new MigrationWizard(project));
|
Jarlakxen/eclipse-sbt-plugin | com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/action/UpdateProjectConfigurationAction.java | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtPlugin.java
// public class SbtPlugin extends AbstractUIPlugin {
//
// public static final String[] PROJECT_NATURES_IDS = new String[] {
// ScalaPlugin.plugin().natureId(),
// "org.eclipse.jdt.core.javanature",
// SbtPlugin.NATURE_ID
// };
//
// /** The plug-in ID */
// public static final String PLUGIN_ID = "com.github.jarlakxen.scala.sbt"; //$NON-NLS-1$
//
// /** The nature ID */
// public static final String NATURE_ID = PLUGIN_ID + ".SbtProjectNature"; //$NON-NLS-1$
//
// // The shared instance
// private static SbtPlugin plugin;
//
// public static final String ICON_SETTING_KEY = "/icons/setting_key.gif";
// public static final String ICON_SETTING_VALUE = "/icons/setting_value.gif";
//
// /**
// * The constructor
// */
// public SbtPlugin() {
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
// * )
// */
// public void start(BundleContext context) throws Exception {
// super.start(context);
// plugin = this;
// SbtProjectFilesChangeListener.register();
// SbtLaunchJarManager.deploy();
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
// * )
// */
// public void stop(BundleContext context) throws Exception {
// SbtLaunchJarManager.undeploy();
// plugin = null;
// super.stop(context);
// }
//
// protected void initializeImageRegistry(ImageRegistry registory) {
// super.initializeImageRegistry(registory);
// registory.put(ICON_SETTING_KEY, ImageDescriptor.createFromURL(getBundle().getEntry(ICON_SETTING_KEY)));
// registory.put(ICON_SETTING_VALUE, ImageDescriptor.createFromURL(getBundle().getEntry(ICON_SETTING_VALUE)));
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static SbtPlugin getDefault() {
// return plugin;
// }
//
// public static void logException(Exception ex) {
// IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, ex.toString(), ex);
// getDefault().getLog().log(status);
// }
//
// public static void addProjectNatures(IProject project) throws CoreException {
// IProjectDescription desc = project.getDescription();
// desc.setNatureIds(PROJECT_NATURES_IDS);
// project.setDescription(desc, null);
// }
// }
| import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import com.github.jarlakxen.scala.sbt.SbtPlugin;
| package com.github.jarlakxen.scala.sbt.action;
/**
* Updates project dependency.
*
* @author Facundo Viale
*/
public class UpdateProjectConfigurationAction extends AbstractSbtCommandAction {
public UpdateProjectConfigurationAction() {
super("update eclipse");
}
@Override
public void run(IAction action) {
super.run(action);
try {
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
| // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtPlugin.java
// public class SbtPlugin extends AbstractUIPlugin {
//
// public static final String[] PROJECT_NATURES_IDS = new String[] {
// ScalaPlugin.plugin().natureId(),
// "org.eclipse.jdt.core.javanature",
// SbtPlugin.NATURE_ID
// };
//
// /** The plug-in ID */
// public static final String PLUGIN_ID = "com.github.jarlakxen.scala.sbt"; //$NON-NLS-1$
//
// /** The nature ID */
// public static final String NATURE_ID = PLUGIN_ID + ".SbtProjectNature"; //$NON-NLS-1$
//
// // The shared instance
// private static SbtPlugin plugin;
//
// public static final String ICON_SETTING_KEY = "/icons/setting_key.gif";
// public static final String ICON_SETTING_VALUE = "/icons/setting_value.gif";
//
// /**
// * The constructor
// */
// public SbtPlugin() {
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
// * )
// */
// public void start(BundleContext context) throws Exception {
// super.start(context);
// plugin = this;
// SbtProjectFilesChangeListener.register();
// SbtLaunchJarManager.deploy();
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
// * )
// */
// public void stop(BundleContext context) throws Exception {
// SbtLaunchJarManager.undeploy();
// plugin = null;
// super.stop(context);
// }
//
// protected void initializeImageRegistry(ImageRegistry registory) {
// super.initializeImageRegistry(registory);
// registory.put(ICON_SETTING_KEY, ImageDescriptor.createFromURL(getBundle().getEntry(ICON_SETTING_KEY)));
// registory.put(ICON_SETTING_VALUE, ImageDescriptor.createFromURL(getBundle().getEntry(ICON_SETTING_VALUE)));
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static SbtPlugin getDefault() {
// return plugin;
// }
//
// public static void logException(Exception ex) {
// IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, ex.toString(), ex);
// getDefault().getLog().log(status);
// }
//
// public static void addProjectNatures(IProject project) throws CoreException {
// IProjectDescription desc = project.getDescription();
// desc.setNatureIds(PROJECT_NATURES_IDS);
// project.setDescription(desc, null);
// }
// }
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/action/UpdateProjectConfigurationAction.java
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import com.github.jarlakxen.scala.sbt.SbtPlugin;
package com.github.jarlakxen.scala.sbt.action;
/**
* Updates project dependency.
*
* @author Facundo Viale
*/
public class UpdateProjectConfigurationAction extends AbstractSbtCommandAction {
public UpdateProjectConfigurationAction() {
super("update eclipse");
}
@Override
public void run(IAction action) {
super.run(action);
try {
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
| SbtPlugin.addProjectNatures(project);
|
Jarlakxen/eclipse-sbt-plugin | com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/builder/TestLibrary.java | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/ScalaVersion.java
// public enum ScalaVersion {
// V_2_10_3("2.10.3"),
// V_2_10_2("2.10.2"),
// V_2_10_1("2.10.1"),
// V_2_9_3("2.9.3"),
// V_2_9_2("2.9.2");
//
// public static ScalaVersion getDefault() {
// return V_2_10_3;
// }
//
// public static ScalaVersion versionOf(String text){
// for(ScalaVersion version : values()){
// if(version.getText().equals(text)){
// return version;
// }
// }
// return null;
// }
//
// private final String text;
// private final String baseVersion;
//
// private ScalaVersion(String text) {
// this.text = text;
// this.baseVersion = text.substring(0, text.lastIndexOf("."));
// }
//
// public String getText() {
// return text;
// }
//
// public String getBaseVersion(){
// return baseVersion;
// }
// }
| import java.util.HashMap;
import java.util.Map;
import com.github.jarlakxen.scala.sbt.ScalaVersion; | package com.github.jarlakxen.scala.sbt.builder;
public enum TestLibrary {
SPECS2 {
@Override
protected void populate(Map<String, String> dependancyMap) {
dependancyMap.put("2.10", "\"org.specs2\" %% \"specs2\" % \"2.2.3\" % \"test\"");
dependancyMap.put("2.9", "\"org.specs2\" %% \"specs2\" % \"1.12.4.1\" % \"test\"");
}
};
private Map<String, String> dependancyMap;
private TestLibrary() {
dependancyMap = new HashMap<String, String>();
populate(dependancyMap);
}
protected abstract void populate(Map<String, String> dependancyMap);
| // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/ScalaVersion.java
// public enum ScalaVersion {
// V_2_10_3("2.10.3"),
// V_2_10_2("2.10.2"),
// V_2_10_1("2.10.1"),
// V_2_9_3("2.9.3"),
// V_2_9_2("2.9.2");
//
// public static ScalaVersion getDefault() {
// return V_2_10_3;
// }
//
// public static ScalaVersion versionOf(String text){
// for(ScalaVersion version : values()){
// if(version.getText().equals(text)){
// return version;
// }
// }
// return null;
// }
//
// private final String text;
// private final String baseVersion;
//
// private ScalaVersion(String text) {
// this.text = text;
// this.baseVersion = text.substring(0, text.lastIndexOf("."));
// }
//
// public String getText() {
// return text;
// }
//
// public String getBaseVersion(){
// return baseVersion;
// }
// }
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/builder/TestLibrary.java
import java.util.HashMap;
import java.util.Map;
import com.github.jarlakxen.scala.sbt.ScalaVersion;
package com.github.jarlakxen.scala.sbt.builder;
public enum TestLibrary {
SPECS2 {
@Override
protected void populate(Map<String, String> dependancyMap) {
dependancyMap.put("2.10", "\"org.specs2\" %% \"specs2\" % \"2.2.3\" % \"test\"");
dependancyMap.put("2.9", "\"org.specs2\" %% \"specs2\" % \"1.12.4.1\" % \"test\"");
}
};
private Map<String, String> dependancyMap;
private TestLibrary() {
dependancyMap = new HashMap<String, String>();
populate(dependancyMap);
}
protected abstract void populate(Map<String, String> dependancyMap);
| public String getDependancy(ScalaVersion version) { |
Jarlakxen/eclipse-sbt-plugin | com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtPlugin.java | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/listener/SbtProjectFilesChangeListener.java
// public class SbtProjectFilesChangeListener implements IResourceChangeListener {
//
// private static final List<String> SBT_PROJECT_FILES = asList("build.sbt", "project/plugins.sbt", "project/build.properties", "project/Build.scala");
//
// public static void register() {
// ResourcesPlugin.getWorkspace().addResourceChangeListener(new SbtProjectFilesChangeListener(), IResourceChangeEvent.POST_CHANGE);
// }
//
// private SbtProjectFilesChangeListener() {
// }
//
// @Override
// public void resourceChanged(IResourceChangeEvent event) {
// List<IProject> projects = getProjects(event.getDelta());
//
// for(IProject project : projects){
// new UpdateProjectJob(project).schedule();
// }
// }
//
// private List<IProject> getProjects(IResourceDelta delta) {
// final List<IProject> projects = new ArrayList<IProject>();
// try {
// delta.accept(new IResourceDeltaVisitor() {
// public boolean visit(IResourceDelta delta) throws CoreException {
// // only interested in changed resources (not added or
// // removed)
// if (delta.getKind() != IResourceDelta.CHANGED) {
// return true;
// }
// // only interested in content changes
// if ((delta.getFlags() & IResourceDelta.CONTENT) == 0) {
// return true;
// }
//
// IResource resource = delta.getResource();
// if (resource.getType() == IResource.FILE && isProjectFile(resource) && !projects.contains(resource.getProject())) {
// projects.add(resource.getProject());
// }
// return true;
//
// }
// });
// } catch (CoreException ex) {
// UIUtil.showErrorDialog(ex.toString());
// SbtPlugin.logException(ex);
// }
// return projects;
// }
//
// private boolean isProjectFile(IResource resource){
// String resourcePath = resource.getProjectRelativePath().toString();
// for(String projectFile : SBT_PROJECT_FILES){
// if(projectFile.equals(resourcePath)){
// return true;
// }
// }
// return false;
// }
//
// }
| import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import com.github.jarlakxen.scala.sbt.listener.SbtProjectFilesChangeListener;
import scala.tools.eclipse.ScalaPlugin;
| package com.github.jarlakxen.scala.sbt;
/**
* The activator class controls the plug-in life cycle
*
* @author Naoki Takezoe
*/
public class SbtPlugin extends AbstractUIPlugin {
public static final String[] PROJECT_NATURES_IDS = new String[] {
ScalaPlugin.plugin().natureId(),
"org.eclipse.jdt.core.javanature",
SbtPlugin.NATURE_ID
};
/** The plug-in ID */
public static final String PLUGIN_ID = "com.github.jarlakxen.scala.sbt"; //$NON-NLS-1$
/** The nature ID */
public static final String NATURE_ID = PLUGIN_ID + ".SbtProjectNature"; //$NON-NLS-1$
// The shared instance
private static SbtPlugin plugin;
public static final String ICON_SETTING_KEY = "/icons/setting_key.gif";
public static final String ICON_SETTING_VALUE = "/icons/setting_value.gif";
/**
* The constructor
*/
public SbtPlugin() {
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
* )
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
| // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/listener/SbtProjectFilesChangeListener.java
// public class SbtProjectFilesChangeListener implements IResourceChangeListener {
//
// private static final List<String> SBT_PROJECT_FILES = asList("build.sbt", "project/plugins.sbt", "project/build.properties", "project/Build.scala");
//
// public static void register() {
// ResourcesPlugin.getWorkspace().addResourceChangeListener(new SbtProjectFilesChangeListener(), IResourceChangeEvent.POST_CHANGE);
// }
//
// private SbtProjectFilesChangeListener() {
// }
//
// @Override
// public void resourceChanged(IResourceChangeEvent event) {
// List<IProject> projects = getProjects(event.getDelta());
//
// for(IProject project : projects){
// new UpdateProjectJob(project).schedule();
// }
// }
//
// private List<IProject> getProjects(IResourceDelta delta) {
// final List<IProject> projects = new ArrayList<IProject>();
// try {
// delta.accept(new IResourceDeltaVisitor() {
// public boolean visit(IResourceDelta delta) throws CoreException {
// // only interested in changed resources (not added or
// // removed)
// if (delta.getKind() != IResourceDelta.CHANGED) {
// return true;
// }
// // only interested in content changes
// if ((delta.getFlags() & IResourceDelta.CONTENT) == 0) {
// return true;
// }
//
// IResource resource = delta.getResource();
// if (resource.getType() == IResource.FILE && isProjectFile(resource) && !projects.contains(resource.getProject())) {
// projects.add(resource.getProject());
// }
// return true;
//
// }
// });
// } catch (CoreException ex) {
// UIUtil.showErrorDialog(ex.toString());
// SbtPlugin.logException(ex);
// }
// return projects;
// }
//
// private boolean isProjectFile(IResource resource){
// String resourcePath = resource.getProjectRelativePath().toString();
// for(String projectFile : SBT_PROJECT_FILES){
// if(projectFile.equals(resourcePath)){
// return true;
// }
// }
// return false;
// }
//
// }
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtPlugin.java
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import com.github.jarlakxen.scala.sbt.listener.SbtProjectFilesChangeListener;
import scala.tools.eclipse.ScalaPlugin;
package com.github.jarlakxen.scala.sbt;
/**
* The activator class controls the plug-in life cycle
*
* @author Naoki Takezoe
*/
public class SbtPlugin extends AbstractUIPlugin {
public static final String[] PROJECT_NATURES_IDS = new String[] {
ScalaPlugin.plugin().natureId(),
"org.eclipse.jdt.core.javanature",
SbtPlugin.NATURE_ID
};
/** The plug-in ID */
public static final String PLUGIN_ID = "com.github.jarlakxen.scala.sbt"; //$NON-NLS-1$
/** The nature ID */
public static final String NATURE_ID = PLUGIN_ID + ".SbtProjectNature"; //$NON-NLS-1$
// The shared instance
private static SbtPlugin plugin;
public static final String ICON_SETTING_KEY = "/icons/setting_key.gif";
public static final String ICON_SETTING_VALUE = "/icons/setting_value.gif";
/**
* The constructor
*/
public SbtPlugin() {
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
* )
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
| SbtProjectFilesChangeListener.register();
|
Jarlakxen/eclipse-sbt-plugin | com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/configurations/CreateSbtProjectConfiguration.java | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtVersion.java
// public enum SbtVersion {
//
// /**
// * SBT 0.11
// */
// SBT011("0.11", "0.11.3-2"),
//
// /**
// * SBT 0.12
// */
// SBT012("0.12", "0.12.4"),
//
// /**
// * SBT 0.13
// */
// SBT013("0.13", "0.13.0");
//
// public static SbtVersion getDefault() {
// return SBT013;
// }
//
// public static SbtVersion getVersion(String version) {
// for (SbtVersion value : values()) {
// if (version.startsWith(value.prefix)) {
// return value;
// }
// }
// return null;
// }
//
// private String prefix;
// private String lastVersion;
//
// private SbtVersion(String prefix, String lastVersion) {
// this.prefix = prefix;
// this.lastVersion = lastVersion;
// }
//
// public String getPrefix() {
// return prefix;
// }
//
// public String getLastVersion() {
// return lastVersion;
// }
//
// public String getLauncherJarName() {
// return "sbt-launch-" + lastVersion + ".jar";
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/ScalaVersion.java
// public enum ScalaVersion {
// V_2_10_3("2.10.3"),
// V_2_10_2("2.10.2"),
// V_2_10_1("2.10.1"),
// V_2_9_3("2.9.3"),
// V_2_9_2("2.9.2");
//
// public static ScalaVersion getDefault() {
// return V_2_10_3;
// }
//
// public static ScalaVersion versionOf(String text){
// for(ScalaVersion version : values()){
// if(version.getText().equals(text)){
// return version;
// }
// }
// return null;
// }
//
// private final String text;
// private final String baseVersion;
//
// private ScalaVersion(String text) {
// this.text = text;
// this.baseVersion = text.substring(0, text.lastIndexOf("."));
// }
//
// public String getText() {
// return text;
// }
//
// public String getBaseVersion(){
// return baseVersion;
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/builder/TestLibrary.java
// public enum TestLibrary {
// SPECS2 {
// @Override
// protected void populate(Map<String, String> dependancyMap) {
// dependancyMap.put("2.10", "\"org.specs2\" %% \"specs2\" % \"2.2.3\" % \"test\"");
// dependancyMap.put("2.9", "\"org.specs2\" %% \"specs2\" % \"1.12.4.1\" % \"test\"");
// }
// };
//
// private Map<String, String> dependancyMap;
//
// private TestLibrary() {
// dependancyMap = new HashMap<String, String>();
// populate(dependancyMap);
// }
//
// protected abstract void populate(Map<String, String> dependancyMap);
//
// public String getDependancy(ScalaVersion version) {
// if(dependancyMap.containsKey(version.getText())){
// return dependancyMap.get(version.getText());
// }
//
// return dependancyMap.get(version.getBaseVersion());
// }
//
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/wizard/create/SbtWizard.java
// public class SbtWizard extends BasicNewProjectResourceWizard {
//
// private CreateSbtProjectConfiguration configuration = CreateSbtProjectConfiguration.getDefault();
//
// @Override
// public void addPages() {
// super.addPages();
// WizardNewProjectCreationPage mainPage = (WizardNewProjectCreationPage) getPage("basicNewProjectPage");
// addPage(new SbtProjectWizardPage(mainPage, configuration));
// addPage(new SbtOptionsWizardPage(configuration));
// }
//
// @Override
// public boolean performFinish() {
// if (super.performFinish() == false) {
// return false;
// }
//
// configuration.setProject(getNewProject());
//
// try {
// CreateSbtProjectJob job = new CreateSbtProjectJob(configuration);
// job.schedule();
// return true;
// } catch (Exception e) {
// UIUtil.showErrorDialog(e.toString());
// SbtPlugin.logException(e);
// return false;
// }
// }
// }
| import org.eclipse.core.resources.IProject;
import com.github.jarlakxen.scala.sbt.SbtVersion;
import com.github.jarlakxen.scala.sbt.ScalaVersion;
import com.github.jarlakxen.scala.sbt.builder.TestLibrary;
import com.github.jarlakxen.scala.sbt.wizard.create.SbtWizard; | package com.github.jarlakxen.scala.sbt.configurations;
/**
* Configuration for create SBT project.
*
* @see SbtWizard
* @author Facundo Viale
*/
public class CreateSbtProjectConfiguration {
public static CreateSbtProjectConfiguration getDefault(){
CreateSbtProjectConfiguration configuration = new CreateSbtProjectConfiguration(); | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtVersion.java
// public enum SbtVersion {
//
// /**
// * SBT 0.11
// */
// SBT011("0.11", "0.11.3-2"),
//
// /**
// * SBT 0.12
// */
// SBT012("0.12", "0.12.4"),
//
// /**
// * SBT 0.13
// */
// SBT013("0.13", "0.13.0");
//
// public static SbtVersion getDefault() {
// return SBT013;
// }
//
// public static SbtVersion getVersion(String version) {
// for (SbtVersion value : values()) {
// if (version.startsWith(value.prefix)) {
// return value;
// }
// }
// return null;
// }
//
// private String prefix;
// private String lastVersion;
//
// private SbtVersion(String prefix, String lastVersion) {
// this.prefix = prefix;
// this.lastVersion = lastVersion;
// }
//
// public String getPrefix() {
// return prefix;
// }
//
// public String getLastVersion() {
// return lastVersion;
// }
//
// public String getLauncherJarName() {
// return "sbt-launch-" + lastVersion + ".jar";
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/ScalaVersion.java
// public enum ScalaVersion {
// V_2_10_3("2.10.3"),
// V_2_10_2("2.10.2"),
// V_2_10_1("2.10.1"),
// V_2_9_3("2.9.3"),
// V_2_9_2("2.9.2");
//
// public static ScalaVersion getDefault() {
// return V_2_10_3;
// }
//
// public static ScalaVersion versionOf(String text){
// for(ScalaVersion version : values()){
// if(version.getText().equals(text)){
// return version;
// }
// }
// return null;
// }
//
// private final String text;
// private final String baseVersion;
//
// private ScalaVersion(String text) {
// this.text = text;
// this.baseVersion = text.substring(0, text.lastIndexOf("."));
// }
//
// public String getText() {
// return text;
// }
//
// public String getBaseVersion(){
// return baseVersion;
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/builder/TestLibrary.java
// public enum TestLibrary {
// SPECS2 {
// @Override
// protected void populate(Map<String, String> dependancyMap) {
// dependancyMap.put("2.10", "\"org.specs2\" %% \"specs2\" % \"2.2.3\" % \"test\"");
// dependancyMap.put("2.9", "\"org.specs2\" %% \"specs2\" % \"1.12.4.1\" % \"test\"");
// }
// };
//
// private Map<String, String> dependancyMap;
//
// private TestLibrary() {
// dependancyMap = new HashMap<String, String>();
// populate(dependancyMap);
// }
//
// protected abstract void populate(Map<String, String> dependancyMap);
//
// public String getDependancy(ScalaVersion version) {
// if(dependancyMap.containsKey(version.getText())){
// return dependancyMap.get(version.getText());
// }
//
// return dependancyMap.get(version.getBaseVersion());
// }
//
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/wizard/create/SbtWizard.java
// public class SbtWizard extends BasicNewProjectResourceWizard {
//
// private CreateSbtProjectConfiguration configuration = CreateSbtProjectConfiguration.getDefault();
//
// @Override
// public void addPages() {
// super.addPages();
// WizardNewProjectCreationPage mainPage = (WizardNewProjectCreationPage) getPage("basicNewProjectPage");
// addPage(new SbtProjectWizardPage(mainPage, configuration));
// addPage(new SbtOptionsWizardPage(configuration));
// }
//
// @Override
// public boolean performFinish() {
// if (super.performFinish() == false) {
// return false;
// }
//
// configuration.setProject(getNewProject());
//
// try {
// CreateSbtProjectJob job = new CreateSbtProjectJob(configuration);
// job.schedule();
// return true;
// } catch (Exception e) {
// UIUtil.showErrorDialog(e.toString());
// SbtPlugin.logException(e);
// return false;
// }
// }
// }
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/configurations/CreateSbtProjectConfiguration.java
import org.eclipse.core.resources.IProject;
import com.github.jarlakxen.scala.sbt.SbtVersion;
import com.github.jarlakxen.scala.sbt.ScalaVersion;
import com.github.jarlakxen.scala.sbt.builder.TestLibrary;
import com.github.jarlakxen.scala.sbt.wizard.create.SbtWizard;
package com.github.jarlakxen.scala.sbt.configurations;
/**
* Configuration for create SBT project.
*
* @see SbtWizard
* @author Facundo Viale
*/
public class CreateSbtProjectConfiguration {
public static CreateSbtProjectConfiguration getDefault(){
CreateSbtProjectConfiguration configuration = new CreateSbtProjectConfiguration(); | configuration.setSbtVersion(SbtVersion.SBT013); |
Jarlakxen/eclipse-sbt-plugin | com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtPropertyPage.java | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/util/UIUtil.java
// public class UIUtil {
//
// /**
// * Creates the Label with the given text.
// *
// * @param parent
// * the parent composite
// * @param text
// * the label text
// */
// public static Label createLabel(Composite parent, String text) {
// return createLabel(parent, text, null);
// }
//
// /**
// * Creates the Label with the given text.
// *
// * @param parent
// * the parent composite
// * @param text
// * the label text
// */
// public static Label createLabel(Composite parent, String text, GridData gridData) {
// Label label = new Label(parent, SWT.NULL);
// label.setText(text);
// if (gridData != null) {
// label.setLayoutData(gridData);
// }
// label.setAlignment(SWT.VERTICAL + SWT.CENTER);
// return label;
// }
//
// /**
// * Shows the error dialog with the given message.
// *
// * @param message
// * the error message to show in the dialog.
// */
// public static void showErrorDialog(final String message) {
// Display.getDefault().syncExec(new Runnable() {
// @Override
// public void run() {
// MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", message);
// }
// });
// }
//
// public static GridData createGridData(int option, int colspan) {
// GridData gd = new GridData(option);
// gd.horizontalSpan = colspan;
// return gd;
// }
//
// public static GridData createGridDataWithWidth(int width) {
// GridData gd = new GridData();
// gd.minimumWidth = width;
// gd.widthHint = width;
// return gd;
// }
// }
| import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchPropertyPage;
import org.eclipse.ui.dialogs.PropertyPage;
import com.github.jarlakxen.scala.sbt.util.UIUtil;
| package com.github.jarlakxen.scala.sbt;
/**
* The property page to configure the SBT project.
*
* @author Naoki Takezoe
*/
public class SbtPropertyPage extends PropertyPage implements IWorkbenchPropertyPage {
private List<Button> sbtRadioButtons;
@Override
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// sbt version
| // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/util/UIUtil.java
// public class UIUtil {
//
// /**
// * Creates the Label with the given text.
// *
// * @param parent
// * the parent composite
// * @param text
// * the label text
// */
// public static Label createLabel(Composite parent, String text) {
// return createLabel(parent, text, null);
// }
//
// /**
// * Creates the Label with the given text.
// *
// * @param parent
// * the parent composite
// * @param text
// * the label text
// */
// public static Label createLabel(Composite parent, String text, GridData gridData) {
// Label label = new Label(parent, SWT.NULL);
// label.setText(text);
// if (gridData != null) {
// label.setLayoutData(gridData);
// }
// label.setAlignment(SWT.VERTICAL + SWT.CENTER);
// return label;
// }
//
// /**
// * Shows the error dialog with the given message.
// *
// * @param message
// * the error message to show in the dialog.
// */
// public static void showErrorDialog(final String message) {
// Display.getDefault().syncExec(new Runnable() {
// @Override
// public void run() {
// MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", message);
// }
// });
// }
//
// public static GridData createGridData(int option, int colspan) {
// GridData gd = new GridData(option);
// gd.horizontalSpan = colspan;
// return gd;
// }
//
// public static GridData createGridDataWithWidth(int width) {
// GridData gd = new GridData();
// gd.minimumWidth = width;
// gd.widthHint = width;
// return gd;
// }
// }
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtPropertyPage.java
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchPropertyPage;
import org.eclipse.ui.dialogs.PropertyPage;
import com.github.jarlakxen.scala.sbt.util.UIUtil;
package com.github.jarlakxen.scala.sbt;
/**
* The property page to configure the SBT project.
*
* @author Naoki Takezoe
*/
public class SbtPropertyPage extends PropertyPage implements IWorkbenchPropertyPage {
private List<Button> sbtRadioButtons;
@Override
protected Control createContents(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// sbt version
| UIUtil.createLabel(composite, "SBT Version:");
|
Jarlakxen/eclipse-sbt-plugin | com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/builder/TemplateBuilder.java | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtVersion.java
// public enum SbtVersion {
//
// /**
// * SBT 0.11
// */
// SBT011("0.11", "0.11.3-2"),
//
// /**
// * SBT 0.12
// */
// SBT012("0.12", "0.12.4"),
//
// /**
// * SBT 0.13
// */
// SBT013("0.13", "0.13.0");
//
// public static SbtVersion getDefault() {
// return SBT013;
// }
//
// public static SbtVersion getVersion(String version) {
// for (SbtVersion value : values()) {
// if (version.startsWith(value.prefix)) {
// return value;
// }
// }
// return null;
// }
//
// private String prefix;
// private String lastVersion;
//
// private SbtVersion(String prefix, String lastVersion) {
// this.prefix = prefix;
// this.lastVersion = lastVersion;
// }
//
// public String getPrefix() {
// return prefix;
// }
//
// public String getLastVersion() {
// return lastVersion;
// }
//
// public String getLauncherJarName() {
// return "sbt-launch-" + lastVersion + ".jar";
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/ScalaVersion.java
// public enum ScalaVersion {
// V_2_10_3("2.10.3"),
// V_2_10_2("2.10.2"),
// V_2_10_1("2.10.1"),
// V_2_9_3("2.9.3"),
// V_2_9_2("2.9.2");
//
// public static ScalaVersion getDefault() {
// return V_2_10_3;
// }
//
// public static ScalaVersion versionOf(String text){
// for(ScalaVersion version : values()){
// if(version.getText().equals(text)){
// return version;
// }
// }
// return null;
// }
//
// private final String text;
// private final String baseVersion;
//
// private ScalaVersion(String text) {
// this.text = text;
// this.baseVersion = text.substring(0, text.lastIndexOf("."));
// }
//
// public String getText() {
// return text;
// }
//
// public String getBaseVersion(){
// return baseVersion;
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/wizard/create/SbtWizard.java
// public class SbtWizard extends BasicNewProjectResourceWizard {
//
// private CreateSbtProjectConfiguration configuration = CreateSbtProjectConfiguration.getDefault();
//
// @Override
// public void addPages() {
// super.addPages();
// WizardNewProjectCreationPage mainPage = (WizardNewProjectCreationPage) getPage("basicNewProjectPage");
// addPage(new SbtProjectWizardPage(mainPage, configuration));
// addPage(new SbtOptionsWizardPage(configuration));
// }
//
// @Override
// public boolean performFinish() {
// if (super.performFinish() == false) {
// return false;
// }
//
// configuration.setProject(getNewProject());
//
// try {
// CreateSbtProjectJob job = new CreateSbtProjectJob(configuration);
// job.schedule();
// return true;
// } catch (Exception e) {
// UIUtil.showErrorDialog(e.toString());
// SbtPlugin.logException(e);
// return false;
// }
// }
// }
| import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.github.jarlakxen.scala.sbt.SbtVersion;
import com.github.jarlakxen.scala.sbt.ScalaVersion;
import com.github.jarlakxen.scala.sbt.wizard.create.SbtWizard; | package com.github.jarlakxen.scala.sbt.builder;
/**
* TemplateBuilder for SBT files
*
* @see SbtWizard
* @author Facundo Viale
*/
public class TemplateBuilder {
private static final String BR = System.getProperty("line.separator");
// Template for build.sbt
public static SbtTemplateBuilder createSbtTemplate() {
return new SbtTemplateBuilder();
}
public static class SbtTemplateBuilder { | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtVersion.java
// public enum SbtVersion {
//
// /**
// * SBT 0.11
// */
// SBT011("0.11", "0.11.3-2"),
//
// /**
// * SBT 0.12
// */
// SBT012("0.12", "0.12.4"),
//
// /**
// * SBT 0.13
// */
// SBT013("0.13", "0.13.0");
//
// public static SbtVersion getDefault() {
// return SBT013;
// }
//
// public static SbtVersion getVersion(String version) {
// for (SbtVersion value : values()) {
// if (version.startsWith(value.prefix)) {
// return value;
// }
// }
// return null;
// }
//
// private String prefix;
// private String lastVersion;
//
// private SbtVersion(String prefix, String lastVersion) {
// this.prefix = prefix;
// this.lastVersion = lastVersion;
// }
//
// public String getPrefix() {
// return prefix;
// }
//
// public String getLastVersion() {
// return lastVersion;
// }
//
// public String getLauncherJarName() {
// return "sbt-launch-" + lastVersion + ".jar";
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/ScalaVersion.java
// public enum ScalaVersion {
// V_2_10_3("2.10.3"),
// V_2_10_2("2.10.2"),
// V_2_10_1("2.10.1"),
// V_2_9_3("2.9.3"),
// V_2_9_2("2.9.2");
//
// public static ScalaVersion getDefault() {
// return V_2_10_3;
// }
//
// public static ScalaVersion versionOf(String text){
// for(ScalaVersion version : values()){
// if(version.getText().equals(text)){
// return version;
// }
// }
// return null;
// }
//
// private final String text;
// private final String baseVersion;
//
// private ScalaVersion(String text) {
// this.text = text;
// this.baseVersion = text.substring(0, text.lastIndexOf("."));
// }
//
// public String getText() {
// return text;
// }
//
// public String getBaseVersion(){
// return baseVersion;
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/wizard/create/SbtWizard.java
// public class SbtWizard extends BasicNewProjectResourceWizard {
//
// private CreateSbtProjectConfiguration configuration = CreateSbtProjectConfiguration.getDefault();
//
// @Override
// public void addPages() {
// super.addPages();
// WizardNewProjectCreationPage mainPage = (WizardNewProjectCreationPage) getPage("basicNewProjectPage");
// addPage(new SbtProjectWizardPage(mainPage, configuration));
// addPage(new SbtOptionsWizardPage(configuration));
// }
//
// @Override
// public boolean performFinish() {
// if (super.performFinish() == false) {
// return false;
// }
//
// configuration.setProject(getNewProject());
//
// try {
// CreateSbtProjectJob job = new CreateSbtProjectJob(configuration);
// job.schedule();
// return true;
// } catch (Exception e) {
// UIUtil.showErrorDialog(e.toString());
// SbtPlugin.logException(e);
// return false;
// }
// }
// }
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/builder/TemplateBuilder.java
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.github.jarlakxen.scala.sbt.SbtVersion;
import com.github.jarlakxen.scala.sbt.ScalaVersion;
import com.github.jarlakxen.scala.sbt.wizard.create.SbtWizard;
package com.github.jarlakxen.scala.sbt.builder;
/**
* TemplateBuilder for SBT files
*
* @see SbtWizard
* @author Facundo Viale
*/
public class TemplateBuilder {
private static final String BR = System.getProperty("line.separator");
// Template for build.sbt
public static SbtTemplateBuilder createSbtTemplate() {
return new SbtTemplateBuilder();
}
public static class SbtTemplateBuilder { | private ScalaVersion scalaVersion; |
Jarlakxen/eclipse-sbt-plugin | com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/builder/TemplateBuilder.java | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtVersion.java
// public enum SbtVersion {
//
// /**
// * SBT 0.11
// */
// SBT011("0.11", "0.11.3-2"),
//
// /**
// * SBT 0.12
// */
// SBT012("0.12", "0.12.4"),
//
// /**
// * SBT 0.13
// */
// SBT013("0.13", "0.13.0");
//
// public static SbtVersion getDefault() {
// return SBT013;
// }
//
// public static SbtVersion getVersion(String version) {
// for (SbtVersion value : values()) {
// if (version.startsWith(value.prefix)) {
// return value;
// }
// }
// return null;
// }
//
// private String prefix;
// private String lastVersion;
//
// private SbtVersion(String prefix, String lastVersion) {
// this.prefix = prefix;
// this.lastVersion = lastVersion;
// }
//
// public String getPrefix() {
// return prefix;
// }
//
// public String getLastVersion() {
// return lastVersion;
// }
//
// public String getLauncherJarName() {
// return "sbt-launch-" + lastVersion + ".jar";
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/ScalaVersion.java
// public enum ScalaVersion {
// V_2_10_3("2.10.3"),
// V_2_10_2("2.10.2"),
// V_2_10_1("2.10.1"),
// V_2_9_3("2.9.3"),
// V_2_9_2("2.9.2");
//
// public static ScalaVersion getDefault() {
// return V_2_10_3;
// }
//
// public static ScalaVersion versionOf(String text){
// for(ScalaVersion version : values()){
// if(version.getText().equals(text)){
// return version;
// }
// }
// return null;
// }
//
// private final String text;
// private final String baseVersion;
//
// private ScalaVersion(String text) {
// this.text = text;
// this.baseVersion = text.substring(0, text.lastIndexOf("."));
// }
//
// public String getText() {
// return text;
// }
//
// public String getBaseVersion(){
// return baseVersion;
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/wizard/create/SbtWizard.java
// public class SbtWizard extends BasicNewProjectResourceWizard {
//
// private CreateSbtProjectConfiguration configuration = CreateSbtProjectConfiguration.getDefault();
//
// @Override
// public void addPages() {
// super.addPages();
// WizardNewProjectCreationPage mainPage = (WizardNewProjectCreationPage) getPage("basicNewProjectPage");
// addPage(new SbtProjectWizardPage(mainPage, configuration));
// addPage(new SbtOptionsWizardPage(configuration));
// }
//
// @Override
// public boolean performFinish() {
// if (super.performFinish() == false) {
// return false;
// }
//
// configuration.setProject(getNewProject());
//
// try {
// CreateSbtProjectJob job = new CreateSbtProjectJob(configuration);
// job.schedule();
// return true;
// } catch (Exception e) {
// UIUtil.showErrorDialog(e.toString());
// SbtPlugin.logException(e);
// return false;
// }
// }
// }
| import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.github.jarlakxen.scala.sbt.SbtVersion;
import com.github.jarlakxen.scala.sbt.ScalaVersion;
import com.github.jarlakxen.scala.sbt.wizard.create.SbtWizard; |
if (webNature) {
builder.append("seq(webSettings :_*)").append(BR).append(BR);
}
List<String> libraryDependencies = new ArrayList<String>();
if (testLibrary != null) {
libraryDependencies.add( testLibrary.getDependancy(scalaVersion));
}
if (webNature) {
libraryDependencies.add( "\"org.mortbay.jetty\" % \"jetty\" % \"6.1.22\" % \"container\"");
}
builder.append("libraryDependencies ++= Seq(");
if (!libraryDependencies.isEmpty()) {
builder.append(BR).append(StringUtils.join(libraryDependencies, "," + BR )).append(BR);
}
builder.append(")").append(BR).append(BR);
return builder.toString();
}
}
// Template for project/build.properties
public static SbtPropertiesTemplateBuilder createSbtPropertiesTemplate() {
return new SbtPropertiesTemplateBuilder();
}
public static class SbtPropertiesTemplateBuilder { | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtVersion.java
// public enum SbtVersion {
//
// /**
// * SBT 0.11
// */
// SBT011("0.11", "0.11.3-2"),
//
// /**
// * SBT 0.12
// */
// SBT012("0.12", "0.12.4"),
//
// /**
// * SBT 0.13
// */
// SBT013("0.13", "0.13.0");
//
// public static SbtVersion getDefault() {
// return SBT013;
// }
//
// public static SbtVersion getVersion(String version) {
// for (SbtVersion value : values()) {
// if (version.startsWith(value.prefix)) {
// return value;
// }
// }
// return null;
// }
//
// private String prefix;
// private String lastVersion;
//
// private SbtVersion(String prefix, String lastVersion) {
// this.prefix = prefix;
// this.lastVersion = lastVersion;
// }
//
// public String getPrefix() {
// return prefix;
// }
//
// public String getLastVersion() {
// return lastVersion;
// }
//
// public String getLauncherJarName() {
// return "sbt-launch-" + lastVersion + ".jar";
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/ScalaVersion.java
// public enum ScalaVersion {
// V_2_10_3("2.10.3"),
// V_2_10_2("2.10.2"),
// V_2_10_1("2.10.1"),
// V_2_9_3("2.9.3"),
// V_2_9_2("2.9.2");
//
// public static ScalaVersion getDefault() {
// return V_2_10_3;
// }
//
// public static ScalaVersion versionOf(String text){
// for(ScalaVersion version : values()){
// if(version.getText().equals(text)){
// return version;
// }
// }
// return null;
// }
//
// private final String text;
// private final String baseVersion;
//
// private ScalaVersion(String text) {
// this.text = text;
// this.baseVersion = text.substring(0, text.lastIndexOf("."));
// }
//
// public String getText() {
// return text;
// }
//
// public String getBaseVersion(){
// return baseVersion;
// }
// }
//
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/wizard/create/SbtWizard.java
// public class SbtWizard extends BasicNewProjectResourceWizard {
//
// private CreateSbtProjectConfiguration configuration = CreateSbtProjectConfiguration.getDefault();
//
// @Override
// public void addPages() {
// super.addPages();
// WizardNewProjectCreationPage mainPage = (WizardNewProjectCreationPage) getPage("basicNewProjectPage");
// addPage(new SbtProjectWizardPage(mainPage, configuration));
// addPage(new SbtOptionsWizardPage(configuration));
// }
//
// @Override
// public boolean performFinish() {
// if (super.performFinish() == false) {
// return false;
// }
//
// configuration.setProject(getNewProject());
//
// try {
// CreateSbtProjectJob job = new CreateSbtProjectJob(configuration);
// job.schedule();
// return true;
// } catch (Exception e) {
// UIUtil.showErrorDialog(e.toString());
// SbtPlugin.logException(e);
// return false;
// }
// }
// }
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/builder/TemplateBuilder.java
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.github.jarlakxen.scala.sbt.SbtVersion;
import com.github.jarlakxen.scala.sbt.ScalaVersion;
import com.github.jarlakxen.scala.sbt.wizard.create.SbtWizard;
if (webNature) {
builder.append("seq(webSettings :_*)").append(BR).append(BR);
}
List<String> libraryDependencies = new ArrayList<String>();
if (testLibrary != null) {
libraryDependencies.add( testLibrary.getDependancy(scalaVersion));
}
if (webNature) {
libraryDependencies.add( "\"org.mortbay.jetty\" % \"jetty\" % \"6.1.22\" % \"container\"");
}
builder.append("libraryDependencies ++= Seq(");
if (!libraryDependencies.isEmpty()) {
builder.append(BR).append(StringUtils.join(libraryDependencies, "," + BR )).append(BR);
}
builder.append(")").append(BR).append(BR);
return builder.toString();
}
}
// Template for project/build.properties
public static SbtPropertiesTemplateBuilder createSbtPropertiesTemplate() {
return new SbtPropertiesTemplateBuilder();
}
public static class SbtPropertiesTemplateBuilder { | private SbtVersion sbtVersion; |
Jarlakxen/eclipse-sbt-plugin | com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtExecutor.java | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/util/UIUtil.java
// public class UIUtil {
//
// /**
// * Creates the Label with the given text.
// *
// * @param parent
// * the parent composite
// * @param text
// * the label text
// */
// public static Label createLabel(Composite parent, String text) {
// return createLabel(parent, text, null);
// }
//
// /**
// * Creates the Label with the given text.
// *
// * @param parent
// * the parent composite
// * @param text
// * the label text
// */
// public static Label createLabel(Composite parent, String text, GridData gridData) {
// Label label = new Label(parent, SWT.NULL);
// label.setText(text);
// if (gridData != null) {
// label.setLayoutData(gridData);
// }
// label.setAlignment(SWT.VERTICAL + SWT.CENTER);
// return label;
// }
//
// /**
// * Shows the error dialog with the given message.
// *
// * @param message
// * the error message to show in the dialog.
// */
// public static void showErrorDialog(final String message) {
// Display.getDefault().syncExec(new Runnable() {
// @Override
// public void run() {
// MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", message);
// }
// });
// }
//
// public static GridData createGridData(int option, int colspan) {
// GridData gd = new GridData(option);
// gd.horizontalSpan = colspan;
// return gd;
// }
//
// public static GridData createGridDataWithWidth(int width) {
// GridData gd = new GridData();
// gd.minimumWidth = width;
// gd.widthHint = width;
// return gd;
// }
// }
| import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
import org.eclipse.core.net.proxy.IProxyData;
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.IStreamListener;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.github.jarlakxen.scala.sbt.util.UIUtil;
|
// Creates new configuration
ILaunchConfigurationWorkingCopy wc = null;
if(command == null || command.length() == 0){
wc = type.newInstance(null, String.format("sbt - %s", project.getName()));
} else {
wc = type.newInstance(null, String.format("sbt %s - %s", command, project.getName()));
}
// Sets the project name
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName());
// Sets the main class
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "xsbt.boot.Boot");
// Sets the VM arguments
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, createVMarguments(projectConfig));
// Sets the working directory if it's specified
if(this.workDir != null){
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, workDir.getAbsolutePath());
}
// Sets the classpath
File jarFile = projectConfig.getProjectSbtRuntime();
URL sbtRuntimeUrl = null;
if(jarFile != null){
sbtRuntimeUrl = jarFile.toURI().toURL();
}
if(sbtRuntimeUrl == null){
| // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/util/UIUtil.java
// public class UIUtil {
//
// /**
// * Creates the Label with the given text.
// *
// * @param parent
// * the parent composite
// * @param text
// * the label text
// */
// public static Label createLabel(Composite parent, String text) {
// return createLabel(parent, text, null);
// }
//
// /**
// * Creates the Label with the given text.
// *
// * @param parent
// * the parent composite
// * @param text
// * the label text
// */
// public static Label createLabel(Composite parent, String text, GridData gridData) {
// Label label = new Label(parent, SWT.NULL);
// label.setText(text);
// if (gridData != null) {
// label.setLayoutData(gridData);
// }
// label.setAlignment(SWT.VERTICAL + SWT.CENTER);
// return label;
// }
//
// /**
// * Shows the error dialog with the given message.
// *
// * @param message
// * the error message to show in the dialog.
// */
// public static void showErrorDialog(final String message) {
// Display.getDefault().syncExec(new Runnable() {
// @Override
// public void run() {
// MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", message);
// }
// });
// }
//
// public static GridData createGridData(int option, int colspan) {
// GridData gd = new GridData(option);
// gd.horizontalSpan = colspan;
// return gd;
// }
//
// public static GridData createGridDataWithWidth(int width) {
// GridData gd = new GridData();
// gd.minimumWidth = width;
// gd.widthHint = width;
// return gd;
// }
// }
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtExecutor.java
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
import org.eclipse.core.net.proxy.IProxyData;
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.IStreamListener;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStreamMonitor;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.eclipse.jdt.launching.JavaRuntime;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.github.jarlakxen.scala.sbt.util.UIUtil;
// Creates new configuration
ILaunchConfigurationWorkingCopy wc = null;
if(command == null || command.length() == 0){
wc = type.newInstance(null, String.format("sbt - %s", project.getName()));
} else {
wc = type.newInstance(null, String.format("sbt %s - %s", command, project.getName()));
}
// Sets the project name
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, project.getName());
// Sets the main class
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "xsbt.boot.Boot");
// Sets the VM arguments
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, createVMarguments(projectConfig));
// Sets the working directory if it's specified
if(this.workDir != null){
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, workDir.getAbsolutePath());
}
// Sets the classpath
File jarFile = projectConfig.getProjectSbtRuntime();
URL sbtRuntimeUrl = null;
if(jarFile != null){
sbtRuntimeUrl = jarFile.toURI().toURL();
}
if(sbtRuntimeUrl == null){
| UIUtil.showErrorDialog("Can't find SBT runtime in your project.");
|
Jarlakxen/eclipse-sbt-plugin | com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/action/DownloadSourceAction.java | // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtPlugin.java
// public class SbtPlugin extends AbstractUIPlugin {
//
// public static final String[] PROJECT_NATURES_IDS = new String[] {
// ScalaPlugin.plugin().natureId(),
// "org.eclipse.jdt.core.javanature",
// SbtPlugin.NATURE_ID
// };
//
// /** The plug-in ID */
// public static final String PLUGIN_ID = "com.github.jarlakxen.scala.sbt"; //$NON-NLS-1$
//
// /** The nature ID */
// public static final String NATURE_ID = PLUGIN_ID + ".SbtProjectNature"; //$NON-NLS-1$
//
// // The shared instance
// private static SbtPlugin plugin;
//
// public static final String ICON_SETTING_KEY = "/icons/setting_key.gif";
// public static final String ICON_SETTING_VALUE = "/icons/setting_value.gif";
//
// /**
// * The constructor
// */
// public SbtPlugin() {
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
// * )
// */
// public void start(BundleContext context) throws Exception {
// super.start(context);
// plugin = this;
// SbtProjectFilesChangeListener.register();
// SbtLaunchJarManager.deploy();
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
// * )
// */
// public void stop(BundleContext context) throws Exception {
// SbtLaunchJarManager.undeploy();
// plugin = null;
// super.stop(context);
// }
//
// protected void initializeImageRegistry(ImageRegistry registory) {
// super.initializeImageRegistry(registory);
// registory.put(ICON_SETTING_KEY, ImageDescriptor.createFromURL(getBundle().getEntry(ICON_SETTING_KEY)));
// registory.put(ICON_SETTING_VALUE, ImageDescriptor.createFromURL(getBundle().getEntry(ICON_SETTING_VALUE)));
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static SbtPlugin getDefault() {
// return plugin;
// }
//
// public static void logException(Exception ex) {
// IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, ex.toString(), ex);
// getDefault().getLog().log(status);
// }
//
// public static void addProjectNatures(IProject project) throws CoreException {
// IProjectDescription desc = project.getDescription();
// desc.setNatureIds(PROJECT_NATURES_IDS);
// project.setDescription(desc, null);
// }
// }
| import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import com.github.jarlakxen.scala.sbt.SbtPlugin;
| package com.github.jarlakxen.scala.sbt.action;
/**
* Updates project dependency.
*
* @author Facundo Viale
*/
public class DownloadSourceAction extends AbstractSbtCommandAction {
public DownloadSourceAction() {
super("'eclipse with-source=true'");
}
@Override
public void run(IAction action) {
super.run(action);
try {
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
| // Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/SbtPlugin.java
// public class SbtPlugin extends AbstractUIPlugin {
//
// public static final String[] PROJECT_NATURES_IDS = new String[] {
// ScalaPlugin.plugin().natureId(),
// "org.eclipse.jdt.core.javanature",
// SbtPlugin.NATURE_ID
// };
//
// /** The plug-in ID */
// public static final String PLUGIN_ID = "com.github.jarlakxen.scala.sbt"; //$NON-NLS-1$
//
// /** The nature ID */
// public static final String NATURE_ID = PLUGIN_ID + ".SbtProjectNature"; //$NON-NLS-1$
//
// // The shared instance
// private static SbtPlugin plugin;
//
// public static final String ICON_SETTING_KEY = "/icons/setting_key.gif";
// public static final String ICON_SETTING_VALUE = "/icons/setting_value.gif";
//
// /**
// * The constructor
// */
// public SbtPlugin() {
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
// * )
// */
// public void start(BundleContext context) throws Exception {
// super.start(context);
// plugin = this;
// SbtProjectFilesChangeListener.register();
// SbtLaunchJarManager.deploy();
// }
//
// /*
// * (non-Javadoc)
// *
// * @see
// * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
// * )
// */
// public void stop(BundleContext context) throws Exception {
// SbtLaunchJarManager.undeploy();
// plugin = null;
// super.stop(context);
// }
//
// protected void initializeImageRegistry(ImageRegistry registory) {
// super.initializeImageRegistry(registory);
// registory.put(ICON_SETTING_KEY, ImageDescriptor.createFromURL(getBundle().getEntry(ICON_SETTING_KEY)));
// registory.put(ICON_SETTING_VALUE, ImageDescriptor.createFromURL(getBundle().getEntry(ICON_SETTING_VALUE)));
// }
//
// /**
// * Returns the shared instance
// *
// * @return the shared instance
// */
// public static SbtPlugin getDefault() {
// return plugin;
// }
//
// public static void logException(Exception ex) {
// IStatus status = new Status(IStatus.ERROR, PLUGIN_ID, ex.toString(), ex);
// getDefault().getLog().log(status);
// }
//
// public static void addProjectNatures(IProject project) throws CoreException {
// IProjectDescription desc = project.getDescription();
// desc.setNatureIds(PROJECT_NATURES_IDS);
// project.setDescription(desc, null);
// }
// }
// Path: com.github.jarlakxen.scala.sbt/src/com/github/jarlakxen/scala/sbt/action/DownloadSourceAction.java
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import com.github.jarlakxen.scala.sbt.SbtPlugin;
package com.github.jarlakxen.scala.sbt.action;
/**
* Updates project dependency.
*
* @author Facundo Viale
*/
public class DownloadSourceAction extends AbstractSbtCommandAction {
public DownloadSourceAction() {
super("'eclipse with-source=true'");
}
@Override
public void run(IAction action) {
super.run(action);
try {
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
| SbtPlugin.addProjectNatures(project);
|
caligin/tinytypes | examples/src/test/java/tech/anima/tinytypes/examples/DropwizardJerseyClientTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: jackson/src/main/java/tech/anima/tinytypes/jackson/TinyTypesModule.java
// public final class TinyTypesModule extends Module {
//
// @Override
// public String getModuleName() {
// return "TinyTypes";
// }
//
// @Override
// public Version version() {
// return new Version(1, 1, 0, "SNAPSHOT", "tech.anima", "jackson-datatype-tinytypes");
// }
//
// @Override
// public void setupModule(SetupContext context) {
// context.addKeySerializers(new TinyTypesKeySerializers());
// context.addSerializers(new TinyTypesSerializers());
// context.addDeserializers(new TinyTypesDeserializers());
// context.addKeyDeserializers(new TinyTypesKeyDeserializers());
// }
//
// }
| import com.codahale.metrics.MetricRegistry;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.client.JerseyClientConfiguration;
import io.dropwizard.setup.Environment;
import io.dropwizard.testing.junit.DropwizardClientRule;
import javax.validation.Validation;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.jackson.TinyTypesModule; | package tech.anima.tinytypes.examples;
@RunWith(Enclosed.class)
public class DropwizardJerseyClientTest {
@RunWith(Theories.class)
public static class JsonBodySerializationTest {
| // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: jackson/src/main/java/tech/anima/tinytypes/jackson/TinyTypesModule.java
// public final class TinyTypesModule extends Module {
//
// @Override
// public String getModuleName() {
// return "TinyTypes";
// }
//
// @Override
// public Version version() {
// return new Version(1, 1, 0, "SNAPSHOT", "tech.anima", "jackson-datatype-tinytypes");
// }
//
// @Override
// public void setupModule(SetupContext context) {
// context.addKeySerializers(new TinyTypesKeySerializers());
// context.addSerializers(new TinyTypesSerializers());
// context.addDeserializers(new TinyTypesDeserializers());
// context.addKeyDeserializers(new TinyTypesKeyDeserializers());
// }
//
// }
// Path: examples/src/test/java/tech/anima/tinytypes/examples/DropwizardJerseyClientTest.java
import com.codahale.metrics.MetricRegistry;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.client.JerseyClientConfiguration;
import io.dropwizard.setup.Environment;
import io.dropwizard.testing.junit.DropwizardClientRule;
import javax.validation.Validation;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.jackson.TinyTypesModule;
package tech.anima.tinytypes.examples;
@RunWith(Enclosed.class)
public class DropwizardJerseyClientTest {
@RunWith(Theories.class)
public static class JsonBodySerializationTest {
| private final Environment dwEnvironment = new Environment("env", new ObjectMapper().registerModule(new TinyTypesModule()), Validation.buildDefaultValidatorFactory().getValidator(), new MetricRegistry(), this.getClass().getClassLoader()); |
caligin/tinytypes | examples/src/test/java/tech/anima/tinytypes/examples/DropwizardJerseyClientTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: jackson/src/main/java/tech/anima/tinytypes/jackson/TinyTypesModule.java
// public final class TinyTypesModule extends Module {
//
// @Override
// public String getModuleName() {
// return "TinyTypes";
// }
//
// @Override
// public Version version() {
// return new Version(1, 1, 0, "SNAPSHOT", "tech.anima", "jackson-datatype-tinytypes");
// }
//
// @Override
// public void setupModule(SetupContext context) {
// context.addKeySerializers(new TinyTypesKeySerializers());
// context.addSerializers(new TinyTypesSerializers());
// context.addDeserializers(new TinyTypesDeserializers());
// context.addKeyDeserializers(new TinyTypesKeyDeserializers());
// }
//
// }
| import com.codahale.metrics.MetricRegistry;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.client.JerseyClientConfiguration;
import io.dropwizard.setup.Environment;
import io.dropwizard.testing.junit.DropwizardClientRule;
import javax.validation.Validation;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.jackson.TinyTypesModule; | package tech.anima.tinytypes.examples;
@RunWith(Enclosed.class)
public class DropwizardJerseyClientTest {
@RunWith(Theories.class)
public static class JsonBodySerializationTest {
private final Environment dwEnvironment = new Environment("env", new ObjectMapper().registerModule(new TinyTypesModule()), Validation.buildDefaultValidatorFactory().getValidator(), new MetricRegistry(), this.getClass().getClassLoader());
@ClassRule
public static final DropwizardClientRule deserializedEcho = new DropwizardClientRule(new DeserializedEchoResource());
@DataPoints | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: jackson/src/main/java/tech/anima/tinytypes/jackson/TinyTypesModule.java
// public final class TinyTypesModule extends Module {
//
// @Override
// public String getModuleName() {
// return "TinyTypes";
// }
//
// @Override
// public Version version() {
// return new Version(1, 1, 0, "SNAPSHOT", "tech.anima", "jackson-datatype-tinytypes");
// }
//
// @Override
// public void setupModule(SetupContext context) {
// context.addKeySerializers(new TinyTypesKeySerializers());
// context.addSerializers(new TinyTypesSerializers());
// context.addDeserializers(new TinyTypesDeserializers());
// context.addKeyDeserializers(new TinyTypesKeyDeserializers());
// }
//
// }
// Path: examples/src/test/java/tech/anima/tinytypes/examples/DropwizardJerseyClientTest.java
import com.codahale.metrics.MetricRegistry;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.client.JerseyClientConfiguration;
import io.dropwizard.setup.Environment;
import io.dropwizard.testing.junit.DropwizardClientRule;
import javax.validation.Validation;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.jackson.TinyTypesModule;
package tech.anima.tinytypes.examples;
@RunWith(Enclosed.class)
public class DropwizardJerseyClientTest {
@RunWith(Theories.class)
public static class JsonBodySerializationTest {
private final Environment dwEnvironment = new Environment("env", new ObjectMapper().registerModule(new TinyTypesModule()), Validation.buildDefaultValidatorFactory().getValidator(), new MetricRegistry(), this.getClass().getClassLoader());
@ClassRule
public static final DropwizardClientRule deserializedEcho = new DropwizardClientRule(new DeserializedEchoResource());
@DataPoints | public static final Object[] tts = new Object[]{new Samples.Boolean(true), new Samples.Str("1"), new Samples.Byte((byte) 1), new Samples.Short((byte) 1), new Samples.Integer(1), new Samples.Long(1)}; |
caligin/tinytypes | jersey/src/main/java/tech/anima/tinytypes/jersey/TinyTypesHeaderDelegateProvider.java | // Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyType.java
// public interface MetaTinyType<T> {
//
// /**
// * Checks whether this implementation can operate on the given TinyType
// * class type.
// *
// * @param candidate the TInyType type to check for compatibility
// * @return true if the candidate is supported, false otherwise
// */
// boolean isMetaOf(Class<?> candidate);
//
// /**
// * Returns a String representation of the value wrapped in the given
// * TinyType. The given TinyType must be compatible with this meta.
// *
// * @param value the TinyType to stringify
// * @return a String representation of the native value wrapped in the
// * TinyType
// */
// String stringify(T value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value. The given TinyType class type and the type of value must
// * both be compatible with this meta.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U newInstance(Class<U> type, Object value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value given in string form. The given TinyType class type must be
// * compatible with this meta, the given String value must be parseable as
// * the appropriate native type.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U fromString(Class<U> type, String value);
// }
//
// Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyTypes.java
// public abstract class MetaTinyTypes {
//
// public static final MetaTinyType[] metas = new MetaTinyType[]{
// new StringTinyTypes(),
// new BooleanTinyTypes(),
// new ByteTinyTypes(),
// new ShortTinyTypes(),
// new IntTinyTypes(),
// new LongTinyTypes()
// };
//
// /**
// * Provides a type-specific Meta class for the given TinyType.
// *
// * @param <T> the TinyType class type
// * @param candidate the TinyType class to obtain a Meta for
// * @return a Meta implementation suitable for the candidate
// * @throws IllegalArgumentException for null or a non-TinyType
// */
// public static <T> MetaTinyType<T> metaFor(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return meta;
// }
// }
// throw new IllegalArgumentException(String.format("not a tinytype: %s", candidate == null ? "null" : candidate.getCanonicalName()));
// }
//
// /**
// * Checks whether a class is a TinyType. A class is considered a TinyType if
// * is a direct ancestor of a tech.anima.tinytypes.*TinyType, is not abstract
// * and provides a ctor matching super.
// *
// * @param candidate the class to be checked
// * @return true if the candidate is a TinyType, false otherwise.
// */
// public static boolean isTinyType(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import javax.ws.rs.ext.Provider;
import tech.anima.tinytypes.meta.MetaTinyType;
import tech.anima.tinytypes.meta.MetaTinyTypes;
import org.glassfish.jersey.spi.HeaderDelegateProvider; | package tech.anima.tinytypes.jersey;
@Provider
public class TinyTypesHeaderDelegateProvider<T> implements HeaderDelegateProvider<T> {
private final Class<T> type; | // Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyType.java
// public interface MetaTinyType<T> {
//
// /**
// * Checks whether this implementation can operate on the given TinyType
// * class type.
// *
// * @param candidate the TInyType type to check for compatibility
// * @return true if the candidate is supported, false otherwise
// */
// boolean isMetaOf(Class<?> candidate);
//
// /**
// * Returns a String representation of the value wrapped in the given
// * TinyType. The given TinyType must be compatible with this meta.
// *
// * @param value the TinyType to stringify
// * @return a String representation of the native value wrapped in the
// * TinyType
// */
// String stringify(T value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value. The given TinyType class type and the type of value must
// * both be compatible with this meta.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U newInstance(Class<U> type, Object value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value given in string form. The given TinyType class type must be
// * compatible with this meta, the given String value must be parseable as
// * the appropriate native type.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U fromString(Class<U> type, String value);
// }
//
// Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyTypes.java
// public abstract class MetaTinyTypes {
//
// public static final MetaTinyType[] metas = new MetaTinyType[]{
// new StringTinyTypes(),
// new BooleanTinyTypes(),
// new ByteTinyTypes(),
// new ShortTinyTypes(),
// new IntTinyTypes(),
// new LongTinyTypes()
// };
//
// /**
// * Provides a type-specific Meta class for the given TinyType.
// *
// * @param <T> the TinyType class type
// * @param candidate the TinyType class to obtain a Meta for
// * @return a Meta implementation suitable for the candidate
// * @throws IllegalArgumentException for null or a non-TinyType
// */
// public static <T> MetaTinyType<T> metaFor(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return meta;
// }
// }
// throw new IllegalArgumentException(String.format("not a tinytype: %s", candidate == null ? "null" : candidate.getCanonicalName()));
// }
//
// /**
// * Checks whether a class is a TinyType. A class is considered a TinyType if
// * is a direct ancestor of a tech.anima.tinytypes.*TinyType, is not abstract
// * and provides a ctor matching super.
// *
// * @param candidate the class to be checked
// * @return true if the candidate is a TinyType, false otherwise.
// */
// public static boolean isTinyType(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: jersey/src/main/java/tech/anima/tinytypes/jersey/TinyTypesHeaderDelegateProvider.java
import javax.ws.rs.ext.Provider;
import tech.anima.tinytypes.meta.MetaTinyType;
import tech.anima.tinytypes.meta.MetaTinyTypes;
import org.glassfish.jersey.spi.HeaderDelegateProvider;
package tech.anima.tinytypes.jersey;
@Provider
public class TinyTypesHeaderDelegateProvider<T> implements HeaderDelegateProvider<T> {
private final Class<T> type; | private final MetaTinyType<T> meta; |
caligin/tinytypes | jersey/src/main/java/tech/anima/tinytypes/jersey/TinyTypesHeaderDelegateProvider.java | // Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyType.java
// public interface MetaTinyType<T> {
//
// /**
// * Checks whether this implementation can operate on the given TinyType
// * class type.
// *
// * @param candidate the TInyType type to check for compatibility
// * @return true if the candidate is supported, false otherwise
// */
// boolean isMetaOf(Class<?> candidate);
//
// /**
// * Returns a String representation of the value wrapped in the given
// * TinyType. The given TinyType must be compatible with this meta.
// *
// * @param value the TinyType to stringify
// * @return a String representation of the native value wrapped in the
// * TinyType
// */
// String stringify(T value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value. The given TinyType class type and the type of value must
// * both be compatible with this meta.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U newInstance(Class<U> type, Object value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value given in string form. The given TinyType class type must be
// * compatible with this meta, the given String value must be parseable as
// * the appropriate native type.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U fromString(Class<U> type, String value);
// }
//
// Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyTypes.java
// public abstract class MetaTinyTypes {
//
// public static final MetaTinyType[] metas = new MetaTinyType[]{
// new StringTinyTypes(),
// new BooleanTinyTypes(),
// new ByteTinyTypes(),
// new ShortTinyTypes(),
// new IntTinyTypes(),
// new LongTinyTypes()
// };
//
// /**
// * Provides a type-specific Meta class for the given TinyType.
// *
// * @param <T> the TinyType class type
// * @param candidate the TinyType class to obtain a Meta for
// * @return a Meta implementation suitable for the candidate
// * @throws IllegalArgumentException for null or a non-TinyType
// */
// public static <T> MetaTinyType<T> metaFor(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return meta;
// }
// }
// throw new IllegalArgumentException(String.format("not a tinytype: %s", candidate == null ? "null" : candidate.getCanonicalName()));
// }
//
// /**
// * Checks whether a class is a TinyType. A class is considered a TinyType if
// * is a direct ancestor of a tech.anima.tinytypes.*TinyType, is not abstract
// * and provides a ctor matching super.
// *
// * @param candidate the class to be checked
// * @return true if the candidate is a TinyType, false otherwise.
// */
// public static boolean isTinyType(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import javax.ws.rs.ext.Provider;
import tech.anima.tinytypes.meta.MetaTinyType;
import tech.anima.tinytypes.meta.MetaTinyTypes;
import org.glassfish.jersey.spi.HeaderDelegateProvider; | package tech.anima.tinytypes.jersey;
@Provider
public class TinyTypesHeaderDelegateProvider<T> implements HeaderDelegateProvider<T> {
private final Class<T> type;
private final MetaTinyType<T> meta;
public TinyTypesHeaderDelegateProvider(Class<T> concrete) {
this.type = concrete; | // Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyType.java
// public interface MetaTinyType<T> {
//
// /**
// * Checks whether this implementation can operate on the given TinyType
// * class type.
// *
// * @param candidate the TInyType type to check for compatibility
// * @return true if the candidate is supported, false otherwise
// */
// boolean isMetaOf(Class<?> candidate);
//
// /**
// * Returns a String representation of the value wrapped in the given
// * TinyType. The given TinyType must be compatible with this meta.
// *
// * @param value the TinyType to stringify
// * @return a String representation of the native value wrapped in the
// * TinyType
// */
// String stringify(T value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value. The given TinyType class type and the type of value must
// * both be compatible with this meta.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U newInstance(Class<U> type, Object value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value given in string form. The given TinyType class type must be
// * compatible with this meta, the given String value must be parseable as
// * the appropriate native type.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U fromString(Class<U> type, String value);
// }
//
// Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyTypes.java
// public abstract class MetaTinyTypes {
//
// public static final MetaTinyType[] metas = new MetaTinyType[]{
// new StringTinyTypes(),
// new BooleanTinyTypes(),
// new ByteTinyTypes(),
// new ShortTinyTypes(),
// new IntTinyTypes(),
// new LongTinyTypes()
// };
//
// /**
// * Provides a type-specific Meta class for the given TinyType.
// *
// * @param <T> the TinyType class type
// * @param candidate the TinyType class to obtain a Meta for
// * @return a Meta implementation suitable for the candidate
// * @throws IllegalArgumentException for null or a non-TinyType
// */
// public static <T> MetaTinyType<T> metaFor(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return meta;
// }
// }
// throw new IllegalArgumentException(String.format("not a tinytype: %s", candidate == null ? "null" : candidate.getCanonicalName()));
// }
//
// /**
// * Checks whether a class is a TinyType. A class is considered a TinyType if
// * is a direct ancestor of a tech.anima.tinytypes.*TinyType, is not abstract
// * and provides a ctor matching super.
// *
// * @param candidate the class to be checked
// * @return true if the candidate is a TinyType, false otherwise.
// */
// public static boolean isTinyType(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: jersey/src/main/java/tech/anima/tinytypes/jersey/TinyTypesHeaderDelegateProvider.java
import javax.ws.rs.ext.Provider;
import tech.anima.tinytypes.meta.MetaTinyType;
import tech.anima.tinytypes.meta.MetaTinyTypes;
import org.glassfish.jersey.spi.HeaderDelegateProvider;
package tech.anima.tinytypes.jersey;
@Provider
public class TinyTypesHeaderDelegateProvider<T> implements HeaderDelegateProvider<T> {
private final Class<T> type;
private final MetaTinyType<T> meta;
public TinyTypesHeaderDelegateProvider(Class<T> concrete) {
this.type = concrete; | this.meta = MetaTinyTypes.metaFor(concrete); |
caligin/tinytypes | meta/src/test/java/tech/anima/tinytypes/meta/MetaTinyTypesTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
| import tech.anima.tinytypes.Samples;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.FromDataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith; | package tech.anima.tinytypes.meta;
@RunWith(Enclosed.class)
public class MetaTinyTypesTest {
@RunWith(Theories.class)
public static class IsTinyType {
@DataPoints("tts")
public static final Class<?>[] tinyTypesSamples = new Class<?>[]{ | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
// Path: meta/src/test/java/tech/anima/tinytypes/meta/MetaTinyTypesTest.java
import tech.anima.tinytypes.Samples;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.FromDataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
package tech.anima.tinytypes.meta;
@RunWith(Enclosed.class)
public class MetaTinyTypesTest {
@RunWith(Theories.class)
public static class IsTinyType {
@DataPoints("tts")
public static final Class<?>[] tinyTypesSamples = new Class<?>[]{ | Samples.Str.class, |
caligin/tinytypes | jersey/src/main/java/tech/anima/tinytypes/jersey/TinyTypesParamProvider.java | // Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyType.java
// public interface MetaTinyType<T> {
//
// /**
// * Checks whether this implementation can operate on the given TinyType
// * class type.
// *
// * @param candidate the TInyType type to check for compatibility
// * @return true if the candidate is supported, false otherwise
// */
// boolean isMetaOf(Class<?> candidate);
//
// /**
// * Returns a String representation of the value wrapped in the given
// * TinyType. The given TinyType must be compatible with this meta.
// *
// * @param value the TinyType to stringify
// * @return a String representation of the native value wrapped in the
// * TinyType
// */
// String stringify(T value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value. The given TinyType class type and the type of value must
// * both be compatible with this meta.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U newInstance(Class<U> type, Object value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value given in string form. The given TinyType class type must be
// * compatible with this meta, the given String value must be parseable as
// * the appropriate native type.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U fromString(Class<U> type, String value);
// }
//
// Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyTypes.java
// public abstract class MetaTinyTypes {
//
// public static final MetaTinyType[] metas = new MetaTinyType[]{
// new StringTinyTypes(),
// new BooleanTinyTypes(),
// new ByteTinyTypes(),
// new ShortTinyTypes(),
// new IntTinyTypes(),
// new LongTinyTypes()
// };
//
// /**
// * Provides a type-specific Meta class for the given TinyType.
// *
// * @param <T> the TinyType class type
// * @param candidate the TinyType class to obtain a Meta for
// * @return a Meta implementation suitable for the candidate
// * @throws IllegalArgumentException for null or a non-TinyType
// */
// public static <T> MetaTinyType<T> metaFor(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return meta;
// }
// }
// throw new IllegalArgumentException(String.format("not a tinytype: %s", candidate == null ? "null" : candidate.getCanonicalName()));
// }
//
// /**
// * Checks whether a class is a TinyType. A class is considered a TinyType if
// * is a direct ancestor of a tech.anima.tinytypes.*TinyType, is not abstract
// * and provides a ctor matching super.
// *
// * @param candidate the class to be checked
// * @return true if the candidate is a TinyType, false otherwise.
// */
// public static boolean isTinyType(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
import tech.anima.tinytypes.meta.MetaTinyType;
import tech.anima.tinytypes.meta.MetaTinyTypes; | package tech.anima.tinytypes.jersey;
@Provider
public class TinyTypesParamProvider implements ParamConverterProvider {
@Override
public <T> ParamConverter<T> getConverter(final Class<T> rawType, Type genericType, Annotation[] annotations) { | // Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyType.java
// public interface MetaTinyType<T> {
//
// /**
// * Checks whether this implementation can operate on the given TinyType
// * class type.
// *
// * @param candidate the TInyType type to check for compatibility
// * @return true if the candidate is supported, false otherwise
// */
// boolean isMetaOf(Class<?> candidate);
//
// /**
// * Returns a String representation of the value wrapped in the given
// * TinyType. The given TinyType must be compatible with this meta.
// *
// * @param value the TinyType to stringify
// * @return a String representation of the native value wrapped in the
// * TinyType
// */
// String stringify(T value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value. The given TinyType class type and the type of value must
// * both be compatible with this meta.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U newInstance(Class<U> type, Object value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value given in string form. The given TinyType class type must be
// * compatible with this meta, the given String value must be parseable as
// * the appropriate native type.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U fromString(Class<U> type, String value);
// }
//
// Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyTypes.java
// public abstract class MetaTinyTypes {
//
// public static final MetaTinyType[] metas = new MetaTinyType[]{
// new StringTinyTypes(),
// new BooleanTinyTypes(),
// new ByteTinyTypes(),
// new ShortTinyTypes(),
// new IntTinyTypes(),
// new LongTinyTypes()
// };
//
// /**
// * Provides a type-specific Meta class for the given TinyType.
// *
// * @param <T> the TinyType class type
// * @param candidate the TinyType class to obtain a Meta for
// * @return a Meta implementation suitable for the candidate
// * @throws IllegalArgumentException for null or a non-TinyType
// */
// public static <T> MetaTinyType<T> metaFor(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return meta;
// }
// }
// throw new IllegalArgumentException(String.format("not a tinytype: %s", candidate == null ? "null" : candidate.getCanonicalName()));
// }
//
// /**
// * Checks whether a class is a TinyType. A class is considered a TinyType if
// * is a direct ancestor of a tech.anima.tinytypes.*TinyType, is not abstract
// * and provides a ctor matching super.
// *
// * @param candidate the class to be checked
// * @return true if the candidate is a TinyType, false otherwise.
// */
// public static boolean isTinyType(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: jersey/src/main/java/tech/anima/tinytypes/jersey/TinyTypesParamProvider.java
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
import tech.anima.tinytypes.meta.MetaTinyType;
import tech.anima.tinytypes.meta.MetaTinyTypes;
package tech.anima.tinytypes.jersey;
@Provider
public class TinyTypesParamProvider implements ParamConverterProvider {
@Override
public <T> ParamConverter<T> getConverter(final Class<T> rawType, Type genericType, Annotation[] annotations) { | if (MetaTinyTypes.isTinyType(rawType)) { |
caligin/tinytypes | jersey/src/main/java/tech/anima/tinytypes/jersey/TinyTypesParamProvider.java | // Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyType.java
// public interface MetaTinyType<T> {
//
// /**
// * Checks whether this implementation can operate on the given TinyType
// * class type.
// *
// * @param candidate the TInyType type to check for compatibility
// * @return true if the candidate is supported, false otherwise
// */
// boolean isMetaOf(Class<?> candidate);
//
// /**
// * Returns a String representation of the value wrapped in the given
// * TinyType. The given TinyType must be compatible with this meta.
// *
// * @param value the TinyType to stringify
// * @return a String representation of the native value wrapped in the
// * TinyType
// */
// String stringify(T value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value. The given TinyType class type and the type of value must
// * both be compatible with this meta.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U newInstance(Class<U> type, Object value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value given in string form. The given TinyType class type must be
// * compatible with this meta, the given String value must be parseable as
// * the appropriate native type.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U fromString(Class<U> type, String value);
// }
//
// Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyTypes.java
// public abstract class MetaTinyTypes {
//
// public static final MetaTinyType[] metas = new MetaTinyType[]{
// new StringTinyTypes(),
// new BooleanTinyTypes(),
// new ByteTinyTypes(),
// new ShortTinyTypes(),
// new IntTinyTypes(),
// new LongTinyTypes()
// };
//
// /**
// * Provides a type-specific Meta class for the given TinyType.
// *
// * @param <T> the TinyType class type
// * @param candidate the TinyType class to obtain a Meta for
// * @return a Meta implementation suitable for the candidate
// * @throws IllegalArgumentException for null or a non-TinyType
// */
// public static <T> MetaTinyType<T> metaFor(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return meta;
// }
// }
// throw new IllegalArgumentException(String.format("not a tinytype: %s", candidate == null ? "null" : candidate.getCanonicalName()));
// }
//
// /**
// * Checks whether a class is a TinyType. A class is considered a TinyType if
// * is a direct ancestor of a tech.anima.tinytypes.*TinyType, is not abstract
// * and provides a ctor matching super.
// *
// * @param candidate the class to be checked
// * @return true if the candidate is a TinyType, false otherwise.
// */
// public static boolean isTinyType(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
import tech.anima.tinytypes.meta.MetaTinyType;
import tech.anima.tinytypes.meta.MetaTinyTypes; | package tech.anima.tinytypes.jersey;
@Provider
public class TinyTypesParamProvider implements ParamConverterProvider {
@Override
public <T> ParamConverter<T> getConverter(final Class<T> rawType, Type genericType, Annotation[] annotations) {
if (MetaTinyTypes.isTinyType(rawType)) {
return new TinyTypesParamConverter<>(rawType);
}
return null;
}
public static class TinyTypesParamConverter<T> implements ParamConverter<T> {
private final Class<T> type; | // Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyType.java
// public interface MetaTinyType<T> {
//
// /**
// * Checks whether this implementation can operate on the given TinyType
// * class type.
// *
// * @param candidate the TInyType type to check for compatibility
// * @return true if the candidate is supported, false otherwise
// */
// boolean isMetaOf(Class<?> candidate);
//
// /**
// * Returns a String representation of the value wrapped in the given
// * TinyType. The given TinyType must be compatible with this meta.
// *
// * @param value the TinyType to stringify
// * @return a String representation of the native value wrapped in the
// * TinyType
// */
// String stringify(T value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value. The given TinyType class type and the type of value must
// * both be compatible with this meta.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U newInstance(Class<U> type, Object value);
//
// /**
// * Creates a new instance of the given TinyType class type, wrapping the
// * given value given in string form. The given TinyType class type must be
// * compatible with this meta, the given String value must be parseable as
// * the appropriate native type.
// *
// * @param <U> the TinyType class type to construct
// * @param type the TinyType class type to construct
// * @param value the native value to wrap
// * @return a new instance of U wrapping the given value
// */
// <U extends T> U fromString(Class<U> type, String value);
// }
//
// Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyTypes.java
// public abstract class MetaTinyTypes {
//
// public static final MetaTinyType[] metas = new MetaTinyType[]{
// new StringTinyTypes(),
// new BooleanTinyTypes(),
// new ByteTinyTypes(),
// new ShortTinyTypes(),
// new IntTinyTypes(),
// new LongTinyTypes()
// };
//
// /**
// * Provides a type-specific Meta class for the given TinyType.
// *
// * @param <T> the TinyType class type
// * @param candidate the TinyType class to obtain a Meta for
// * @return a Meta implementation suitable for the candidate
// * @throws IllegalArgumentException for null or a non-TinyType
// */
// public static <T> MetaTinyType<T> metaFor(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return meta;
// }
// }
// throw new IllegalArgumentException(String.format("not a tinytype: %s", candidate == null ? "null" : candidate.getCanonicalName()));
// }
//
// /**
// * Checks whether a class is a TinyType. A class is considered a TinyType if
// * is a direct ancestor of a tech.anima.tinytypes.*TinyType, is not abstract
// * and provides a ctor matching super.
// *
// * @param candidate the class to be checked
// * @return true if the candidate is a TinyType, false otherwise.
// */
// public static boolean isTinyType(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: jersey/src/main/java/tech/anima/tinytypes/jersey/TinyTypesParamProvider.java
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
import tech.anima.tinytypes.meta.MetaTinyType;
import tech.anima.tinytypes.meta.MetaTinyTypes;
package tech.anima.tinytypes.jersey;
@Provider
public class TinyTypesParamProvider implements ParamConverterProvider {
@Override
public <T> ParamConverter<T> getConverter(final Class<T> rawType, Type genericType, Annotation[] annotations) {
if (MetaTinyTypes.isTinyType(rawType)) {
return new TinyTypesParamConverter<>(rawType);
}
return null;
}
public static class TinyTypesParamConverter<T> implements ParamConverter<T> {
private final Class<T> type; | private final MetaTinyType<T> meta; |
caligin/tinytypes | meta/src/test/java/tech/anima/tinytypes/meta/ByteTinyTypesTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
| import tech.anima.tinytypes.Samples;
import org.junit.Test;
import org.junit.Assert;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith; | package tech.anima.tinytypes.meta;
@RunWith(Enclosed.class)
public class ByteTinyTypesTest {
public static class IsMetaOf {
@Test
public void yieldsTrueWhenCandidateSuperclassIsByteTT() { | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
// Path: meta/src/test/java/tech/anima/tinytypes/meta/ByteTinyTypesTest.java
import tech.anima.tinytypes.Samples;
import org.junit.Test;
import org.junit.Assert;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
package tech.anima.tinytypes.meta;
@RunWith(Enclosed.class)
public class ByteTinyTypesTest {
public static class IsMetaOf {
@Test
public void yieldsTrueWhenCandidateSuperclassIsByteTT() { | final boolean got = new ByteTinyTypes().isMetaOf(Samples.Byte.class); |
caligin/tinytypes | meta/src/test/java/tech/anima/tinytypes/meta/LongTinyTypesTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
| import tech.anima.tinytypes.Samples;
import org.junit.Test;
import org.junit.Assert;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith; | package tech.anima.tinytypes.meta;
@RunWith(Enclosed.class)
public class LongTinyTypesTest {
public static class IsMetaOf {
@Test
public void yieldsTrueWhenCandidateSuperclassIsLongTT() { | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
// Path: meta/src/test/java/tech/anima/tinytypes/meta/LongTinyTypesTest.java
import tech.anima.tinytypes.Samples;
import org.junit.Test;
import org.junit.Assert;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
package tech.anima.tinytypes.meta;
@RunWith(Enclosed.class)
public class LongTinyTypesTest {
public static class IsMetaOf {
@Test
public void yieldsTrueWhenCandidateSuperclassIsLongTT() { | final boolean got = new LongTinyTypes().isMetaOf(Samples.Long.class); |
caligin/tinytypes | jersey/src/test/java/tech/anima/tinytypes/jersey/TinyTypesParamProviderTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
| import javax.ws.rs.ext.ParamConverter;
import tech.anima.tinytypes.Samples;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith; | package tech.anima.tinytypes.jersey;
@RunWith(Enclosed.class)
public class TinyTypesParamProviderTest {
@RunWith(Theories.class)
public static class GetConverter {
@Test
public void yieldsNullWhenTypeIsNotATinyType() {
final Class<?> type = null;
final ParamConverter<?> got = new TinyTypesParamProvider().getConverter(type, null, null);
Assert.assertNull(got);
}
@DataPoints
public static final Class<?>[] tinyTypesSamples = new Class<?>[]{ | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
// Path: jersey/src/test/java/tech/anima/tinytypes/jersey/TinyTypesParamProviderTest.java
import javax.ws.rs.ext.ParamConverter;
import tech.anima.tinytypes.Samples;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
package tech.anima.tinytypes.jersey;
@RunWith(Enclosed.class)
public class TinyTypesParamProviderTest {
@RunWith(Theories.class)
public static class GetConverter {
@Test
public void yieldsNullWhenTypeIsNotATinyType() {
final Class<?> type = null;
final ParamConverter<?> got = new TinyTypesParamProvider().getConverter(type, null, null);
Assert.assertNull(got);
}
@DataPoints
public static final Class<?>[] tinyTypesSamples = new Class<?>[]{ | Samples.Str.class, |
caligin/tinytypes | jackson/src/test/java/tech/anima/tinytypes/jackson/TinyTypesSerializersTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
| import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import java.io.IOException;
import tech.anima.tinytypes.Samples;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith; | package tech.anima.tinytypes.jackson;
@RunWith(Enclosed.class)
public class TinyTypesSerializersTest {
@RunWith(Theories.class)
public static class FindSerializer {
@Test
public void delegatesToOtherWhenTypeIsNotATinyType() throws JsonMappingException {
final JavaType typeForObject = TypeFactory.defaultInstance().uncheckedSimpleType(Object.class);
final JsonSerializer<?> got = new TinyTypesSerializers().findSerializer(null, typeForObject, null);
Assert.assertFalse(got instanceof TinyTypesSerializers.TinyTypesSerializer);
}
@DataPoints
public static final Class<?>[] tinyTypesSamples = new Class<?>[]{ | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
// Path: jackson/src/test/java/tech/anima/tinytypes/jackson/TinyTypesSerializersTest.java
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import java.io.IOException;
import tech.anima.tinytypes.Samples;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
package tech.anima.tinytypes.jackson;
@RunWith(Enclosed.class)
public class TinyTypesSerializersTest {
@RunWith(Theories.class)
public static class FindSerializer {
@Test
public void delegatesToOtherWhenTypeIsNotATinyType() throws JsonMappingException {
final JavaType typeForObject = TypeFactory.defaultInstance().uncheckedSimpleType(Object.class);
final JsonSerializer<?> got = new TinyTypesSerializers().findSerializer(null, typeForObject, null);
Assert.assertFalse(got instanceof TinyTypesSerializers.TinyTypesSerializer);
}
@DataPoints
public static final Class<?>[] tinyTypesSamples = new Class<?>[]{ | Samples.Str.class, |
caligin/tinytypes | jackson/src/test/java/tech/anima/tinytypes/jackson/TinyTypesKeyDeserializersTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
| import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.KeyDeserializer;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import tech.anima.tinytypes.Samples;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith; | package tech.anima.tinytypes.jackson;
@RunWith(Enclosed.class)
public class TinyTypesKeyDeserializersTest {
@RunWith(Theories.class)
public static class FindKeyDeserializer {
@Test
public void yieldsNullWhenTypeIsNotATinyType() throws JsonMappingException {
final JavaType typeForObject = TypeFactory.defaultInstance().uncheckedSimpleType(Object.class);
final KeyDeserializer got = new TinyTypesKeyDeserializers().findKeyDeserializer(typeForObject, null, null);
Assert.assertNull(got);
}
@DataPoints
public static final Class<?>[] tinyTypesSamples = new Class<?>[]{ | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
// Path: jackson/src/test/java/tech/anima/tinytypes/jackson/TinyTypesKeyDeserializersTest.java
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.KeyDeserializer;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import tech.anima.tinytypes.Samples;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
package tech.anima.tinytypes.jackson;
@RunWith(Enclosed.class)
public class TinyTypesKeyDeserializersTest {
@RunWith(Theories.class)
public static class FindKeyDeserializer {
@Test
public void yieldsNullWhenTypeIsNotATinyType() throws JsonMappingException {
final JavaType typeForObject = TypeFactory.defaultInstance().uncheckedSimpleType(Object.class);
final KeyDeserializer got = new TinyTypesKeyDeserializers().findKeyDeserializer(typeForObject, null, null);
Assert.assertNull(got);
}
@DataPoints
public static final Class<?>[] tinyTypesSamples = new Class<?>[]{ | Samples.Str.class, |
caligin/tinytypes | jackson/src/main/java/tech/anima/tinytypes/jackson/TinyTypesKeyDeserializers.java | // Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyTypes.java
// public abstract class MetaTinyTypes {
//
// public static final MetaTinyType[] metas = new MetaTinyType[]{
// new StringTinyTypes(),
// new BooleanTinyTypes(),
// new ByteTinyTypes(),
// new ShortTinyTypes(),
// new IntTinyTypes(),
// new LongTinyTypes()
// };
//
// /**
// * Provides a type-specific Meta class for the given TinyType.
// *
// * @param <T> the TinyType class type
// * @param candidate the TinyType class to obtain a Meta for
// * @return a Meta implementation suitable for the candidate
// * @throws IllegalArgumentException for null or a non-TinyType
// */
// public static <T> MetaTinyType<T> metaFor(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return meta;
// }
// }
// throw new IllegalArgumentException(String.format("not a tinytype: %s", candidate == null ? "null" : candidate.getCanonicalName()));
// }
//
// /**
// * Checks whether a class is a TinyType. A class is considered a TinyType if
// * is a direct ancestor of a tech.anima.tinytypes.*TinyType, is not abstract
// * and provides a ctor matching super.
// *
// * @param candidate the class to be checked
// * @return true if the candidate is a TinyType, false otherwise.
// */
// public static boolean isTinyType(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return true;
// }
// }
// return false;
// }
//
// }
| import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.KeyDeserializer;
import com.fasterxml.jackson.databind.deser.KeyDeserializers;
import java.io.IOException;
import tech.anima.tinytypes.meta.MetaTinyTypes; | package tech.anima.tinytypes.jackson;
public class TinyTypesKeyDeserializers implements KeyDeserializers {
@Override
public KeyDeserializer findKeyDeserializer(JavaType type, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException {
final Class<?> candidateTT = type.getRawClass(); | // Path: meta/src/main/java/tech/anima/tinytypes/meta/MetaTinyTypes.java
// public abstract class MetaTinyTypes {
//
// public static final MetaTinyType[] metas = new MetaTinyType[]{
// new StringTinyTypes(),
// new BooleanTinyTypes(),
// new ByteTinyTypes(),
// new ShortTinyTypes(),
// new IntTinyTypes(),
// new LongTinyTypes()
// };
//
// /**
// * Provides a type-specific Meta class for the given TinyType.
// *
// * @param <T> the TinyType class type
// * @param candidate the TinyType class to obtain a Meta for
// * @return a Meta implementation suitable for the candidate
// * @throws IllegalArgumentException for null or a non-TinyType
// */
// public static <T> MetaTinyType<T> metaFor(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return meta;
// }
// }
// throw new IllegalArgumentException(String.format("not a tinytype: %s", candidate == null ? "null" : candidate.getCanonicalName()));
// }
//
// /**
// * Checks whether a class is a TinyType. A class is considered a TinyType if
// * is a direct ancestor of a tech.anima.tinytypes.*TinyType, is not abstract
// * and provides a ctor matching super.
// *
// * @param candidate the class to be checked
// * @return true if the candidate is a TinyType, false otherwise.
// */
// public static boolean isTinyType(Class<?> candidate) {
// for (MetaTinyType meta : metas) {
// if (meta.isMetaOf(candidate)) {
// return true;
// }
// }
// return false;
// }
//
// }
// Path: jackson/src/main/java/tech/anima/tinytypes/jackson/TinyTypesKeyDeserializers.java
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.KeyDeserializer;
import com.fasterxml.jackson.databind.deser.KeyDeserializers;
import java.io.IOException;
import tech.anima.tinytypes.meta.MetaTinyTypes;
package tech.anima.tinytypes.jackson;
public class TinyTypesKeyDeserializers implements KeyDeserializers {
@Override
public KeyDeserializer findKeyDeserializer(JavaType type, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException {
final Class<?> candidateTT = type.getRawClass(); | if (MetaTinyTypes.isTinyType(candidateTT)) { |
caligin/tinytypes | meta/src/test/java/tech/anima/tinytypes/meta/BooleanTinyTypesTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: testing/src/main/java/tech/anima/tinytypes/Samples.java
// public static class BooleanIndirectAncestor extends Samples.Boolean {
//
// public BooleanIndirectAncestor(boolean value) {
// super(value);
// }
// }
| import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.Samples.BooleanIndirectAncestor;
import org.junit.Test;
import org.junit.Assert;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith; | package tech.anima.tinytypes.meta;
@RunWith(Enclosed.class)
public class BooleanTinyTypesTest {
public static class IsMetaOf {
@Test
public void yieldsTrueWhenCandidateSuperclassIsBooleanTT() { | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: testing/src/main/java/tech/anima/tinytypes/Samples.java
// public static class BooleanIndirectAncestor extends Samples.Boolean {
//
// public BooleanIndirectAncestor(boolean value) {
// super(value);
// }
// }
// Path: meta/src/test/java/tech/anima/tinytypes/meta/BooleanTinyTypesTest.java
import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.Samples.BooleanIndirectAncestor;
import org.junit.Test;
import org.junit.Assert;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
package tech.anima.tinytypes.meta;
@RunWith(Enclosed.class)
public class BooleanTinyTypesTest {
public static class IsMetaOf {
@Test
public void yieldsTrueWhenCandidateSuperclassIsBooleanTT() { | final boolean got = new BooleanTinyTypes().isMetaOf(Samples.Boolean.class); |
caligin/tinytypes | meta/src/test/java/tech/anima/tinytypes/meta/BooleanTinyTypesTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: testing/src/main/java/tech/anima/tinytypes/Samples.java
// public static class BooleanIndirectAncestor extends Samples.Boolean {
//
// public BooleanIndirectAncestor(boolean value) {
// super(value);
// }
// }
| import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.Samples.BooleanIndirectAncestor;
import org.junit.Test;
import org.junit.Assert;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith; | package tech.anima.tinytypes.meta;
@RunWith(Enclosed.class)
public class BooleanTinyTypesTest {
public static class IsMetaOf {
@Test
public void yieldsTrueWhenCandidateSuperclassIsBooleanTT() {
final boolean got = new BooleanTinyTypes().isMetaOf(Samples.Boolean.class);
Assert.assertTrue(got);
}
@Test
public void yieldsFalseWhenCandidateSuperclassIsNotBooleanTT() {
final boolean got = new BooleanTinyTypes().isMetaOf(Samples.class);
Assert.assertFalse(got);
}
@Test
public void yieldsFalseWhenAncestorOfCandidateIsBooleanTTButNotDirectSuperclass() { | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: testing/src/main/java/tech/anima/tinytypes/Samples.java
// public static class BooleanIndirectAncestor extends Samples.Boolean {
//
// public BooleanIndirectAncestor(boolean value) {
// super(value);
// }
// }
// Path: meta/src/test/java/tech/anima/tinytypes/meta/BooleanTinyTypesTest.java
import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.Samples.BooleanIndirectAncestor;
import org.junit.Test;
import org.junit.Assert;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
package tech.anima.tinytypes.meta;
@RunWith(Enclosed.class)
public class BooleanTinyTypesTest {
public static class IsMetaOf {
@Test
public void yieldsTrueWhenCandidateSuperclassIsBooleanTT() {
final boolean got = new BooleanTinyTypes().isMetaOf(Samples.Boolean.class);
Assert.assertTrue(got);
}
@Test
public void yieldsFalseWhenCandidateSuperclassIsNotBooleanTT() {
final boolean got = new BooleanTinyTypes().isMetaOf(Samples.class);
Assert.assertFalse(got);
}
@Test
public void yieldsFalseWhenAncestorOfCandidateIsBooleanTTButNotDirectSuperclass() { | final boolean got = new BooleanTinyTypes().isMetaOf(BooleanIndirectAncestor.class); |
caligin/tinytypes | examples/src/test/java/tech/anima/tinytypes/examples/DropwizardBootstrapTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: jackson/src/main/java/tech/anima/tinytypes/jackson/TinyTypesModule.java
// public final class TinyTypesModule extends Module {
//
// @Override
// public String getModuleName() {
// return "TinyTypes";
// }
//
// @Override
// public Version version() {
// return new Version(1, 1, 0, "SNAPSHOT", "tech.anima", "jackson-datatype-tinytypes");
// }
//
// @Override
// public void setupModule(SetupContext context) {
// context.addKeySerializers(new TinyTypesKeySerializers());
// context.addSerializers(new TinyTypesSerializers());
// context.addDeserializers(new TinyTypesDeserializers());
// context.addKeyDeserializers(new TinyTypesKeyDeserializers());
// }
//
// }
| import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.junit.Assert;
import org.junit.Test;
import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.jackson.TinyTypesModule; | package tech.anima.tinytypes.examples;
public class DropwizardBootstrapTest {
@Test
public void canLoadYamlDWConfigFileWithTinyTypes() throws Exception {
new TestApplication().run(new String[]{"server", ClassLoader.getSystemClassLoader().getResource("tts.yml").getPath().toString()});
}
public static class TestApplication extends Application<ConfigurationWithTinyTypes> {
@Override
public void initialize(Bootstrap<ConfigurationWithTinyTypes> bootstrap) { | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: jackson/src/main/java/tech/anima/tinytypes/jackson/TinyTypesModule.java
// public final class TinyTypesModule extends Module {
//
// @Override
// public String getModuleName() {
// return "TinyTypes";
// }
//
// @Override
// public Version version() {
// return new Version(1, 1, 0, "SNAPSHOT", "tech.anima", "jackson-datatype-tinytypes");
// }
//
// @Override
// public void setupModule(SetupContext context) {
// context.addKeySerializers(new TinyTypesKeySerializers());
// context.addSerializers(new TinyTypesSerializers());
// context.addDeserializers(new TinyTypesDeserializers());
// context.addKeyDeserializers(new TinyTypesKeyDeserializers());
// }
//
// }
// Path: examples/src/test/java/tech/anima/tinytypes/examples/DropwizardBootstrapTest.java
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.junit.Assert;
import org.junit.Test;
import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.jackson.TinyTypesModule;
package tech.anima.tinytypes.examples;
public class DropwizardBootstrapTest {
@Test
public void canLoadYamlDWConfigFileWithTinyTypes() throws Exception {
new TestApplication().run(new String[]{"server", ClassLoader.getSystemClassLoader().getResource("tts.yml").getPath().toString()});
}
public static class TestApplication extends Application<ConfigurationWithTinyTypes> {
@Override
public void initialize(Bootstrap<ConfigurationWithTinyTypes> bootstrap) { | bootstrap.getObjectMapper().registerModule(new TinyTypesModule()); |
caligin/tinytypes | examples/src/test/java/tech/anima/tinytypes/examples/DropwizardBootstrapTest.java | // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: jackson/src/main/java/tech/anima/tinytypes/jackson/TinyTypesModule.java
// public final class TinyTypesModule extends Module {
//
// @Override
// public String getModuleName() {
// return "TinyTypes";
// }
//
// @Override
// public Version version() {
// return new Version(1, 1, 0, "SNAPSHOT", "tech.anima", "jackson-datatype-tinytypes");
// }
//
// @Override
// public void setupModule(SetupContext context) {
// context.addKeySerializers(new TinyTypesKeySerializers());
// context.addSerializers(new TinyTypesSerializers());
// context.addDeserializers(new TinyTypesDeserializers());
// context.addKeyDeserializers(new TinyTypesKeyDeserializers());
// }
//
// }
| import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.junit.Assert;
import org.junit.Test;
import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.jackson.TinyTypesModule; | package tech.anima.tinytypes.examples;
public class DropwizardBootstrapTest {
@Test
public void canLoadYamlDWConfigFileWithTinyTypes() throws Exception {
new TestApplication().run(new String[]{"server", ClassLoader.getSystemClassLoader().getResource("tts.yml").getPath().toString()});
}
public static class TestApplication extends Application<ConfigurationWithTinyTypes> {
@Override
public void initialize(Bootstrap<ConfigurationWithTinyTypes> bootstrap) {
bootstrap.getObjectMapper().registerModule(new TinyTypesModule());
}
@Override
public void run(ConfigurationWithTinyTypes configuration, Environment environment) throws Exception {
Assert.assertEquals("1", configuration.stringValue.value);
Assert.assertEquals(true, configuration.booleanValue.value);
Assert.assertEquals(1, configuration.byteValue.value);
Assert.assertEquals(1, configuration.shortValue.value);
Assert.assertEquals(1, configuration.integerValue.value);
Assert.assertEquals(1, configuration.longValue.value);
}
}
public static class ConfigurationWithTinyTypes extends Configuration {
| // Path: tinytypes/src/test/java/tech/anima/tinytypes/Samples.java
// public class Samples {
//
// public static class Integer extends IntTinyType {
//
// public Integer(int value) {
// super(value);
// }
//
// public static Integer of(int value) {
// return new Integer(value);
// }
//
// }
//
// public static class OtherInteger extends IntTinyType {
//
// public OtherInteger(int value) {
// super(value);
// }
//
// public static OtherInteger of(int value) {
// return new OtherInteger(value);
// }
//
// }
//
// public static class Byte extends ByteTinyType {
//
// public Byte(byte value) {
// super(value);
// }
//
// public static Byte of(byte value) {
// return new Byte(value);
// }
//
// }
//
// public static class OtherByte extends ByteTinyType {
//
// public OtherByte(byte value) {
// super(value);
// }
//
// public static OtherByte of(byte value) {
// return new OtherByte(value);
// }
//
// }
//
// public static class Str extends StringTinyType {
//
// public Str(String value) {
// super(value);
// }
//
// public static Str of(String value) {
// return new Str(value);
// }
//
// }
//
// public static class OtherStr extends StringTinyType {
//
// public OtherStr(String value) {
// super(value);
// }
//
// public static OtherStr of(String value) {
// return new OtherStr(value);
// }
//
// }
//
// public static class Boolean extends BooleanTinyType {
//
// public Boolean(boolean value) {
// super(value);
// }
//
// public static Boolean of(boolean value) {
// return new Boolean(value);
// }
//
// }
//
// public static class OtherBoolean extends BooleanTinyType {
//
// public OtherBoolean(boolean value) {
// super(value);
// }
//
// public static OtherBoolean of(boolean value) {
// return new OtherBoolean(value);
// }
//
// }
//
// public static class Long extends LongTinyType {
//
// public Long(long value) {
// super(value);
// }
//
// public static Long of(long value) {
// return new Long(value);
// }
//
// }
//
// public static class OtherLong extends LongTinyType {
//
// public OtherLong(long value) {
// super(value);
// }
//
// public static OtherLong of(long value) {
// return new OtherLong(value);
// }
//
// }
//
// public static class Short extends ShortTinyType {
//
// public Short(short value) {
// super(value);
// }
//
// public static Short of(short value) {
// return new Short(value);
// }
//
// }
//
// public static class OtherShort extends ShortTinyType {
//
// public OtherShort(short value) {
// super(value);
// }
//
// public static OtherShort of(short value) {
// return new OtherShort(value);
// }
//
// }
//
// }
//
// Path: jackson/src/main/java/tech/anima/tinytypes/jackson/TinyTypesModule.java
// public final class TinyTypesModule extends Module {
//
// @Override
// public String getModuleName() {
// return "TinyTypes";
// }
//
// @Override
// public Version version() {
// return new Version(1, 1, 0, "SNAPSHOT", "tech.anima", "jackson-datatype-tinytypes");
// }
//
// @Override
// public void setupModule(SetupContext context) {
// context.addKeySerializers(new TinyTypesKeySerializers());
// context.addSerializers(new TinyTypesSerializers());
// context.addDeserializers(new TinyTypesDeserializers());
// context.addKeyDeserializers(new TinyTypesKeyDeserializers());
// }
//
// }
// Path: examples/src/test/java/tech/anima/tinytypes/examples/DropwizardBootstrapTest.java
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
import org.junit.Assert;
import org.junit.Test;
import tech.anima.tinytypes.Samples;
import tech.anima.tinytypes.jackson.TinyTypesModule;
package tech.anima.tinytypes.examples;
public class DropwizardBootstrapTest {
@Test
public void canLoadYamlDWConfigFileWithTinyTypes() throws Exception {
new TestApplication().run(new String[]{"server", ClassLoader.getSystemClassLoader().getResource("tts.yml").getPath().toString()});
}
public static class TestApplication extends Application<ConfigurationWithTinyTypes> {
@Override
public void initialize(Bootstrap<ConfigurationWithTinyTypes> bootstrap) {
bootstrap.getObjectMapper().registerModule(new TinyTypesModule());
}
@Override
public void run(ConfigurationWithTinyTypes configuration, Environment environment) throws Exception {
Assert.assertEquals("1", configuration.stringValue.value);
Assert.assertEquals(true, configuration.booleanValue.value);
Assert.assertEquals(1, configuration.byteValue.value);
Assert.assertEquals(1, configuration.shortValue.value);
Assert.assertEquals(1, configuration.integerValue.value);
Assert.assertEquals(1, configuration.longValue.value);
}
}
public static class ConfigurationWithTinyTypes extends Configuration {
| private final Samples.Str stringValue; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.