Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* This file is part of the "LARUS Integration Framework for Neo4j".
*
* The "LARUS Integration Framework for Neo4j" is 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.
*
* Created on 03/02/16
*/
package org.neo4j.jdbc;
import org.neo4j.jdbc.impl.ListNeo4jResultSet;
import org.neo4j.jdbc.metadata.Column;
import org.neo4j.jdbc.metadata.Table;
import org.neo4j.jdbc.utils.Neo4jJdbcRuntimeException;
import java.io.InputStream;
import java.sql.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author AgileLARUS
* @since 3.0.0
*/
public abstract class Neo4jDatabaseMetaData implements java.sql.DatabaseMetaData {
public static final Logger LOGGER = Logger.getLogger(Neo4jDatabaseMetaData.class.getName());
public static final String GET_DBMS_FUNCTIONS = "CALL dbms.functions() YIELD name RETURN name ORDER BY name ASC";
/**
* The regex to parse the version driver.
* NUMBER + . + NUMBER + .|- + STRING
*/
private static final Pattern VERSION_REGEX = Pattern.compile("^(\\d+)\\.(\\d+)(\\.|-)?(.*)?$");
protected static final int PROPERTY_SAMPLE_SIZE = 1000;
/**
* Name of the driver.
*/
private String driverName;
/**
* Version of the driver.
*/
private String driverVersion;
/**
* Database version.
*/
protected String databaseVersion = "Unknown";
/**
* Database labels.
*/
protected List
databaseLabels;
/**
* Database keys.
*/
protected List databaseProperties;
/**
* The JDBC connection.
*/
private Neo4jConnection connection;
/**
* Default constructor.
* Permit to load version and driver name from a property file.
* @param connection the connection
*
*
*/
public Neo4jDatabaseMetaData(Neo4jConnection connection) {
this.connection = connection;
// Compute driver version, name, ...
try (InputStream stream = Neo4jDatabaseMetaData.class.getResourceAsStream("/neo4j-jdbc-driver.properties")) {
Properties properties = new Properties();
properties.load(stream);
this.driverName = properties.getProperty("driver.name");
this.driverVersion = properties.getProperty("driver.version");
} catch (Exception e) {
this.driverName = "Neo4j JDBC Driver";
this.driverVersion = "Unknown";
throw new Neo4jJdbcRuntimeException(e);
}
this.databaseLabels = new ArrayList<>();
this.databaseProperties = new ArrayList<>();
}
/**
* Extract a part of a Version
*
* @param position 1 for the major, 2 for minor and 3 for revision
* @return The corresponding driver version part if it's possible, otherwise -1
*/
private int extractVersionPart(int position) {
int result = -1;
try {
Matcher matcher = VERSION_REGEX.matcher(this.getDriverVersion());
if (matcher.find()) {
result = Integer.valueOf(matcher.group(position));
}
} catch (SQLException e) {
LOGGER.log(Level.FINEST, "Silent exception", e);
}
return result;
}
@Override
public T unwrap(Class iface) throws SQLException {
return Wrapper.unwrap(iface, this);
}
@Override
public boolean isWrapperFor(Class> iface) throws SQLException {
return Wrapper.isWrapperFor(iface, this.getClass());
}
/*------------------------------------*/
/* Default implementation */
/*------------------------------------*/
@Override public java.sql.Connection getConnection() throws SQLException {
return this.connection;
}
@Override public String getDriverName() throws SQLException {
return this.driverName;
}
@Override public String getDriverVersion() throws SQLException {
return this.driverVersion;
}
@Override public int getDriverMajorVersion() {
return this.extractVersionPart(1);
}
@Override public int getDriverMinorVersion() {
return this.extractVersionPart(2);
}
@Override public String getDatabaseProductName() throws SQLException {
return "Neo4j";
}
@Override public String getDatabaseProductVersion() throws SQLException {
return this.databaseVersion;
}
@Override public int getDatabaseMajorVersion() throws SQLException {
return this.extractVersionPart(1);
}
@Override public int getDatabaseMinorVersion() throws SQLException {
return this.extractVersionPart(2);
}
@Override public int getJDBCMajorVersion() throws SQLException {
return 4;
}
@Override public int getJDBCMinorVersion() throws SQLException {
return 0;
}
@Override public String getIdentifierQuoteString() throws SQLException {
return "\"";
}
@Override public String getSQLKeywords() throws SQLException {
return "UNION,ALL,OPTIONAL,MATCH,UNWIND,MERGE,ON,CREATE,SET,DELETE,DETACH,REMOVE,WITH,DISTINCT,RETURN,ORDER,BY,SKIP,LIMIT,"
+ "ASCENDING,ASC,DESCENDING,DESC,WHERE,AND,OR,XOR,NOT,FOREACH,CALL,USING,INDEX,DROP,CONSTRAINT,ASSERT,UNIQUE,LOAD,CSV,"
+ "FROM,HEADERS,AS,START,CASE,WHEN,THEN,ELSE,END,STARTS,ENDS,CONTAINS";
}
@Override public String getNumericFunctions() throws SQLException {
return "abs,rand,round,ceil,floor,sqrt,sign,sin,cos,tan,cot,asin,acos,atan,atan2,havesin,degrees,radians,pi,log10,log,exp,e";
}
@Override public String getStringFunctions() throws SQLException {
return "toString,replace,substring,left,right,trim,ltrim,rtrim,upper,lower,split,reverse,length";
}
@Override public String getTimeDateFunctions() throws SQLException {
return "timestamp";
}
@Override public String getExtraNameCharacters() throws SQLException {
return "";
}
@Override public boolean supportsMultipleResultSets() throws SQLException {
return true;
}
@Override public String getCatalogTerm() throws SQLException {
return null;
}
@Override public String getCatalogSeparator() throws SQLException {
return null;
}
@Override public boolean supportsSchemasInDataManipulation() throws SQLException {
return false;
}
@Override public boolean supportsSchemasInTableDefinitions() throws SQLException {
return false;
}
@Override public boolean supportsCatalogsInDataManipulation() throws SQLException {
return false;
}
@Override public boolean supportsCatalogsInProcedureCalls() throws SQLException {
return false;
}
@Override public boolean supportsCatalogsInTableDefinitions() throws SQLException {
return false;
}
@Override public int getDefaultTransactionIsolation() throws SQLException {
return Neo4jConnection.TRANSACTION_READ_COMMITTED;
}
@Override public boolean supportsTransactions() throws SQLException {
return true;
}
@Override public ResultSet getSchemas() throws SQLException {
return ListNeo4jResultSet.newInstance(false, Collections.>emptyList(), Arrays.asList("TABLE_SCHEM","TABLE_CATALOG"));
}
@Override public ResultSet getCatalogs() throws SQLException {
return ListNeo4jResultSet.newInstance(false, Collections.>emptyList(), Arrays.asList("TABLE_CAT"));
}
@Override public ResultSet getTableTypes() throws SQLException {
List