use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class OCommandExecutorSQLInsert method parse.
@SuppressWarnings("unchecked")
public OCommandExecutorSQLInsert parse(final OCommandRequest iRequest) {
final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
String queryText = textRequest.getText();
String originalQuery = queryText;
try {
// System.out.println("NEW PARSER FROM: " + queryText);
queryText = preParse(queryText, iRequest);
// System.out.println("NEW PARSER TO: " + queryText);
textRequest.setText(queryText);
final ODatabaseDocument database = getDatabase();
init((OCommandRequestText) iRequest);
className = null;
newRecords = null;
content = null;
if (parserTextUpperCase.endsWith(KEYWORD_UNSAFE)) {
unsafe = true;
parserText = parserText.substring(0, parserText.length() - KEYWORD_UNSAFE.length() - 1);
parserTextUpperCase = parserTextUpperCase.substring(0, parserTextUpperCase.length() - KEYWORD_UNSAFE.length() - 1);
}
parserRequiredKeyword("INSERT");
parserRequiredKeyword("INTO");
String subjectName = parserRequiredWord(true, "Invalid subject name. Expected cluster, class or index");
if (subjectName.startsWith(OCommandExecutorSQLAbstract.CLUSTER_PREFIX)) {
// CLUSTER
clusterName = subjectName.substring(OCommandExecutorSQLAbstract.CLUSTER_PREFIX.length());
try {
int clusterId = Integer.parseInt(clusterName);
clusterName = database.getClusterNameById(clusterId);
} catch (Exception e) {
//not an integer
}
} else if (subjectName.startsWith(OCommandExecutorSQLAbstract.INDEX_PREFIX))
// INDEX
indexName = subjectName.substring(OCommandExecutorSQLAbstract.INDEX_PREFIX.length());
else {
// CLASS
if (subjectName.startsWith(OCommandExecutorSQLAbstract.CLASS_PREFIX))
subjectName = subjectName.substring(OCommandExecutorSQLAbstract.CLASS_PREFIX.length());
final OClass cls = ((OMetadataInternal) database.getMetadata()).getImmutableSchemaSnapshot().getClass(subjectName);
if (cls == null)
throwParsingException("Class " + subjectName + " not found in database");
if (!unsafe && cls.isSubClassOf("E"))
// FOUND EDGE
throw new OCommandExecutionException("'INSERT' command cannot create Edges. Use 'CREATE EDGE' command instead, or apply the 'UNSAFE' keyword to force it");
className = cls.getName();
clazz = database.getMetadata().getSchema().getClass(className);
if (clazz == null)
throw new OQueryParsingException("Class '" + className + "' was not found");
}
if (clusterName != null && className == null) {
ODatabaseDocumentInternal db = getDatabase();
OCluster cluster = db.getStorage().getClusterByName(clusterName);
if (cluster != null) {
clazz = db.getMetadata().getSchema().getClassByClusterId(cluster.getId());
if (clazz != null) {
className = clazz.getName();
}
}
}
parserSkipWhiteSpaces();
if (parserIsEnded())
throwSyntaxErrorException("Set of fields is missed. Example: (name, surname) or SET name = 'Bill'");
final String temp = parseOptionalWord(true);
if (parserGetLastWord().equalsIgnoreCase("cluster")) {
clusterName = parserRequiredWord(false);
parserSkipWhiteSpaces();
if (parserIsEnded())
throwSyntaxErrorException("Set of fields is missed. Example: (name, surname) or SET name = 'Bill'");
} else
parserGoBack();
newRecords = new ArrayList<Map<String, Object>>();
Boolean sourceClauseProcessed = false;
if (parserGetCurrentChar() == '(') {
parseValues();
parserNextWord(true, " \r\n");
sourceClauseProcessed = true;
} else {
parserNextWord(true, " ,\r\n");
if (parserGetLastWord().equals(KEYWORD_CONTENT)) {
newRecords = null;
parseContent();
sourceClauseProcessed = true;
} else if (parserGetLastWord().equals(KEYWORD_SET)) {
final List<OPair<String, Object>> fields = new ArrayList<OPair<String, Object>>();
parseSetFields(clazz, fields);
newRecords.add(OPair.convertToMap(fields));
sourceClauseProcessed = true;
}
}
if (sourceClauseProcessed)
parserNextWord(true, " \r\n");
// it has to be processed before KEYWORD_FROM in order to not be taken as part of SELECT
if (parserGetLastWord().equals(KEYWORD_RETURN)) {
parseReturn(!sourceClauseProcessed);
parserNextWord(true, " \r\n");
}
if (!sourceClauseProcessed) {
if (parserGetLastWord().equals(KEYWORD_FROM)) {
newRecords = null;
subQuery = new OSQLAsynchQuery<OIdentifiable>(parserText.substring(parserGetCurrentPosition()), this);
}
}
} finally {
textRequest.setText(originalQuery);
}
return this;
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class OQueryOperatorContainsText method filterRecords.
@SuppressWarnings({ "unchecked", "deprecation" })
@Override
public Collection<OIdentifiable> filterRecords(final ODatabase<?> iDatabase, final List<String> iTargetClasses, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight) {
final String fieldName;
if (iCondition.getLeft() instanceof OSQLFilterItemField)
fieldName = iCondition.getLeft().toString();
else
fieldName = iCondition.getRight().toString();
final String fieldValue;
if (iCondition.getLeft() instanceof OSQLFilterItemField)
fieldValue = iCondition.getRight().toString();
else
fieldValue = iCondition.getLeft().toString();
final String className = iTargetClasses.get(0);
final OProperty prop = ((OMetadataInternal) iDatabase.getMetadata()).getImmutableSchemaSnapshot().getClass(className).getProperty(fieldName);
if (prop == null)
// NO PROPERTY DEFINED
return null;
OIndex<?> fullTextIndex = null;
for (final OIndex<?> indexDefinition : prop.getIndexes()) {
if (indexDefinition instanceof OIndexFullText) {
fullTextIndex = indexDefinition;
break;
}
}
if (fullTextIndex == null) {
return null;
}
return (Collection<OIdentifiable>) fullTextIndex.get(fieldValue);
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class OCommandExecutorSQLAbstract method getInvolvedClustersOfIndex.
protected Set<String> getInvolvedClustersOfIndex(final String iIndexName) {
final ODatabaseDocumentInternal db = getDatabase();
final Set<String> clusters = new HashSet<String>();
final OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
final OIndex<?> idx = metadata.getIndexManager().getIndex(iIndexName);
if (idx != null && idx.getDefinition() != null) {
final String clazz = idx.getDefinition().getClassName();
if (clazz != null) {
final OClass cls = metadata.getImmutableSchemaSnapshot().getClass(clazz);
if (cls != null)
for (int clId : cls.getClusterIds()) {
final String clName = db.getClusterNameById(clId);
if (clName != null)
clusters.add(clName.toLowerCase());
}
}
}
return clusters;
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class OSQLQuery method run.
/**
* Delegates to the OQueryExecutor the query execution.
*/
@SuppressWarnings("unchecked")
public List<T> run(final Object... iArgs) {
final ODatabaseDocumentInternal database = ODatabaseRecordThreadLocal.INSTANCE.get();
if (database == null)
throw new OQueryParsingException("No database configured");
((OMetadataInternal) database.getMetadata()).makeThreadLocalSchemaSnapshot();
try {
setParameters(iArgs);
return (List<T>) database.getStorage().command(this);
} finally {
((OMetadataInternal) database.getMetadata()).clearThreadLocalSchemaSnapshot();
}
}
use of com.orientechnologies.orient.core.metadata.OMetadataInternal in project orientdb by orientechnologies.
the class OObjectDatabaseTx method open.
@Override
public <THISDB extends ODatabase> THISDB open(OToken iToken) {
super.open(iToken);
entityManager.registerEntityClass(OUser.class);
entityManager.registerEntityClass(ORole.class);
metadata = new OMetadataObject((OMetadataInternal) underlying.getMetadata());
return (THISDB) this;
}
Aggregations